@@ -0,0 +1,76 @@
1+{ config, pkgs, lib, ... }:
2+
3+with lib;
4+
5+let
6+ cfg = config.services.bazarr;
7+in
8+{
9+ options = {
10+ services.bazarr = {
11+ enable = mkEnableOption "bazarr, a subtitle manager for Sonarr and Radarr";
12+
13+ openFirewall = mkOption {
14+ type = types.bool;
15+ default = false;
16+ description = "Open ports in the firewall for the bazarr web interface.";
17+ };
18+
19+ listenPort = mkOption {
20+ type = types.port;
21+ default = 6767;
22+ description = "Port on which the bazarr web interface should listen";
23+ };
24+
25+ user = mkOption {
26+ type = types.str;
27+ default = "bazarr";
28+ description = "User account under which bazarr runs.";
29+ };
30+
31+ group = mkOption {
32+ type = types.str;
33+ default = "bazarr";
34+ description = "Group under which bazarr runs.";
35+ };
36+ };
37+ };
38+
39+ config = mkIf cfg.enable {
40+ systemd.services.bazarr = {
41+ description = "bazarr";
42+ after = [ "network.target" ];
43+ wantedBy = [ "multi-user.target" ];
44+
45+ serviceConfig = rec {
46+ Type = "simple";
47+ User = cfg.user;
48+ Group = cfg.group;
49+ StateDirectory = "bazarr";
50+ SyslogIdentifier = "bazarr";
51+ ExecStart = pkgs.writeShellScript "start-bazarr" ''
52+ ${pkgs.bazarr}/bin/bazarr \
53+ --config '/var/lib/${StateDirectory}' \
54+ --port ${toString cfg.listenPort} \
55+ --no-update True
56+ '';
57+ Restart = "on-failure";
58+ };
59+ };
60+
61+ networking.firewall = mkIf cfg.openFirewall {
62+ allowedTCPPorts = [ cfg.listenPort ];
63+ };
64+
65+ users.users = mkIf (cfg.user == "bazarr") {
66+ bazarr = {
67+ group = cfg.group;
68+ home = "/var/lib/${config.systemd.services.bazarr.serviceConfig.StateDirectory}";
69+ };
70+ };
71+
72+ users.groups = mkIf (cfg.group == "bazarr") {
73+ bazarr = {};
74+ };
75+ };
76+}