2020-04-24 23:36:52 +00:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.sonarr;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
services.sonarr = {
|
2022-09-09 14:08:57 +00:00
|
|
|
enable = mkEnableOption (lib.mdDoc "Sonarr");
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
dataDir = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "/var/lib/sonarr/.config/NzbDrone";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "The directory where Sonarr stores its data files.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
openFirewall = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2020-04-24 23:36:52 +00:00
|
|
|
Open ports in the firewall for the Sonarr web interface
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
user = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "sonarr";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "User account under which Sonaar runs.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
group = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "sonarr";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Group under which Sonaar runs.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
2022-10-30 15:09:59 +00:00
|
|
|
|
2024-01-02 11:29:13 +00:00
|
|
|
package = mkPackageOption pkgs "sonarr" { };
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
systemd.tmpfiles.rules = [
|
|
|
|
"d '${cfg.dataDir}' 0700 ${cfg.user} ${cfg.group} - -"
|
|
|
|
];
|
|
|
|
|
|
|
|
systemd.services.sonarr = {
|
|
|
|
description = "Sonarr";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "simple";
|
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
2022-10-30 15:09:59 +00:00
|
|
|
ExecStart = "${cfg.package}/bin/NzbDrone -nobrowser -data='${cfg.dataDir}'";
|
2020-04-24 23:36:52 +00:00
|
|
|
Restart = "on-failure";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
networking.firewall = mkIf cfg.openFirewall {
|
|
|
|
allowedTCPPorts = [ 8989 ];
|
|
|
|
};
|
|
|
|
|
|
|
|
users.users = mkIf (cfg.user == "sonarr") {
|
|
|
|
sonarr = {
|
|
|
|
group = cfg.group;
|
|
|
|
home = cfg.dataDir;
|
|
|
|
uid = config.ids.uids.sonarr;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
users.groups = mkIf (cfg.group == "sonarr") {
|
|
|
|
sonarr.gid = config.ids.gids.sonarr;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|