1 { config, pkgs, lib, utils, ... }:
6 cfg = config.services.sonarr;
11 enable = mkEnableOption "Sonarr";
15 default = "/var/lib/sonarr/.config/NzbDrone";
16 description = "The directory where Sonarr stores its data files.";
19 openFirewall = mkOption {
23 Open ports in the firewall for the Sonarr web interface
30 description = "User account under which Sonaar runs.";
36 description = "Group under which Sonaar runs.";
39 package = mkPackageOption pkgs "sonarr" { };
43 config = mkIf cfg.enable {
44 systemd.tmpfiles.rules = [
45 "d '${cfg.dataDir}' 0700 ${cfg.user} ${cfg.group} - -"
48 systemd.services.sonarr = {
49 description = "Sonarr";
50 after = [ "network.target" ];
51 wantedBy = [ "multi-user.target" ];
57 ExecStart = utils.escapeSystemdExecArgs [
58 (lib.getExe cfg.package)
60 "-data=${cfg.dataDir}"
62 Restart = "on-failure";
66 networking.firewall = mkIf cfg.openFirewall {
67 allowedTCPPorts = [ 8989 ];
70 users.users = mkIf (cfg.user == "sonarr") {
74 uid = config.ids.uids.sonarr;
78 users.groups = mkIf (cfg.group == "sonarr") {
79 sonarr.gid = config.ids.gids.sonarr;