{ lib, nglib, pkgs, config, ... }: let cfg = config.services.jellyseerr; cfgInit = config.init.services.jellyseerr; in { options.services.jellyseerr = { enable = lib.mkEnableOption "jellyseerr"; package = lib.mkPackageOption pkgs "jellyseerr" {}; port = lib.mkOption { description = '' The port Jellyseerr should listen on. ''; type = lib.types.port; example = 8080; default = 5055; }; configDir = lib.mkOption { description = '' The directory to save run-time configuration. ''; type = lib.types.str; example = "/jellyseerr"; default = "/var/lib/jellyseerr"; }; }; config = lib.mkIf cfg.enable { init.services.jellyseerr = { enabled = true; script = pkgs.writeShellScript "jellyseerr-run" '' umask 0002 ${lib.getExe cfg.package} ''; user = lib.mkDefault "jellyseerr"; group = lib.mkDefault "jellyseerr"; }; environment = { systemPackages = [cfg.package]; variables = { PORT = builtins.toString cfg.port; CONFIG_DIRECTORY = cfg.configDir; }; }; users.users.${cfgInit.user} = lib.mkIf (cfgInit.user == "jellyseerr") (nglib.mkDefaultRec { description = "jellyseerr"; group = cfgInit.group; createHome = false; home = "/var/empty"; useDefaultShell = true; uid = config.ids.uids.jellyseerr; }); users.groups.${cfgInit.group} = lib.mkIf (cfgInit.group == "jellyseerr") (nglib.mkDefaultRec {gid = config.ids.gids.jellyseerr;}); }; }