{ pkgs, config, lib, ... }: let cfg = config.services.firefly-iii-data-importer; user = cfg.user; group = cfg.group; defaultUser = "firefly-iii-data-importer"; defaultGroup = "firefly-iii-data-importer"; artisan = "${cfg.package}/artisan"; env-file-values = lib.attrsets.mapAttrs' ( n: v: lib.attrsets.nameValuePair (lib.strings.removeSuffix "_FILE" n) v ) (lib.attrsets.filterAttrs (n: v: lib.strings.hasSuffix "_FILE" n) cfg.settings); env-nonfile-values = lib.attrsets.filterAttrs (n: v: !lib.strings.hasSuffix "_FILE" n) cfg.settings; data-importer-maintenance = pkgs.writeShellScript "data-importer-maintenance.sh" '' set -a ${lib.strings.toShellVars env-nonfile-values} ${lib.strings.concatLines ( lib.attrsets.mapAttrsToList (n: v: "${n}=\"$(< ${v})\"") env-file-values )} set +a ${artisan} package:discover ${artisan} cache:clear ${artisan} config:cache ''; commonServiceConfig = { Type = "oneshot"; User = user; Group = group; StateDirectory = "firefly-iii-data-importer"; ReadWritePaths = [ cfg.dataDir ]; WorkingDirectory = cfg.package; PrivateTmp = true; PrivateDevices = true; CapabilityBoundingSet = ""; AmbientCapabilities = ""; ProtectSystem = "strict"; ProtectKernelTunables = true; ProtectKernelModules = true; ProtectControlGroups = true; ProtectClock = true; ProtectHostname = true; ProtectHome = "tmpfs"; ProtectKernelLogs = true; ProtectProc = "invisible"; ProcSubset = "pid"; PrivateNetwork = false; RestrictAddressFamilies = "AF_INET AF_INET6 AF_UNIX"; SystemCallArchitectures = "native"; SystemCallFilter = [ "@system-service @resources" "~@obsolete @privileged" ]; RestrictSUIDSGID = true; RemoveIPC = true; NoNewPrivileges = true; RestrictRealtime = true; RestrictNamespaces = true; LockPersonality = true; PrivateUsers = true; }; in { options.services.firefly-iii-data-importer = { enable = lib.mkEnableOption "Firefly III Data Importer"; user = lib.mkOption { type = lib.types.str; default = defaultUser; description = "User account under which firefly-iii-data-importer runs."; }; group = lib.mkOption { type = lib.types.str; default = if cfg.enableNginx then "nginx" else defaultGroup; defaultText = "If `services.firefly-iii-data-importer.enableNginx` is true then `nginx` else ${defaultGroup}"; description = '' Group under which firefly-iii-data-importer runs. It is best to set this to the group of whatever webserver is being used as the frontend. ''; }; dataDir = lib.mkOption { type = lib.types.path; default = "/var/lib/firefly-iii-data-importer"; description = '' The place where firefly-iii data importer stores its state. ''; }; package = lib.mkOption { type = lib.types.package; default = pkgs.firefly-iii-data-importer; defaultText = lib.literalExpression "pkgs.firefly-iii-data-importer"; description = '' The firefly-iii-data-importer package served by php-fpm and the webserver of choice. This option can be used to point the webserver to the correct root. It may also be used to set the package to a different version, say a development version. ''; apply = firefly-iii-data-importer: firefly-iii-data-importer.override (prev: { dataDir = cfg.dataDir; }); }; enableNginx = lib.mkOption { type = lib.types.bool; default = false; description = '' Whether to enable nginx or not. If enabled, an nginx virtual host will be created for access to firefly-iii data importer. If not enabled, then you may use `''${config.services.firefly-iii-data-importer.package}` as your document root in whichever webserver you wish to setup. ''; }; virtualHost = lib.mkOption { type = lib.types.str; default = "localhost"; description = '' The hostname at which you wish firefly-iii-data-importer to be served. If you have enabled nginx using `services.firefly-iii-data-importer.enableNginx` then this will be used. ''; }; poolConfig = lib.mkOption { type = lib.types.attrsOf ( lib.types.oneOf [ lib.types.str lib.types.int lib.types.bool ] ); default = { }; defaultText = lib.literalExpression '' { "pm" = "dynamic"; "pm.max_children" = 32; "pm.start_servers" = 2; "pm.min_spare_servers" = 2; "pm.max_spare_servers" = 4; "pm.max_requests" = 500; } ''; description = '' Options for the Firefly III Data Importer PHP pool. See the documentation on php-fpm.conf for details on configuration directives. ''; }; settings = lib.mkOption { default = { }; description = '' Options for firefly-iii data importer configuration. Refer to for details on supported values. All