From b0c07f95146d85a7b62a84fb2a62a773a5942733 Mon Sep 17 00:00:00 2001 From: clerie Date: Mon, 9 Dec 2024 18:37:18 +0100 Subject: [PATCH] Support all options in modules.nix --- module.nix | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/module.nix b/module.nix index 95dc01b..7445068 100644 --- a/module.nix +++ b/module.nix @@ -9,6 +9,31 @@ in { options = { services.scan-to-gpg = { enable = mkEnableOption "scan-to-gpg"; + host = mkOption { + type = types.str; + default = "0.0.0.0"; + description = "Interface to bind FTP server to"; + }; + port = mkOption { + type = with types; nullOr port; + default = null; + description = "Port for FTP server"; + }; + user = mkOption { + type = with types; nullOr str; + default = null; + description = "Username for FTP login"; + }; + passFile = mkOption { + type = with types; nullOr path; + default = null; + description = "Path to file containing password for FTP login"; + }; + output = mkOption { + type = types.path; + default = "/var/lib/scan-to-gpg"; + description = "Path to directory where encrypted files are stored in"; + }; gpgkey = mkOption { type = types.path; description = "Path to a file containing to GPG public key to encrypt to"; @@ -26,13 +51,28 @@ in { serviceConfig = { type = "simple"; - ExecStart = "${getExe pkgs.scan-to-gpg} -host 0.0.0.0 -output /var/lib/scan-to-gpg -gpgkey ${cfg.gpgkey}"; User = "scan-to-gpg"; Group = "scan-to-gpg"; StateDirectory = "scan-to-gpg"; StateDirectoryMode = "775"; + } // mkIf (cfg.passFile != null) { + LoadCredential = "pass-file:${cfg.passFile}"; }; + environment = mkIf (cfg.passFile != null) { + PASS_FILE = "%d/pass-file"; + }; + + script = '' + ${getExe pkgs.scan-to-gpg} -host ${cfg.host} ${ + optionalString (cfg.port != null) "-port ${toString cfg.port} " + }${ + optionalString (cfg.user != null) "-user ${cfg.user} " + }${ + optionalString (cfg.passFile != null) "-pass <($${PASS_FILE}) " + }-output ${cfg.output} -gpgkey ${cfg.gpgkey} + ''; + }; users.users.scan-to-gpg = {