Skip to content

Commit 0c4bc74

Browse files
authored
nixos/radarr,lidarr,readarr,whisparr,prowlarr: add settings option (#384052)
2 parents f5090d4 + b029646 commit 0c4bc74

File tree

9 files changed

+150
-38
lines changed

9 files changed

+150
-38
lines changed

nixos/modules/module-list.nix

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,6 @@
821821
./services/misc/klipper.nix
822822
./services/misc/languagetool.nix
823823
./services/misc/leaps.nix
824-
./services/misc/lidarr.nix
825824
./services/misc/lifecycled.nix
826825
./services/misc/llama-cpp.nix
827826
./services/misc/logkeys.nix
@@ -861,12 +860,9 @@
861860
./services/misc/portunus.nix
862861
./services/misc/preload.nix
863862
./services/misc/private-gpt.nix
864-
./services/misc/prowlarr.nix
865863
./services/misc/pufferpanel.nix
866864
./services/misc/pykms.nix
867-
./services/misc/radarr.nix
868865
./services/misc/radicle.nix
869-
./services/misc/readarr.nix
870866
./services/misc/realmd.nix
871867
./services/misc/rebuilderd.nix
872868
./services/misc/recyclarr.nix
@@ -878,13 +874,18 @@
878874
./services/misc/rshim.nix
879875
./services/misc/safeeyes.nix
880876
./services/misc/sdrplay.nix
877+
./services/misc/servarr/lidarr.nix
878+
./services/misc/servarr/prowlarr.nix
879+
./services/misc/servarr/radarr.nix
880+
./services/misc/servarr/readarr.nix
881+
./services/misc/servarr/sonarr.nix
882+
./services/misc/servarr/whisparr.nix
881883
./services/misc/serviio.nix
882884
./services/misc/sickbeard.nix
883885
./services/misc/signald.nix
884886
./services/misc/siproxd.nix
885887
./services/misc/snapper.nix
886888
./services/misc/soft-serve.nix
887-
./services/misc/sonarr.nix
888889
./services/misc/sourcehut
889890
./services/misc/spice-autorandr.nix
890891
./services/misc/spice-vdagentd.nix
@@ -910,7 +911,6 @@
910911
./services/misc/wastebin.nix
911912
./services/misc/weechat.nix
912913
./services/misc/workout-tracker.nix
913-
./services/misc/whisparr.nix
914914
./services/misc/xmrig.nix
915915
./services/misc/ytdl-sub.nix
916916
./services/misc/zoneminder.nix

nixos/modules/services/misc/lidarr.nix renamed to nixos/modules/services/misc/servarr/lidarr.nix

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
}:
77
let
88
cfg = config.services.lidarr;
9+
servarr = import ./settings-options.nix { inherit lib pkgs; };
910
in
1011
{
1112
options = {
@@ -28,6 +29,10 @@ in
2829
'';
2930
};
3031

32+
settings = servarr.mkServarrSettingsOptions "lidarr" 8686;
33+
34+
environmentFiles = servarr.mkServarrEnvironmentFiles "lidarr";
35+
3136
user = lib.mkOption {
3237
type = lib.types.str;
3338
default = "lidarr";
@@ -56,18 +61,20 @@ in
5661
description = "Lidarr";
5762
after = [ "network.target" ];
5863
wantedBy = [ "multi-user.target" ];
64+
environment = servarr.mkServarrSettingsEnvVars "LIDARR" cfg.settings;
5965

6066
serviceConfig = {
6167
Type = "simple";
6268
User = cfg.user;
6369
Group = cfg.group;
70+
EnvironmentFile = cfg.environmentFiles;
6471
ExecStart = "${cfg.package}/bin/Lidarr -nobrowser -data='${cfg.dataDir}'";
6572
Restart = "on-failure";
6673
};
6774
};
6875

6976
networking.firewall = lib.mkIf cfg.openFirewall {
70-
allowedTCPPorts = [ 8686 ];
77+
allowedTCPPorts = [ cfg.settings.server.port ];
7178
};
7279

7380
users.users = lib.mkIf (cfg.user == "lidarr") {

nixos/modules/services/misc/prowlarr.nix renamed to nixos/modules/services/misc/servarr/prowlarr.nix

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
}:
77
let
88
cfg = config.services.prowlarr;
9-
9+
servarr = import ./settings-options.nix { inherit lib pkgs; };
1010
in
1111
{
1212
options = {
@@ -20,6 +20,10 @@ in
2020
default = false;
2121
description = "Open ports in the firewall for the Prowlarr web interface.";
2222
};
23+
24+
settings = servarr.mkServarrSettingsOptions "prowlarr" 9696;
25+
26+
environmentFiles = servarr.mkServarrEnvironmentFiles "prowlarr";
2327
};
2428
};
2529

@@ -28,19 +32,22 @@ in
2832
description = "Prowlarr";
2933
after = [ "network.target" ];
3034
wantedBy = [ "multi-user.target" ];
35+
environment = servarr.mkServarrSettingsEnvVars "PROWLARR" cfg.settings // {
36+
HOME = "/var/empty";
37+
};
3138

