photoncloud-monorepo/nix/modules/plasmavmc.nix
centra baa3e038f9 Add NixOS service modules to git tracking
The nix/modules directory was untracked, causing flake evaluation to fail
when referencing ./nix/modules. This adds 9 service module definitions
created during T024 NixOS packaging.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-09 17:34:41 +09:00

76 lines
1.9 KiB
Nix

{ config, lib, pkgs, ... }:
let
cfg = config.services.plasmavmc;
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" ];
requires = [ "iam.service" "flaredb.service" ];
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 --port ${toString cfg.port} --data-dir ${cfg.dataDir}";
};
};
};
}