summary refs log tree commit diff
path: root/nixos/modules/services/misc/sonarr.nix
blob: 97b67a0b5033c051aa14031b172ae9306ff6de89 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
{ config, pkgs, lib, ... }:

with lib;

let
  cfg = config.services.sonarr;
in
{
  options = {
    services.sonarr = {
      enable = mkEnableOption "Sonarr";
    };
  };

  config = mkIf cfg.enable {
    systemd.services.sonarr = {
      description = "Sonarr";
      after = [ "network.target" ];
      wantedBy = [ "multi-user.target" ];
      preStart = ''
        test -d /var/lib/sonarr/ || {
          echo "Creating sonarr data directory in /var/lib/sonarr/"
          mkdir -p /var/lib/sonarr/
        }
        chown -R sonarr:sonarr /var/lib/sonarr/
        chmod 0700 /var/lib/sonarr/
      '';

      serviceConfig = {
        Type = "simple";
        User = "sonarr";
        Group = "sonarr";
        PermissionsStartOnly = "true";
        ExecStart = "${pkgs.sonarr}/bin/NzbDrone --no-browser";
        Restart = "on-failure";
      };
    };

    users.users.sonarr = {
      uid = config.ids.uids.sonarr;
      home = "/var/lib/sonarr";
      group = "sonarr";
    };
    users.groups.sonarr.gid = config.ids.gids.sonarr;

  };
}