3239
serviceConfig = {
3340
Type = "simple";
3441
DynamicUser = true;
3542
StateDirectory = "prowlarr";
43+
EnvironmentFile = cfg.environmentFiles;
3644
ExecStart = "${lib.getExe cfg.package} -nobrowser -data=/var/lib/prowlarr";
3745
Restart = "on-failure";
3846
};
39-
environment.HOME = "/var/empty";
4047
};
4148

4249
networking.firewall = lib.mkIf cfg.openFirewall {
43-
allowedTCPPorts = [ 9696 ];
50+
allowedTCPPorts = [ cfg.settings.server.port ];
4451
};
4552
};
4653
}

nixos/modules/services/misc/radarr.nix renamed to nixos/modules/services/misc/servarr/radarr.nix

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
}:
77
let
88
cfg = config.services.radarr;
9-
9+
servarr = import ./settings-options.nix { inherit lib pkgs; };
1010
in
1111
{
1212
options = {
@@ -27,6 +27,10 @@ in
2727
description = "Open ports in the firewall for the Radarr web interface.";
2828
};
2929

30+
settings = servarr.mkServarrSettingsOptions "radarr" 7878;
31+
32+
environmentFiles = servarr.mkServarrEnvironmentFiles "radarr";
33+
3034
user = lib.mkOption {
3135
type = lib.types.str;
3236
default = "radarr";
@@ -51,18 +55,20 @@ in
5155
description = "Radarr";
5256
after = [ "network.target" ];
5357
wantedBy = [ "multi-user.target" ];
58+
environment = servarr.mkServarrSettingsEnvVars "RADARR" cfg.settings;
5459

5560
serviceConfig = {
5661
Type = "simple";
5762
User = cfg.user;
5863
Group = cfg.group;
64+
EnvironmentFile = cfg.environmentFiles;
5965
ExecStart = "${cfg.package}/bin/Radarr -nobrowser -data='${cfg.dataDir}'";
6066
Restart = "on-failure";
6167
};
6268
};
6369

6470
networking.firewall = lib.mkIf cfg.openFirewall {
65-
allowedTCPPorts = [ 7878 ];
71+
allowedTCPPorts = [ cfg.settings.server.port ];
6672
};
6773

6874
users.users = lib.mkIf (cfg.user == "radarr") {

nixos/modules/services/misc/readarr.nix renamed to nixos/modules/services/misc/servarr/readarr.nix

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
}:
77
let
88
cfg = config.services.readarr;
9+
servarr = import ./settings-options.nix { inherit lib pkgs; };
910
in
1011
{
1112
options = {
@@ -28,6 +29,10 @@ in
2829
'';
2930
};
3031

32+
settings = servarr.mkServarrSettingsOptions "readarr" 8787;
33+
34+
environmentFiles = servarr.mkServarrEnvironmentFiles "readarr";
35+
3136
user = lib.mkOption {
3237
type = lib.types.str;
3338
default = "readarr";
@@ -56,18 +61,20 @@ in
5661
description = "Readarr";
5762
after = [ "network.target" ];
5863
wantedBy = [ "multi-user.target" ];
64+
environment = servarr.mkServarrSettingsEnvVars "READARR" cfg.settings;
5965

6066
serviceConfig = {
6167
Type = "simple";
6268
User = cfg.user;
6369
Group = cfg.group;
70+
EnvironmentFile = cfg.environmentFiles;
6471
ExecStart = "${cfg.package}/bin/Readarr -nobrowser -data='${cfg.dataDir}'";
6572
Restart = "on-failure";
6673
};
6774
};
6875

6976
networking.firewall = lib.mkIf cfg.openFirewall {
70-
allowedTCPPorts = [ 8787 ];
77+
allowedTCPPorts = [ cfg.settings.server.port ];
7178
};
7279

7380
users.users = lib.mkIf (cfg.user == "readarr") {
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
{ lib, pkgs }:
2+
{
3+
mkServarrSettingsOptions =
4+
name: port:
5+
lib.mkOption {
6+
type = lib.types.submodule {
7+
freeformType = (pkgs.formats.ini { }).type;
8+
options = {
9+
update = {
10+
mechanism = lib.mkOption {
11+
type =
12+
with lib.types;
13+
nullOr (enum [
14+
"external"
15+
"builtIn"
16+
"script"
17+
]);
18+
description = "which update mechanism to use";
19+
default = "external";
20+
};
21+
automatically = lib.mkOption {
22+
type = lib.types.bool;
23+
description = "Automatically download and install updates.";
24+
default = false;
25+
};
26+
};
27+
server = {
28+
port = lib.mkOption {
29+
type = lib.types.int;
30+
description = "Port Number";
31+
default = port;
32+
};
33+
};
34+
log = {
35+
analyticsEnabled = lib.mkOption {
36+
type = lib.types.bool;
37+
description = "Send Anonymous Usage Data";
38+
default = false;
39+
};
40+
};
41+
};
42+
};
43+
example = lib.options.literalExpression ''
44+
{
45+
update.mechanism = "internal";
46+
server = {
47+
urlbase = "localhost";
48+
port = ${toString port};
49+
bindaddress = "*";
50+
};
51+
}
52+
'';
53+
default = { };
54+
description = ''
55+
Attribute set of arbitrary config options.
56+
Please consult the documentation at the [wiki](https://wiki.servarr.com/useful-tools#using-environment-variables-for-config).
57+
58+
WARNING: this configuration is stored in the world-readable Nix store!
59+
For secrets use [](#opt-services.${name}.environmentFiles).
60+
'';
61+
};
62+
63+
mkServarrEnvironmentFiles =
64+
name:
65+
lib.mkOption {
66+
type = lib.types.listOf lib.types.path;
67+
default = [ ];
68+
description = ''
69+
Environment file to pass secret configuration values.
70+
Each line must follow the `${lib.toUpper name}__SECTION__KEY=value` pattern.
71+
Please consult the documentation at the [wiki](https://wiki.servarr.com/useful-tools#using-environment-variables-for-config).
72+
'';
73+
};
74+
75+
mkServarrSettingsEnvVars =
76+
name: settings:
77+
lib.pipe settings [
78+
(lib.mapAttrsRecursive (
79+
path: value:
80+
lib.optionalAttrs (value != null) {
81+
name = lib.toUpper "${name}__${lib.concatStringsSep "__" path}";
82+
value = toString (if lib.isBool value then lib.boolToString value else value);
83+
}
84+
))
85+
(lib.collect (x: lib.isString x.name or false && lib.isString x.value or false))
86+
lib.listToAttrs
87+
];
88+
}

nixos/modules/services/misc/sonarr.nix renamed to nixos/modules/services/misc/servarr/sonarr.nix

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
}:
88
let
99
cfg = config.services.sonarr;
10+
servarr = import ./settings-options.nix { inherit lib pkgs; };
1011
in
1112
{
1213
options = {
@@ -27,6 +28,10 @@ in
2728
'';
2829
};
2930

31+
environmentFiles = servarr.mkServarrEnvironmentFiles "sonarr";
32+
33+
settings = servarr.mkServarrSettingsOptions "sonarr" 8989;
34+
3035
user = lib.mkOption {
3136
type = lib.types.str;
3237
default = "sonarr";
@@ -52,11 +57,12 @@ in
5257
description = "Sonarr";
5358
after = [ "network.target" ];
5459
wantedBy = [ "multi-user.target" ];
55-
60+
environment = servarr.mkServarrSettingsEnvVars "SONARR" cfg.settings;
5661
serviceConfig = {
5762
Type = "simple";
5863
User = cfg.user;
5964
Group = cfg.group;
65+
EnvironmentFile = cfg.environmentFiles;
6066
ExecStart = utils.escapeSystemdExecArgs [
6167
(lib.getExe cfg.package)
6268
"-nobrowser"
@@ -67,7 +73,7 @@ in
6773
};
6874

6975
networking.firewall = lib.mkIf cfg.openFirewall {
70-
allowedTCPPorts = [ 8989 ];
76+
allowedTCPPorts = [ cfg.settings.server.port ];
7177
};
7278

7379
users.users = lib.mkIf (cfg.user == "sonarr") {

nixos/modules/services/misc/whisparr.nix renamed to nixos/modules/services/misc/servarr/whisparr.nix

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
let
99
cfg = config.services.whisparr;
10+
servarr = import ./settings-options.nix { inherit lib pkgs; };
1011
in
1112
{
1213
options = {
@@ -27,6 +28,10 @@ in
2728
description = "Open ports in the firewall for the Whisparr web interface.";
2829
};
2930

31+
settings = servarr.mkServarrSettingsOptions "whisparr" 6969;
32+
33+
environmentFiles = servarr.mkServarrEnvironmentFiles "whisparr";
34+
3035
user = lib.mkOption {
3136
type = lib.types.str;
3237
default = "whisparr";
@@ -48,17 +53,21 @@ in
4853
description = "Whisparr";
4954
after = [ "network.target" ];
5055
wantedBy = [ "multi-user.target" ];
56+
environment = servarr.mkServarrSettingsEnvVars "WHISPARR" cfg.settings;
5157

5258
serviceConfig = {
5359
Type = "simple";
5460
User = cfg.user;
5561
Group = cfg.group;
62+
EnvironmentFile = cfg.environmentFiles;
5663
ExecStart = "${lib.getExe cfg.package} -nobrowser -data='${cfg.dataDir}'";
5764
Restart = "on-failure";
5865
};
5966
};
6067

61-
networking.firewall = lib.mkIf cfg.openFirewall { allowedTCPPorts = [ 6969 ]; };
68+
networking.firewall = lib.mkIf cfg.openFirewall {
69+
allowedTCPPorts = [ cfg.settings.server.port ];
70+
};
6271

6372
users.users = lib.mkIf (cfg.user == "whisparr") {
6473
whisparr = {

0 commit comments

Comments
 (0)