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