Files
dotfiles/systems/jeeves/services/gems.nix
T

92 lines
2.0 KiB
Nix

{
inputs,
pkgs,
...
}:
let
vars = import ../vars.nix;
stateDir = "${vars.services}/gems";
gemsPackages =
ps: with ps; [
fastapi
jinja2
pydantic
pydantic-settings
python-multipart
typer
uvicorn
];
in
{
nixpkgs.overlays = [
(final: _prev: {
gems_python = final.python314.withPackages gemsPackages;
gems_test_python = final.python314.withPackages (
ps:
gemsPackages ps
++ (with ps; [
httpx
pytest
pytest-asyncio
pytest-xdist
])
);
gems_tests =
final.runCommand "gems-tests"
{
nativeBuildInputs = [ final.gems_test_python ];
}
''
export HOME="$TMPDIR"
cd ${inputs.self}
pytest -o cache_dir="$TMPDIR/pytest-cache" tests/gems
touch "$out"
'';
})
];
system.checks = [ pkgs.gems_tests ];
users.groups.gems = { };
users.users.gems = {
isSystemUser = true;
group = "gems";
home = stateDir;
};
systemd.tmpfiles.rules = [
"d ${stateDir} 0750 gems gems - -"
];
systemd.services.gems = {
description = "Gems multiplayer game";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
environment = {
PYTHONPATH = "${inputs.self}";
GEMS_DATABASE_PATH = "${stateDir}/gems.sqlite3";
GEMS_KEY_PATH = "${stateDir}/instance.key";
GEMS_PUBLIC_ORIGIN = "https://gems.tmmworkshop.com";
GEMS_SECURE_COOKIES = "true";
};
serviceConfig = {
Type = "simple";
User = "gems";
Group = "gems";
ExecStart = "${pkgs.gems_python}/bin/python -m python.gems.main --host 0.0.0.0 --port 8002";
Restart = "on-failure";
RestartSec = "5s";
StandardOutput = "journal";
StandardError = "journal";
NoNewPrivileges = true;
PrivateTmp = true;
ProtectHome = true;
ProtectSystem = "strict";
ReadOnlyPaths = [ "${inputs.self}" ];
ReadWritePaths = [ stateDir ];
};
};
}