about summary refs log tree commit diff
path: root/nixos/modules/services/misc/bazarr.nix
blob: 07c935053591946e2402b4608a91c59f458048c0 (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
{ config, pkgs, lib, ... }:

with lib;

let
  cfg = config.services.bazarr;
in
{
  options = {
    services.bazarr = {
      enable = mkEnableOption (lib.mdDoc "bazarr, a subtitle manager for Sonarr and Radarr");

      openFirewall = mkOption {
        type = types.bool;
        default = false;
        description = lib.mdDoc "Open ports in the firewall for the bazarr web interface.";
      };

      listenPort = mkOption {
        type = types.port;
        default = 6767;
        description = lib.mdDoc "Port on which the bazarr web interface should listen";
      };

      user = mkOption {
        type = types.str;
        default = "bazarr";
        description = lib.mdDoc "User account under which bazarr runs.";
      };

      group = mkOption {
        type = types.str;
        default = "bazarr";
        description = lib.mdDoc "Group under which bazarr runs.";
      };
    };
  };

  config = mkIf cfg.enable {
    systemd.services.bazarr = {
      description = "bazarr";
      after = [ "network.target" ];
      wantedBy = [ "multi-user.target" ];

      serviceConfig = rec {
        Type = "simple";
        User = cfg.user;
        Group = cfg.group;
        StateDirectory = "bazarr";
        SyslogIdentifier = "bazarr";
        ExecStart = pkgs.writeShellScript "start-bazarr" ''
          ${pkgs.bazarr}/bin/bazarr \
            --config '/var/lib/${StateDirectory}' \
            --port ${toString cfg.listenPort} \
            --no-update True
        '';
        Restart = "on-failure";
      };
    };

    networking.firewall = mkIf cfg.openFirewall {
      allowedTCPPorts = [ cfg.listenPort ];
    };

    users.users = mkIf (cfg.user == "bazarr") {
      bazarr = {
        isSystemUser = true;
        group = cfg.group;
        home = "/var/lib/${config.systemd.services.bazarr.serviceConfig.StateDirectory}";
      };
    };

    users.groups = mkIf (cfg.group == "bazarr") {
      bazarr = {};
    };
  };
}