1
0
Fork 0
mirror of https://github.com/NixOS/nixpkgs.git synced 2025-06-19 16:09:19 +03:00
nixpkgs/nixos/modules/services/misc/servarr/sonarr.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

92 lines
2.2 KiB
Nix
Raw Normal View History

{
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 = {
enable = lib.mkEnableOption "Sonarr";
dataDir = lib.mkOption {
type = lib.types.str;
default = "/var/lib/sonarr/.config/NzbDrone";
description = "The directory where Sonarr stores its data files.";
};
openFirewall = lib.mkOption {
type = lib.types.bool;
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;
user = lib.mkOption {
type = lib.types.str;
default = "sonarr";
description = "User account under which Sonaar runs.";
};
group = lib.mkOption {
type = lib.types.str;
default = "sonarr";
description = "Group under which Sonaar runs.";
};
2022-10-27 13:49:23 +01:00
package = lib.mkPackageOption pkgs "sonarr" { };
2016-06-02 21:00:00 +02:00
};
};
config = lib.mkIf cfg.enable {
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";
User = cfg.user;
Group = cfg.group;
2025-02-21 22:34:12 +01:00
EnvironmentFile = cfg.environmentFiles;
ExecStart = utils.escapeSystemdExecArgs [
(lib.getExe cfg.package)
"-nobrowser"
"-data=${cfg.dataDir}"
];
2016-06-02 21:00:00 +02:00
Restart = "on-failure";
};
};
networking.firewall = lib.mkIf cfg.openFirewall {
2025-02-21 22:34:12 +01:00
allowedTCPPorts = [ cfg.settings.server.port ];
};
users.users = lib.mkIf (cfg.user == "sonarr") {
sonarr = {
group = cfg.group;
home = cfg.dataDir;
uid = config.ids.uids.sonarr;
};
2016-06-02 21:00:00 +02:00
};
users.groups = lib.mkIf (cfg.group == "sonarr") {
sonarr.gid = config.ids.gids.sonarr;
};
2016-06-02 21:00:00 +02:00
};
}