Files
Battle-for-Tismo/nix/package.nix
T
2026-09-16 19:59:18 +02:00

69 lines
1.9 KiB
Nix

# Packages the HTML5/JavaScript build for headless deployment:
# - `app` : the Node game server plus the static browser client
# - `server` : a wrapper that runs the authoritative WebSocket/HTTP server
# - `web` : the static client (index.html, scripts, shared modules, assets)
#
# There is no build step and no runtime dependency: the server is plain Node.js
# ESM and the client is plain ES modules plus a vendored jQuery. The dev-only
# packages (`c8`, `jsdom`) are not part of these outputs.
{
lib,
stdenvNoCC,
runCommand,
writeShellScriptBin,
nodejs,
}:
let
version = "0.1.0";
# Only the files the running game needs; development-only material (test
# suite, git hooks, coverage output, installed node_modules) is left out.
src = lib.cleanSourceWith {
src = ../.;
filter =
path: type:
!(builtins.elem (baseNameOf (toString path)) [
"node_modules"
"coverage"
"githooks"
"scripts"
"tests"
"result"
".git"
]);
};
app = stdenvNoCC.mkDerivation {
pname = "battle-for-tismo";
inherit version src;
strictDeps = true;
installPhase = ''
runHook preInstall
mkdir -p $out/share/battle-for-tismo
cp -r client server shared package.json $out/share/battle-for-tismo/
runHook postInstall
'';
};
server = writeShellScriptBin "battle-for-tismo-server" ''
exec ${nodejs}/bin/node ${app}/share/battle-for-tismo/server/server.js "$@"
'';
# nginx serves this directory at "/", so it must keep the `client/` and
# `shared/` layout: browser modules import `../../shared/...` and the server
# redirects "/" to "/client/index.html".
web = runCommand "battle-for-tismo-web" { } ''
mkdir -p $out
cp -r ${app}/share/battle-for-tismo/client $out/client
cp -r ${app}/share/battle-for-tismo/shared $out/shared
'';
in
{
inherit app server web;
}