{config, pkgs, lib, self, system, ... }: let cfg = config.services.gatekeeper; in { options = { services.gatekeeper = { enable = lib.mkEnableOption "Enable the gatekeeper api service."; dotenv = lib.mkOption { type = lib.types.path; description = "The path to a .env file with the keys"; }; db = lib.mkOption { type = lib.types.path; description = "Where to save the database."; }; }; }; config = lib.mkIf cfg.enable { users.groups.gatekeeper = {}; users.users.gatekeeper = { description = "gatekeeper user"; group = "gatekeeper"; isSystemUser = true; }; services.pcscd = { enable = true; plugins = [ pkgs.acsccid ]; }; networking.firewall.allowedTCPPorts = [ 8000 ]; systemd.services.gatekeeper = { description = "Runs the gatekeeper api"; script = '' export LD_LIBRARY_PATH="${lib.getLib pkgs.pcsclite}/lib''${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" exec ${self.packages.${system}.default}/bin/uvicorn --host 0.0.0.0 --port 8000 --app-dir ${self} app.main:app ''; after = [ "network.target" ]; wantedBy = ["multi-user.target"]; serviceConfig = { User = "gatekeeper"; Restart = "on-failure"; RestartSec = "20"; StateDirectory = "gatekeeper"; WorkingDirectory = "/var/lib/gatekeeper"; }; }; }; }