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