{ config, lib, pkgs, ... }: let cfg = config.services.k8shost; in { options.services.k8shost = { enable = lib.mkEnableOption "k8shost service"; port = lib.mkOption { type = lib.types.port; default = 6443; description = "Port for k8shost API server"; }; dataDir = lib.mkOption { type = lib.types.path; default = "/var/lib/k8shost"; description = "Data directory for k8shost"; }; settings = lib.mkOption { type = lib.types.attrs; default = {}; description = "Additional configuration settings"; }; package = lib.mkOption { type = lib.types.package; default = pkgs.k8shost-server or (throw "k8shost-server package not found"); description = "Package to use for k8shost"; }; }; config = lib.mkIf cfg.enable { # Create system user users.users.k8shost = { isSystemUser = true; group = "k8shost"; description = "K8shost Kubernetes Hosting Service user"; home = cfg.dataDir; }; users.groups.k8shost = {}; # Create systemd service systemd.services.k8shost = { description = "K8shost Kubernetes Hosting Service"; wantedBy = [ "multi-user.target" ]; after = [ "network.target" "iam.service" "flaredb.service" "prismnet.service" ]; requires = [ "iam.service" "flaredb.service" "prismnet.service" ]; serviceConfig = { Type = "simple"; User = "k8shost"; Group = "k8shost"; Restart = "on-failure"; RestartSec = "10s"; # State directory management StateDirectory = "k8shost"; StateDirectoryMode = "0750"; # Security hardening NoNewPrivileges = true; PrivateTmp = true; ProtectSystem = "strict"; ProtectHome = true; ReadWritePaths = [ cfg.dataDir ]; # Start command ExecStart = "${cfg.package}/bin/k8shost-server --port ${toString cfg.port} --data-dir ${cfg.dataDir}"; }; }; }; }