at master 2.3 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 dataDir = lib.mkOption { 18 type = lib.types.str; 19 default = "/var/lib/bazarr"; 20 description = "The directory where Bazarr stores its data files."; 21 }; 22 23 openFirewall = lib.mkOption { 24 type = lib.types.bool; 25 default = false; 26 description = "Open ports in the firewall for the bazarr web interface."; 27 }; 28 29 listenPort = lib.mkOption { 30 type = lib.types.port; 31 default = 6767; 32 description = "Port on which the bazarr web interface should listen"; 33 }; 34 35 user = lib.mkOption { 36 type = lib.types.str; 37 default = "bazarr"; 38 description = "User account under which bazarr runs."; 39 }; 40 41 group = lib.mkOption { 42 type = lib.types.str; 43 default = "bazarr"; 44 description = "Group under which bazarr runs."; 45 }; 46 }; 47 }; 48 49 config = lib.mkIf cfg.enable { 50 systemd.tmpfiles.settings."10-bazarr".${cfg.dataDir}.d = { 51 inherit (cfg) user group; 52 mode = "0700"; 53 }; 54 55 systemd.services.bazarr = { 56 description = "Bazarr"; 57 after = [ "network.target" ]; 58 wantedBy = [ "multi-user.target" ]; 59 60 serviceConfig = { 61 Type = "simple"; 62 User = cfg.user; 63 Group = cfg.group; 64 SyslogIdentifier = "bazarr"; 65 ExecStart = pkgs.writeShellScript "start-bazarr" '' 66 ${cfg.package}/bin/bazarr \ 67 --config '${cfg.dataDir}' \ 68 --port ${toString cfg.listenPort} \ 69 --no-update True 70 ''; 71 Restart = "on-failure"; 72 KillSignal = "SIGINT"; 73 SuccessExitStatus = "0 156"; 74 }; 75 }; 76 77 networking.firewall = lib.mkIf cfg.openFirewall { 78 allowedTCPPorts = [ cfg.listenPort ]; 79 }; 80 81 users.users = lib.mkIf (cfg.user == "bazarr") { 82 bazarr = { 83 isSystemUser = true; 84 group = cfg.group; 85 home = cfg.dataDir; 86 }; 87 }; 88 89 users.groups = lib.mkIf (cfg.group == "bazarr") { 90 bazarr = { }; 91 }; 92 }; 93}