{ lib, nglib, config, pkgs, ... }: let cfg = config.services.bazarr; cfgInit = config.init.services.bazarr; in { options.services.bazarr = { enable = lib.mkEnableOption "bazarr"; package = lib.mkPackageOption pkgs "bazarr" {}; configDir = lib.mkOption { description = "Where Bazarr's configuration files are stored."; type = lib.types.str; default = "/config"; }; }; config = lib.mkIf cfg.enable { init.services.bazarr = { enabled = true; user = lib.mkDefault "bazarr"; group = lib.mkDefault "bazarr"; script = pkgs.writeShellScript "bazarr-run" '' umask 0002 ${lib.getExe cfg.package} \ --no-update \ --config '${cfg.configDir}' ''; }; environment.systemPackages = [cfg.package]; users.users.${cfgInit.user} = lib.mkIf (cfgInit.user == "bazarr") (nglib.mkDefaultRec { description = "bazarr"; group = cfgInit.group; createHome = false; home = "/var/empty"; useDefaultShell = true; uid = config.ids.uids.bazarr; }); users.groups.${cfgInit.group} = lib.mkIf (cfgInit.group == "bazarr") (nglib.mkDefaultRec {gid = config.ids.gids.bazarr;}); }; }