2024-03-02 15:31:56 +03:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
pkgs,
|
|
|
|
lib,
|
|
|
|
utils,
|
|
|
|
...
|
|
|
|
}:
|
2016-06-02 21:00:00 +02:00
|
|
|
let
|
|
|
|
cfg = config.services.sonarr;
|
2025-02-24 18:46:54 +01:00
|
|
|
servarr = import ./settings-options.nix { inherit lib pkgs; };
|
2016-06-02 21:00:00 +02:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
services.sonarr = {
|
2024-08-30 00:46:48 +02:00
|
|
|
enable = lib.mkEnableOption "Sonarr";
|
2019-01-14 12:47:20 +01:00
|
|
|
|
2024-08-30 00:46:48 +02:00
|
|
|
dataDir = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
2019-01-14 12:47:20 +01:00
|
|
|
default = "/var/lib/sonarr/.config/NzbDrone";
|
|
|
|
description = "The directory where Sonarr stores its data files.";
|
|
|
|
};
|
|
|
|
|
2024-08-30 00:46:48 +02:00
|
|
|
openFirewall = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2019-01-14 12:47:20 +01:00
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Open ports in the firewall for the Sonarr web interface
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2025-02-21 22:34:12 +01:00
|
|
|
environmentFiles = servarr.mkServarrEnvironmentFiles "sonarr";
|
|
|
|
|
|
|
|
settings = servarr.mkServarrSettingsOptions "sonarr" 8989;
|
|
|
|
|
2024-08-30 00:46:48 +02:00
|
|
|
user = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
2019-01-14 12:47:20 +01:00
|
|
|
default = "sonarr";
|
|
|
|
description = "User account under which Sonaar runs.";
|
|
|
|
};
|
|
|
|
|
2024-08-30 00:46:48 +02:00
|
|
|
group = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
2019-01-14 12:47:20 +01:00
|
|
|
default = "sonarr";
|
|
|
|
description = "Group under which Sonaar runs.";
|
|
|
|
};
|
2022-10-27 13:49:23 +01:00
|
|
|
|
2024-08-30 00:46:48 +02:00
|
|
|
package = lib.mkPackageOption pkgs "sonarr" { };
|
2016-06-02 21:00:00 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-08-30 00:46:48 +02:00
|
|
|
config = lib.mkIf cfg.enable {
|
2019-02-23 16:56:42 -05:00
|
|
|
systemd.tmpfiles.rules = [
|
|
|
|
"d '${cfg.dataDir}' 0700 ${cfg.user} ${cfg.group} - -"
|
|
|
|
];
|
|
|
|
|
2016-06-02 21:00:00 +02:00
|
|
|
systemd.services.sonarr = {
|
|
|
|
description = "Sonarr";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2025-02-21 22:34:12 +01:00
|
|
|
environment = servarr.mkServarrSettingsEnvVars "SONARR" cfg.settings;
|
2016-06-02 21:00:00 +02:00
|
|
|
serviceConfig = {
|
|
|
|
Type = "simple";
|
2019-01-14 12:47:20 +01:00
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
2025-02-21 22:34:12 +01:00
|
|
|
EnvironmentFile = cfg.environmentFiles;
|
2024-03-02 15:31:56 +03:00
|
|
|
ExecStart = utils.escapeSystemdExecArgs [
|
|
|
|
(lib.getExe cfg.package)
|
|
|
|
"-nobrowser"
|
|
|
|
"-data=${cfg.dataDir}"
|
|
|
|
];
|
2016-06-02 21:00:00 +02:00
|
|
|
Restart = "on-failure";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-08-30 00:46:48 +02:00
|
|
|
networking.firewall = lib.mkIf cfg.openFirewall {
|
2025-02-21 22:34:12 +01:00
|
|
|
allowedTCPPorts = [ cfg.settings.server.port ];
|
2019-01-14 12:47:20 +01:00
|
|
|
};
|
|
|
|
|
2024-08-30 00:46:48 +02:00
|
|
|
users.users = lib.mkIf (cfg.user == "sonarr") {
|
2019-01-14 12:47:20 +01:00
|
|
|
sonarr = {
|
|
|
|
group = cfg.group;
|
|
|
|
home = cfg.dataDir;
|
|
|
|
uid = config.ids.uids.sonarr;
|
|
|
|
};
|
2016-06-02 21:00:00 +02:00
|
|
|
};
|
|
|
|
|
2024-08-30 00:46:48 +02:00
|
|
|
users.groups = lib.mkIf (cfg.group == "sonarr") {
|
2019-01-14 12:47:20 +01:00
|
|
|
sonarr.gid = config.ids.gids.sonarr;
|
|
|
|
};
|
2016-06-02 21:00:00 +02:00
|
|
|
};
|
|
|
|
}
|