Skip to content

Commit 79faf5a

Browse files
authored
nixos/sonarr: conditionally provision required directories with StateDirectory (#479148)
2 parents 68d4a23 + 1636693 commit 79faf5a

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

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

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ in
1717
dataDir = lib.mkOption {
1818
type = lib.types.str;
1919
default = "/var/lib/sonarr/.config/NzbDrone";
20-
description = "The directory where Sonarr stores its data files.";
20+
description = ''
21+
The Sonarr home directory used to store all data. If left as the default value
22+
this directory will automatically be created before the Sonarr server starts, otherwise
23+
you are responsible for ensuring the directory exists with appropriate ownership
24+
and permissions.
25+
'';
2126
};
2227

2328
openFirewall = lib.mkOption {
@@ -35,24 +40,36 @@ in
3540
user = lib.mkOption {
3641
type = lib.types.str;
3742
default = "sonarr";
38-
description = "User account under which Sonaar runs.";
43+
description = ''
44+
User account under which Sonarr runs.";
45+
46+
::: {.note}
47+
If left as the default value this user will automatically be created
48+
on system activation, otherwise you are responsible for
49+
ensuring the user exists before the Sonarr service starts.
50+
:::
51+
'';
3952
};
4053

4154
group = lib.mkOption {
4255
type = lib.types.str;
4356
default = "sonarr";
44-
description = "Group under which Sonaar runs.";
57+
description = ''
58+
Group account under which Sonarr runs.
59+
60+
::: {.note}
61+
If left as the default value this group will automatically be created
62+
on system activation, otherwise you are responsible for
63+
ensuring the group exists before the Sonarr service starts.
64+
:::
65+
'';
4566
};
4667

4768
package = lib.mkPackageOption pkgs "sonarr" { };
4869
};
4970
};
5071

5172
config = lib.mkIf cfg.enable {
52-
systemd.tmpfiles.rules = [
53-
"d '${cfg.dataDir}' 0700 ${cfg.user} ${cfg.group} - -"
54-
];
55-
5673
systemd.services.sonarr = {
5774
description = "Sonarr";
5875
after = [ "network.target" ];
@@ -69,6 +86,9 @@ in
6986
"-data=${cfg.dataDir}"
7087
];
7188
Restart = "on-failure";
89+
}
90+
// lib.optionalAttrs (cfg.dataDir == "/var/lib/sonarr/.config/NzbDrone") {
91+
StateDirectory = "sonarr";
7292
};
7393
};
7494

0 commit comments

Comments
 (0)