diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index 23972da40674..2b4e3f5bddbd 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -821,7 +821,6 @@ ./services/misc/klipper.nix ./services/misc/languagetool.nix ./services/misc/leaps.nix - ./services/misc/lidarr.nix ./services/misc/lifecycled.nix ./services/misc/llama-cpp.nix ./services/misc/logkeys.nix @@ -861,12 +860,9 @@ ./services/misc/portunus.nix ./services/misc/preload.nix ./services/misc/private-gpt.nix - ./services/misc/prowlarr.nix ./services/misc/pufferpanel.nix ./services/misc/pykms.nix - ./services/misc/radarr.nix ./services/misc/radicle.nix - ./services/misc/readarr.nix ./services/misc/realmd.nix ./services/misc/rebuilderd.nix ./services/misc/recyclarr.nix @@ -878,13 +874,18 @@ ./services/misc/rshim.nix ./services/misc/safeeyes.nix ./services/misc/sdrplay.nix + ./services/misc/servarr/lidarr.nix + ./services/misc/servarr/prowlarr.nix + ./services/misc/servarr/radarr.nix + ./services/misc/servarr/readarr.nix + ./services/misc/servarr/sonarr.nix + ./services/misc/servarr/whisparr.nix ./services/misc/serviio.nix ./services/misc/sickbeard.nix ./services/misc/signald.nix ./services/misc/siproxd.nix ./services/misc/snapper.nix ./services/misc/soft-serve.nix - ./services/misc/sonarr.nix ./services/misc/sourcehut ./services/misc/spice-autorandr.nix ./services/misc/spice-vdagentd.nix @@ -910,7 +911,6 @@ ./services/misc/wastebin.nix ./services/misc/weechat.nix ./services/misc/workout-tracker.nix - ./services/misc/whisparr.nix ./services/misc/xmrig.nix ./services/misc/ytdl-sub.nix ./services/misc/zoneminder.nix diff --git a/nixos/modules/services/misc/lidarr.nix b/nixos/modules/services/misc/servarr/lidarr.nix similarity index 83% rename from nixos/modules/services/misc/lidarr.nix rename to nixos/modules/services/misc/servarr/lidarr.nix index 1ca0697205b5..09df550fb2cd 100644 --- a/nixos/modules/services/misc/lidarr.nix +++ b/nixos/modules/services/misc/servarr/lidarr.nix @@ -6,6 +6,7 @@ }: let cfg = config.services.lidarr; + servarr = import ./settings-options.nix { inherit lib pkgs; }; in { options = { @@ -28,6 +29,10 @@ in ''; }; + settings = servarr.mkServarrSettingsOptions "lidarr" 8686; + + environmentFiles = servarr.mkServarrEnvironmentFiles "lidarr"; + user = lib.mkOption { type = lib.types.str; default = "lidarr"; @@ -56,18 +61,20 @@ in description = "Lidarr"; after = [ "network.target" ]; wantedBy = [ "multi-user.target" ]; + environment = servarr.mkServarrSettingsEnvVars "LIDARR" cfg.settings; serviceConfig = { Type = "simple"; User = cfg.user; Group = cfg.group; + EnvironmentFile = cfg.environmentFiles; ExecStart = "${cfg.package}/bin/Lidarr -nobrowser -data='${cfg.dataDir}'"; Restart = "on-failure"; }; }; networking.firewall = lib.mkIf cfg.openFirewall { - allowedTCPPorts = [ 8686 ]; + allowedTCPPorts = [ cfg.settings.server.port ]; }; users.users = lib.mkIf (cfg.user == "lidarr") { diff --git a/nixos/modules/services/misc/prowlarr.nix b/nixos/modules/services/misc/servarr/prowlarr.nix similarity index 69% rename from nixos/modules/services/misc/prowlarr.nix rename to nixos/modules/services/misc/servarr/prowlarr.nix index 21296985b3ef..dcf5b18005b4 100644 --- a/nixos/modules/services/misc/prowlarr.nix +++ b/nixos/modules/services/misc/servarr/prowlarr.nix @@ -6,7 +6,7 @@ }: let cfg = config.services.prowlarr; - + servarr = import ./settings-options.nix { inherit lib pkgs; }; in { options = { @@ -20,6 +20,10 @@ in default = false; description = "Open ports in the firewall for the Prowlarr web interface."; }; + + settings = servarr.mkServarrSettingsOptions "prowlarr" 9696; + + environmentFiles = servarr.mkServarrEnvironmentFiles "prowlarr"; }; }; @@ -28,19 +32,22 @@ in description = "Prowlarr"; after = [ "network.target" ]; wantedBy = [ "multi-user.target" ]; + environment = servarr.mkServarrSettingsEnvVars "PROWLARR" cfg.settings // { + HOME = "/var/empty"; + }; serviceConfig = { Type = "simple"; DynamicUser = true; StateDirectory = "prowlarr"; + EnvironmentFile = cfg.environmentFiles; ExecStart = "${lib.getExe cfg.package} -nobrowser -data=/var/lib/prowlarr"; Restart = "on-failure"; }; - environment.HOME = "/var/empty"; }; networking.firewall = lib.mkIf cfg.openFirewall { - allowedTCPPorts = [ 9696 ]; + allowedTCPPorts = [ cfg.settings.server.port ]; }; }; } diff --git a/nixos/modules/services/misc/radarr.nix b/nixos/modules/services/misc/servarr/radarr.nix similarity index 82% rename from nixos/modules/services/misc/radarr.nix rename to nixos/modules/services/misc/servarr/radarr.nix index bb645acd5f92..9ca4b889de63 100644 --- a/nixos/modules/services/misc/radarr.nix +++ b/nixos/modules/services/misc/servarr/radarr.nix @@ -6,7 +6,7 @@ }: let cfg = config.services.radarr; - + servarr = import ./settings-options.nix { inherit lib pkgs; }; in { options = { @@ -27,6 +27,10 @@ in description = "Open ports in the firewall for the Radarr web interface."; }; + settings = servarr.mkServarrSettingsOptions "radarr" 7878; + + environmentFiles = servarr.mkServarrEnvironmentFiles "radarr"; + user = lib.mkOption { type = lib.types.str; default = "radarr"; @@ -51,18 +55,20 @@ in description = "Radarr"; after = [ "network.target" ]; wantedBy = [ "multi-user.target" ]; + environment = servarr.mkServarrSettingsEnvVars "RADARR" cfg.settings; serviceConfig = { Type = "simple"; User = cfg.user; Group = cfg.group; + EnvironmentFile = cfg.environmentFiles; ExecStart = "${cfg.package}/bin/Radarr -nobrowser -data='${cfg.dataDir}'"; Restart = "on-failure"; }; }; networking.firewall = lib.mkIf cfg.openFirewall { - allowedTCPPorts = [ 7878 ]; + allowedTCPPorts = [ cfg.settings.server.port ]; }; users.users = lib.mkIf (cfg.user == "radarr") { diff --git a/nixos/modules/services/misc/readarr.nix b/nixos/modules/services/misc/servarr/readarr.nix similarity index 83% rename from nixos/modules/services/misc/readarr.nix rename to nixos/modules/services/misc/servarr/readarr.nix index 49a3fde81a9d..3933ec0305f4 100644 --- a/nixos/modules/services/misc/readarr.nix +++ b/nixos/modules/services/misc/servarr/readarr.nix @@ -6,6 +6,7 @@ }: let cfg = config.services.readarr; + servarr = import ./settings-options.nix { inherit lib pkgs; }; in { options = { @@ -28,6 +29,10 @@ in ''; }; + settings = servarr.mkServarrSettingsOptions "readarr" 8787; + + environmentFiles = servarr.mkServarrEnvironmentFiles "readarr"; + user = lib.mkOption { type = lib.types.str; default = "readarr"; @@ -56,18 +61,20 @@ in description = "Readarr"; after = [ "network.target" ]; wantedBy = [ "multi-user.target" ]; + environment = servarr.mkServarrSettingsEnvVars "READARR" cfg.settings; serviceConfig = { Type = "simple"; User = cfg.user; Group = cfg.group; + EnvironmentFile = cfg.environmentFiles; ExecStart = "${cfg.package}/bin/Readarr -nobrowser -data='${cfg.dataDir}'"; Restart = "on-failure"; }; }; networking.firewall = lib.mkIf cfg.openFirewall { - allowedTCPPorts = [ 8787 ]; + allowedTCPPorts = [ cfg.settings.server.port ]; }; users.users = lib.mkIf (cfg.user == "readarr") { diff --git a/nixos/modules/services/misc/servarr/settings-options.nix b/nixos/modules/services/misc/servarr/settings-options.nix new file mode 100644 index 000000000000..007deba75425 --- /dev/null +++ b/nixos/modules/services/misc/servarr/settings-options.nix @@ -0,0 +1,88 @@ +{ lib, pkgs }: +{ + mkServarrSettingsOptions = + name: port: + lib.mkOption { + type = lib.types.submodule { + freeformType = (pkgs.formats.ini { }).type; + options = { + update = { + mechanism = lib.mkOption { + type = + with lib.types; + nullOr (enum [ + "external" + "builtIn" + "script" + ]); + description = "which update mechanism to use"; + default = "external"; + }; + automatically = lib.mkOption { + type = lib.types.bool; + description = "Automatically download and install updates."; + default = false; + }; + }; + server = { + port = lib.mkOption { + type = lib.types.int; + description = "Port Number"; + default = port; + }; + }; + log = { + analyticsEnabled = lib.mkOption { + type = lib.types.bool; + description = "Send Anonymous Usage Data"; + default = false; + }; + }; + }; + }; + example = lib.options.literalExpression '' + { + update.mechanism = "internal"; + server = { + urlbase = "localhost"; + port = ${toString port}; + bindaddress = "*"; + }; + } + ''; + default = { }; + description = '' + Attribute set of arbitrary config options. + Please consult the documentation at the [wiki](https://wiki.servarr.com/useful-tools#using-environment-variables-for-config). + + WARNING: this configuration is stored in the world-readable Nix store! + For secrets use [](#opt-services.${name}.environmentFiles). + ''; + }; + + mkServarrEnvironmentFiles = + name: + lib.mkOption { + type = lib.types.listOf lib.types.path; + default = [ ]; + description = '' + Environment file to pass secret configuration values. + Each line must follow the `${lib.toUpper name}__SECTION__KEY=value` pattern. + Please consult the documentation at the [wiki](https://wiki.servarr.com/useful-tools#using-environment-variables-for-config). + ''; + }; + + mkServarrSettingsEnvVars = + name: settings: + lib.pipe settings [ + (lib.mapAttrsRecursive ( + path: value: + lib.optionalAttrs (value != null) { + name = lib.toUpper "${name}__${lib.concatStringsSep "__" path}"; + value = toString (if lib.isBool value then lib.boolToString value else value); + } + )) + (lib.collect (x: lib.isString x.name or false && lib.isString x.value or false)) + lib.listToAttrs + ]; +} diff --git a/nixos/modules/services/misc/sonarr.nix b/nixos/modules/services/misc/servarr/sonarr.nix similarity index 83% rename from nixos/modules/services/misc/sonarr.nix rename to nixos/modules/services/misc/servarr/sonarr.nix index 65f43df08312..9918c9da28f5 100644 --- a/nixos/modules/services/misc/sonarr.nix +++ b/nixos/modules/services/misc/servarr/sonarr.nix @@ -7,6 +7,7 @@ }: let cfg = config.services.sonarr; + servarr = import ./settings-options.nix { inherit lib pkgs; }; in { options = { @@ -27,6 +28,10 @@ in ''; }; + environmentFiles = servarr.mkServarrEnvironmentFiles "sonarr"; + + settings = servarr.mkServarrSettingsOptions "sonarr" 8989; + user = lib.mkOption { type = lib.types.str; default = "sonarr"; @@ -52,11 +57,12 @@ in description = "Sonarr"; after = [ "network.target" ]; wantedBy = [ "multi-user.target" ]; - + environment = servarr.mkServarrSettingsEnvVars "SONARR" cfg.settings; serviceConfig = { Type = "simple"; User = cfg.user; Group = cfg.group; + EnvironmentFile = cfg.environmentFiles; ExecStart = utils.escapeSystemdExecArgs [ (lib.getExe cfg.package) "-nobrowser" @@ -67,7 +73,7 @@ in }; networking.firewall = lib.mkIf cfg.openFirewall { - allowedTCPPorts = [ 8989 ]; + allowedTCPPorts = [ cfg.settings.server.port ]; }; users.users = lib.mkIf (cfg.user == "sonarr") { diff --git a/nixos/modules/services/misc/whisparr.nix b/nixos/modules/services/misc/servarr/whisparr.nix similarity index 79% rename from nixos/modules/services/misc/whisparr.nix rename to nixos/modules/services/misc/servarr/whisparr.nix index bf15ee70fde4..b686c8a76691 100644 --- a/nixos/modules/services/misc/whisparr.nix +++ b/nixos/modules/services/misc/servarr/whisparr.nix @@ -7,6 +7,7 @@ let cfg = config.services.whisparr; + servarr = import ./settings-options.nix { inherit lib pkgs; }; in { options = { @@ -27,6 +28,10 @@ in description = "Open ports in the firewall for the Whisparr web interface."; }; + settings = servarr.mkServarrSettingsOptions "whisparr" 6969; + + environmentFiles = servarr.mkServarrEnvironmentFiles "whisparr"; + user = lib.mkOption { type = lib.types.str; default = "whisparr"; @@ -48,17 +53,21 @@ in description = "Whisparr"; after = [ "network.target" ]; wantedBy = [ "multi-user.target" ]; + environment = servarr.mkServarrSettingsEnvVars "WHISPARR" cfg.settings; serviceConfig = { Type = "simple"; User = cfg.user; Group = cfg.group; + EnvironmentFile = cfg.environmentFiles; ExecStart = "${lib.getExe cfg.package} -nobrowser -data='${cfg.dataDir}'"; Restart = "on-failure"; }; }; - networking.firewall = lib.mkIf cfg.openFirewall { allowedTCPPorts = [ 6969 ]; }; + networking.firewall = lib.mkIf cfg.openFirewall { + allowedTCPPorts = [ cfg.settings.server.port ]; + }; users.users = lib.mkIf (cfg.user == "whisparr") { whisparr = { diff --git a/nixos/tests/prometheus-exporters.nix b/nixos/tests/prometheus-exporters.nix index be11bddb9329..89e33952697f 100644 --- a/nixos/tests/prometheus-exporters.nix +++ b/nixos/tests/prometheus-exporters.nix @@ -364,28 +364,10 @@ let apiKeyFile = pkgs.writeText "dummy-api-key" apikey; }; metricProvider = { - services.sonarr.enable = true; - systemd.services.sonarr.serviceConfig.ExecStartPre = - let - sonarr_config = pkgs.writeText "config.xml" '' - - info - False - 8989 - 9898 - - * - ${apikey} - None - BuiltIn - main - Sonarr - - ''; - in - [ - ''${pkgs.coreutils}/bin/install -D -m 777 ${sonarr_config} -T /var/lib/sonarr/.config/NzbDrone/config.xml'' - ]; + services.sonarr = { + enable = true; + environmentFiles = [(pkgs.writeText "sonarr-env" "SONARR__AUTH__APIKEY=${apikey}")]; + }; }; exporterTest = '' wait_for_unit("sonarr.service")