at 23.11-pre 2.0 kB view raw
1{ config, pkgs, lib, ... }: 2 3with lib; 4 5let 6 cfg = config.services.bazarr; 7in 8{ 9 options = { 10 services.bazarr = { 11 enable = mkEnableOption (lib.mdDoc "bazarr, a subtitle manager for Sonarr and Radarr"); 12 13 openFirewall = mkOption { 14 type = types.bool; 15 default = false; 16 description = lib.mdDoc "Open ports in the firewall for the bazarr web interface."; 17 }; 18 19 listenPort = mkOption { 20 type = types.port; 21 default = 6767; 22 description = lib.mdDoc "Port on which the bazarr web interface should listen"; 23 }; 24 25 user = mkOption { 26 type = types.str; 27 default = "bazarr"; 28 description = lib.mdDoc "User account under which bazarr runs."; 29 }; 30 31 group = mkOption { 32 type = types.str; 33 default = "bazarr"; 34 description = lib.mdDoc "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 isSystemUser = true; 68 group = cfg.group; 69 home = "/var/lib/${config.systemd.services.bazarr.serviceConfig.StateDirectory}"; 70 }; 71 }; 72 73 users.groups = mkIf (cfg.group == "bazarr") { 74 bazarr = {}; 75 }; 76 }; 77}