- client/e2e/audit.test.mjs: independent player-browser traffic audit (own frame catalogue and banned-key list, never leakcheck.nim), with a -d:leakfault/otherVision negative control. - client/e2e/fogbench.test.mjs + tools/fogbench.nim: 50 tokens on a 16384 px map (server move path and headless SwiftShader cadence); results/m4-fog-bench.md records both honestly (SW is not the phone gate). - Archive prototype-* under docs/archive/prototypes (Q24); DESIGN 13 M4 done, TESTING 13 M4 accept result, HANDOFF-M4 close-out. - mutation.sh c1/c2 patch the post-#65 tile-gate line again (they had silently become sed no-ops).
14 KiB
Q20: Nix packaging of the Nim server + NixOS module
Date: 2026-11-08. Scope: research only. No repo code changed. Refs: docs/DESIGN.md Q20 (line 563) and §11.1 (line 445).
Source pins:
- NP = nixpkgs
c56a87d8e41ce69bd2af57eb35dcc117a9dfca33(26.05.20261105). This is the owner's system nixpkgs (nixos-version --json). Links below use this commit. Local store copy:/nix/store/qyccs9pc22b3fvl2lxia3jagcg97dn48-source(nim 2.2.4). - MUM = mummy commit
01deb1ff694988635c7bf0f24f6088a0bdf6db5d. - DEV =
devbox.lock(local,/home/davide/Projects/GDR/FFF_vtt/devbox.lock): nixpkgs55ba7f49ef2962b42cbd126522b7df5f95037679, nim 2.2.12, nimble 0.24.1.
1. Summary
- nixpkgs has a documented Nim builder:
buildNimPackageplus a JSONlockFile, generated bynim_lk. The owner's system nixpkgs (NP) has it. [S1][S2] - Lock entries carry the source fetch:
methodfetchzip(tarball) orgit(url,rev,sha256,srcDir,fetchSubmodules). The builder turns each into a fixed-output fetch plus--path:flag. Git-commit deps are fetched withfetchgitat the exactrev. [S1][S7][S8] - nim_builder ignores
requiresin the .nimble. Deps come only from the lock. The lock must list the full transitive closure. [S5][S1] - Not in nixpkgs:
mummy,db_connector,zippy,webby,crunchy,nimsimd(noby-nameentry, nonimPackages). They enter via the lock. [checked NP tree] - Nim 2.2.4 stdlib has no
db_*module.db_connectormust be a separate lock entry. [local stdlib] - Upstream now HAS tag
0.4.8on mummy. DESIGN says "no tags" (stale). Tag0.4.8=77a7563e. MUM is 7 commits ahead; only.github/workflows/*differ. Library code is identical. [S13][S14] - nim_builder builds only nimble
binentries. Rootfff_vtt.nimblehas none andserver/has no entrypoint yet (onlygeometry.nim). The Nix build would produce an empty package until abinis declared. [S5][local] - Devbox pins nim 2.2.12. NP's nim-2_2 is 2.2.4. Version drift must be handled by pinning the nixpkgs input, not by hoping. [DEV][S10]
.gitignorealready excludesnix/. DESIGN M6 plansnix/. Either remove that line or use another dir name before committing packaging. [local.gitignore]- Recommended:
buildNimPackage+ committednix/lock.json(fromnim_lk) +nix/module.nixmodeled on nitter's systemd unit. Devbox stays the dev shell and is untouched.
2. Findings with sources
2.1 buildNimPackage (NP)
- Builder:
pkgs/build-support/build-nim-package.nix. Phases delegate tonim_builder --phase:{configure,build,check,install}.doCheck = trueby default. [S1] lockFileis read withbuiltins.fromJSON. Eachdependsentry becomes--path:"<fod>/<srcDir>"innimFlags. Methods:fetchzip->fetchzip {url,sha256};git->fetchgit {url,rev,sha256,fetchSubmodules,leaveDotGit}.pathin the lock is ignored. [S1]nimOverridesmaps a dep name to a function of (lockAttrs, prevAttrs) to add buildInputs etc. Mummy needs none (pure Nim). [S3][S2]overrideNimAttrsexists to changesrc/lockFilebefore lock flags are generated. [S2][S1]- Nim:
nim2 = nim-2_2(NPpkgs/top-level/all-packages.nixL4248). Nim 2.2.4 in NP. [S10][all-packages] - Doc for the example and lock regeneration:
nix run -f . nim_lk ./result | jq --sort-keys > pkgs/by-name/.../lock.json. The doc says runnim_lkon the source directory. [S2]
2.2 nim_builder behavior that matters
configurePhase: writesconfig.nims(backend, nimcache,-d:release,nimDefines). It also addspathswitches fromNIX_NIM_BUILD_INPUTSnimble files, not fromrequires. [S5]buildPhase:nim compile <nimFlags> --outdir:$out/bin <srcDir>/<bin>for eachbinin the root .nimble. Nobin= nothing built. [S5]checkPhase:nim r <nimFlags> tests/t*.nim(top-leveltests/only). Root hastests/tgeometry.nim, which matches. [S5][local]- Root
nim.cfghas--mm:orcand--path:"server"; no--threads:on. Nim 2.2 stdlib config defaultsthreads:on(local.../nim/config/nim.cfgL23). Mummy needs threads on. Keep it explicit innimFlagsanyway. [local stdlib][MUM README]
2.3 Lock file format (NP)
- Generator:
nim_lk(sourcehut~ehmry/nim_lk; NPpkgs/by-name/ni/nim_lk/package.nix). It reads Nimble metadata and emits{"depends":[...]}. [S4][S2] - Entry fields seen:
method,packages,path,ref,rev,sha256,srcDir,url; git entries alsosubDir,fetchSubmodules,leaveDotGit. [S7][S8] - Example git entry:
pkgs/by-name/ni/nimlangserver/lock.json. Example fetchzip entry:pkgs/by-name/ni/nimdow/lock.json. [S7][S8] - nim_lk README: sourcehut is bot-walled from my environment. I could NOT read the README. Whether
nim_lkacceptsrequires "pkg#<commit>"and whether it readsnimble.lockis UNVERIFIED. Test it.
2.4 Dependency graph and revisions
Pinned in the owner's devbox nimble cache (docs/archive/prototypes/server-vision/.devbox/nimble/pkgs2/*/nimblemeta.json, vcsRevision). Use as the first lock target, then compare with nim_lk output.
| dep | constraint in mummy/registry | devbox-resolved vcsRevision | upstream tag check |
|---|---|---|---|
| mummy | requires "mummy#01deb1ff..." (servervision.nimble) |
01deb1ff694988635c7bf0f24f6088a0bdf6db5d |
tag 0.4.8 = 77a7563e [S13][S14] |
| zippy | mummy: >= 0.10.9 |
cd562ba43ae8904a4d1ba55611b8a521ef4a179e (0.10.20) |
tag exists [API] |
| webby | mummy: >= 0.2.1 |
325d6ade0970562bee7d7d53961a2c3287f0c4bc (0.2.1); repo treeform/webby |
no tags via API |
| crunchy | mummy: >= 0.1.11 |
98eb6526982bb8aae8eec6e8781f4539fa19e049 (0.1.11) |
tag exists [API] |
| nimsimd | crunchy dep | 3f6b2668ffb0867d0bf786a658b817763e611350 (1.3.2) |
tag exists [API] |
| db_connector | fff: requires "db_connector" (unpinned) |
29450a2063970712422e1ab857695c12d80112a6 (0.1.0) |
no tags via API [S15] |
- mummy nimble (at MUM):
requires nim >= 1.6.8,zippy >= 0.10.9,webby >= 0.2.1,crunchy >= 0.1.11. [S12] - db_connector nimble:
requires nim >= 1.7.3, no other deps. [S15] - Mummy commit diff vs tag 0.4.8: only
.github/workflows/build.ymlanddocs.yml. [S13] - Mummy README: needs
--threads:onand--mm:orcor--mm:arc. [MUM README]
2.5 Are the deps in nixpkgs?
- Checked NP tree:
pkgs/by-namehas nomummy,db_connector,zippy,webby,crunchy,nimsimddirectories. Grep ofpkgs/formummy|db_connectoronly hits unrelated files. No Nim package set (nimPackagesis empty). [NP tree] - Conclusion: all deps go through the lock. No nixpkgs package to reuse.
2.6 Alternatives
- nimble.lock (Nimble native):
nimble.lock, version 2, fieldsvcsRevision,url,downloadMethod,checksums.sha1. Written bysrc/nimblepkg/lockfile.nim. No nixpkgs builder consumes it. Converting it would be a custom script. [S18] - atlas: documents
atlas.lockviapin/repcommands. nixpkgsnim-atlasis pinned tounstable-2023-09-22(ab22f997). No nixpkgs builder readsatlas.lock. [S17][S11] - Vendored deps (no lock tool): drop
lockFile, commit deps (orfetchFromGitHubeach) and passnimFlags = ["--path:..." ...].buildNimPackagemakeslockFileoptional (optionalAttrs (hasAttr "lockFile")). Simplest, zero tooling, but every bump is manual. [S1]
2.7 NixOS module precedent
- nitter:
nixos/modules/services/misc/nitter.nixat NP, lines ~369-420. Unit:DynamicUser,StateDirectory,LoadCredential,ProtectSystem-style hardening block:ProtectHome,PrivateDevices,ProtectKernel*,RestrictAddressFamilies = [AF_INET AF_INET6],SystemCallFilter,UMask = 0077. [S9] - Nitter package:
pkgs/by-name/ni/nitter/package.nix,lockFile = ./lock.json,nixosTests. [S-nitter-pkg] - Note: nitter's
RestrictAddressFamiliesexcludesAF_UNIX. DESIGN §11.1 includesAF_UNIX; keep it only if the FFF sidecar (Q18/Q19 option b) is chosen. [DESIGN L447]
2.8 Owner's host config
/home/davide/Projects/server_nixos_configuration/configuration.nix: channel-style (<agenix/modules/age.nix>), not flake. Imports per-service files (gitea.nix,foundryvtt.nix). [local]- Precedent for a service module file imported from
imports = [...]. [localconfiguration.nixL13-23]
2.9 Devbox coexistence
devbox.json:nim: "2",nimble: "latest",NIMBLE_DIR=$DEVBOX_PROJECT_ROOT/.devbox/nimble; scriptstest=nimble test,mutation. [local devbox.json]devbox.lockresolves nim2.2.12(nixpkgs55ba7f49), nimble0.24.1. [DEV]- Nix build uses NP nim
2.2.4unless the flake pins a nixpkgs with 2.2.12. Mismatch risk. nimble testresolves deps fromrequires(registry +#commitpin). The Nix build resolves from the lock. Two resolution paths. Keep revs equal; checkvcsRevisionvalues above after lock generation..devbox/is gitignored; Nix never sees it. No interference, provided the Nix package source does not depend on.devbox/.
3. Recommendation
Use buildNimPackage + committed lock.json generated by nim_lk, pinned to the same nixpkgs as devbox (or a nixpkgs with nim 2.2.12). Package and module live in-repo under nix/. Devbox stays the dev shell only.
Steps (sketch, no files written):
- Un-ignore the packaging dir: remove
nix/from.gitignore(or name itpackaging/nix/). [local] - Declare a
bininfff_vtt.nimbleonce the entrypoint exists (for examplebin = @["main"],srcDirserver). Until then the package is empty. Alternative: overridebuildPhase. [S5] - Decide mummy ref: keep
01deb1ff(identical code to 0.4.8 except CI) or move both nimble and Nix to tag0.4.8. Fix the DESIGN "no tags" note either way. [S13] - Add
db_connectorpin to the lock (no tags upstream; pin the devboxvcsRevision). [S15] - Generate lock:
nix run <nixpkgs-with-nim_lk>#nim_lk -- <src> | jq --sort-keys > nix/lock.json. Diffrevs against the devbox table in §2.4. [S2] nix/package.nix:buildNimPackage (finalAttrs: { pname = "fff-vtt-server"; version; src = lib.cleanSource ../.; lockFile = ./lock.json; nimFlags = ["--threads:on" "--mm:orc"]; ... }). Let doCheck runtests/t*.nim. [S1][S5]nix/module.nix:options.services.fffVtt = { enable; package; port (127.0.0.1 only); publicOrigin; stateDir }.systemd.services.fff-vtt:wantedBy multi-user.target,DynamicUser,StateDirectory,ExecStart = ${cfg.package}/bin/<bin>, hardening copied from nitter (§2.7),AF_UNIXonly with sidecar. [S9][DESIGN L447]- Host: add
nix/module.nixtoimportsinserver_nixos_configuration/configuration.nix(path import orbuiltins.fetchGitpinned to a commit). Mirrorfoundryvtt.nixpattern. [local] - Smoke check:
nix buildthe package;nix-buildrunsnim r tests/t*.nimvia doCheck. OptionalnixosTestsVM test as nitter does. [S1][S9]
Fallback if nim_lk cannot resolve mummy#<commit> or db_connector: vendored deps with nimFlags --path: (§2.6). Nothing else changes.
4. Not checked / risks
- nim_lk CLI and its handling of
#commitrequires: unverified (sourcehut blocked). - No
nix buildrun; no lock generated; no fetch hashes computed. Hashes will come fromnim_lk. - Devbox nim 2.2.12 vs NP 2.2.4: pinned nixpkgs revision for the build not chosen yet.
- webby tags: none found via API. Pinned rev
325d6adeis what the devbox resolved; upstream version list not checked. nim_builder'sbinhandling assumes the root .nimble lists binaries; checked only the code, not a built example.- atlas
atlas.lockformat not read in full; only the doc summary.
5. Sources
NixOS/nixpkgs @ c56a87d8e41ce69bd2af57eb35dcc117a9dfca33 (owner's system nixpkgs):
- [S1] https://github.com/NixOS/nixpkgs/blob/c56a87d8e41ce69bd2af57eb35dcc117a9dfca33/pkgs/build-support/build-nim-package.nix
- [S2] https://github.com/NixOS/nixpkgs/blob/c56a87d8e41ce69bd2af57eb35dcc117a9dfca33/doc/languages-frameworks/nim.section.md
- [S3] https://github.com/NixOS/nixpkgs/blob/c56a87d8e41ce69bd2af57eb35dcc117a9dfca33/pkgs/top-level/nim-overrides.nix
- [S4] https://github.com/NixOS/nixpkgs/blob/c56a87d8e41ce69bd2af57eb35dcc117a9dfca33/pkgs/by-name/ni/nim_lk/package.nix
- [S5] https://github.com/NixOS/nixpkgs/blob/c56a87d8e41ce69bd2af57eb35dcc117a9dfca33/pkgs/by-name/ni/nim_builder/nim_builder.nim
- [S7] https://github.com/NixOS/nixpkgs/blob/c56a87d8e41ce69bd2af57eb35dcc117a9dfca33/pkgs/by-name/ni/nimdow/lock.json
- [S8] https://github.com/NixOS/nixpkgs/blob/c56a87d8e41ce69bd2af57eb35dcc117a9dfca33/pkgs/by-name/ni/nimlangserver/lock.json
- [S9] https://github.com/NixOS/nixpkgs/blob/c56a87d8e41ce69bd2af57eb35dcc117a9dfca33/nixos/modules/services/misc/nitter.nix
- [S-nitter-pkg] https://github.com/NixOS/nixpkgs/blob/c56a87d8e41ce69bd2af57eb35dcc117a9dfca33/pkgs/by-name/ni/nitter/package.nix
- [S10] https://github.com/NixOS/nixpkgs/blob/c56a87d8e41ce69bd2af57eb35dcc117a9dfca33/pkgs/by-name/ni/nim-2_2/package.nix
- [S11] https://github.com/NixOS/nixpkgs/blob/c56a87d8e41ce69bd2af57eb35dcc117a9dfca33/pkgs/by-name/ni/nim-atlas/package.nix
- [all-packages] https://github.com/NixOS/nixpkgs/blob/c56a87d8e41ce69bd2af57eb35dcc117a9dfca33/pkgs/top-level/all-packages.nix (L4246-4255: nim, nim1, nim2, buildNimPackage, nimOverrides)
Upstream:
- [S12] mummy nimble @ pin: https://github.com/guzba/mummy/blob/01deb1ff694988635c7bf0f24f6088a0bdf6db5d/mummy.nimble
- [MUM README] https://github.com/guzba/mummy/blob/01deb1ff694988635c7bf0f24f6088a0bdf6db5d/README.md
- [S13] tag compare: https://api.github.com/repos/guzba/mummy/compare/77a7563e87a1045e4e407a3a68731e299fa3507e...01deb1ff694988635c7bf0f24f6088a0bdf6db5d
- [S14] mummy tags: https://api.github.com/repos/guzba/mummy/tags
- [S15] db_connector nimble: https://github.com/nim-lang/db_connector/blob/master/db_connector.nimble
- [S17] atlas doc: https://github.com/nim-lang/atlas/blob/master/doc/atlas.md
- [S18] nimble lockfile impl: https://github.com/nim-lang/nimble/blob/master/src/nimblepkg/lockfile.nim
- [API] zippy/crunchy/nimsimd tags: https://api.github.com/repos/guzba/zippy/tags , https://api.github.com/repos/guzba/crunchy/tags , https://api.github.com/repos/guzba/nimsimd/tags
Local (read-only):
- devbox.json / devbox.lock: /home/davide/Projects/GDR/FFF_vtt/devbox.json, /home/davide/Projects/GDR/FFF_vtt/devbox.lock
- devbox nimble cache (vcsRevision): /home/davide/Projects/GDR/FFF_vtt/docs/archive/prototypes/server-vision/.devbox/nimble/pkgs2/*/nimblemeta.json
- nim 2.2.4 stdlib (threads default, no db_* modules): /nix/store/aa4fgarndnvq417l50imvqx5fdrrx9sn-nim-unwrapped-2.2.4/nim/config/nim.cfg, /nix/store/aa4fgarndnvq417l50imvqx5fdrrx9sn-nim-unwrapped-2.2.4/nim/lib
- owner config: /home/davide/Projects/server_nixos_configuration/configuration.nix, foundryvtt.nix
- repo .gitignore: /home/davide/Projects/GDR/FFF_vtt/.gitignore