diff --git a/modules/services/pbgopy.nix b/modules/services/pbgopy.nix index a95ad959f..f4fd4f53f 100644 --- a/modules/services/pbgopy.nix +++ b/modules/services/pbgopy.nix @@ -3,14 +3,32 @@ with lib; let + cfg = config.services.pbgopy; package = pkgs.pbgopy; + + commandLine = concatStringsSep " " ([ + "${package}/bin/pbgopy serve" + "--port ${toString cfg.port}" + "--ttl ${cfg.cache.ttl}" + ] ++ optional (cfg.httpAuth != null) + "--basic-auth ${escapeShellArg cfg.httpAuth}"); + in { meta.maintainers = [ maintainers.ivar ]; options.services.pbgopy = { enable = mkEnableOption "pbgopy"; + port = mkOption { + type = types.port; + default = 9090; + example = 8080; + description = '' + The port to host the pbgopy server on. + ''; + }; + cache.ttl = mkOption { type = types.str; default = "24h"; @@ -19,6 +37,16 @@ in { The TTL for the cache. Use "0s" to disable it. ''; }; + + httpAuth = mkOption { + type = types.nullOr types.str; + default = null; + example = "user:pass"; + description = '' + Basic HTTP authentication's username and password. Both the username and + password are escaped. + ''; + }; }; config = mkIf cfg.enable { @@ -31,7 +59,7 @@ in { PartOf = [ "graphical-session.target" ]; }; Service = { - ExecStart = "${package}/bin/pbgopy serve --ttl ${cfg.cache.ttl}"; + ExecStart = commandLine; Restart = "on-abort"; }; Install = { WantedBy = [ "graphical-session.target" ]; }; diff --git a/tests/modules/services/pbgopy/service.nix b/tests/modules/services/pbgopy/service.nix index 221214394..fb03c355c 100644 --- a/tests/modules/services/pbgopy/service.nix +++ b/tests/modules/services/pbgopy/service.nix @@ -16,7 +16,7 @@ assertFileExists $serviceFile assertFileContains $serviceFile \ - 'ExecStart=@pbgopy@/bin/pbgopy serve --ttl 24h' + 'ExecStart=@pbgopy@/bin/pbgopy serve --port 9090 --ttl 24h' ''; }; }