1 { config, pkgs, lib, ... }:
6 cfg = config.services.sonarr;
11 enable = mkEnableOption (lib.mdDoc "Sonarr");
15 default = "/var/lib/sonarr/.config/NzbDrone";
16 description = lib.mdDoc "The directory where Sonarr stores its data files.";
19 openFirewall = mkOption {
22 description = lib.mdDoc ''
23 Open ports in the firewall for the Sonarr web interface
30 description = lib.mdDoc "User account under which Sonaar runs.";
36 description = lib.mdDoc "Group under which Sonaar runs.";
41 default = pkgs.sonarr;
42 defaultText = literalExpression "pkgs.sonarr";
43 description = lib.mdDoc ''
44 Sonarr package to use.
50 config = mkIf cfg.enable {
51 systemd.tmpfiles.rules = [
52 "d '${cfg.dataDir}' 0700 ${cfg.user} ${cfg.group} - -"
55 systemd.services.sonarr = {
56 description = "Sonarr";
57 after = [ "network.target" ];
58 wantedBy = [ "multi-user.target" ];
64 ExecStart = "${cfg.package}/bin/NzbDrone -nobrowser -data='${cfg.dataDir}'";
65 Restart = "on-failure";
69 networking.firewall = mkIf cfg.openFirewall {
70 allowedTCPPorts = [ 8989 ];
73 users.users = mkIf (cfg.user == "sonarr") {
77 uid = config.ids.uids.sonarr;
81 users.groups = mkIf (cfg.group == "sonarr") {
82 sonarr.gid = config.ids.gids.sonarr;