1 { config, pkgs, lib, utils, ... }:
3 cfg = config.services.sonarr;
8 enable = lib.mkEnableOption "Sonarr";
10 dataDir = lib.mkOption {
12 default = "/var/lib/sonarr/.config/NzbDrone";
13 description = "The directory where Sonarr stores its data files.";
16 openFirewall = lib.mkOption {
17 type = lib.types.bool;
20 Open ports in the firewall for the Sonarr web interface
27 description = "User account under which Sonaar runs.";
30 group = lib.mkOption {
33 description = "Group under which Sonaar runs.";
36 package = lib.mkPackageOption pkgs "sonarr" { };
40 config = lib.mkIf cfg.enable {
41 systemd.tmpfiles.rules = [
42 "d '${cfg.dataDir}' 0700 ${cfg.user} ${cfg.group} - -"
45 systemd.services.sonarr = {
46 description = "Sonarr";
47 after = [ "network.target" ];
48 wantedBy = [ "multi-user.target" ];
54 ExecStart = utils.escapeSystemdExecArgs [
55 (lib.getExe cfg.package)
57 "-data=${cfg.dataDir}"
59 Restart = "on-failure";
63 networking.firewall = lib.mkIf cfg.openFirewall {
64 allowedTCPPorts = [ 8989 ];
67 users.users = lib.mkIf (cfg.user == "sonarr") {
71 uid = config.ids.uids.sonarr;
75 users.groups = lib.mkIf (cfg.group == "sonarr") {
76 sonarr.gid = config.ids.gids.sonarr;