#462 Nix flake and NixOS module (#461)
–
- github
- github/openchronology/timeline-app
- github/openchronology/timeline-app#462
- pull request
- state:merged
Closes #461. OpenChronology for Nix and NixOS: the repository is now a flake ([docs/nix.md](docs/nix.md)). ## Packages All four are built from source for `x86_64-linux` and `aarch64-linux`: | Package | How it's built | | --- | --- | | `openchronology-server` (default) | `buildNpmPackage`, its npm dependencies pinned by `package-lock.json` through `importNpmLock`, so there's no hash to keep in step | | `och-convert` | pinned by `native-store/Cargo.lock` | | `openchronology-desktop` | the Tauri hook, pinned by `src-tauri/Cargo.lock` | | `pgmp` | the commit the Dockerfiles pin, for whichever PostgreSQL the package set uses | - **Layout:** the server is installed as the Debian package lays it out, with the same commands (`openchronology-server`, `-migrate`, `-reset-admin-password`, `-mail`, `-syslog`, `-journald`, `och-import-logs`). - **Source archive:** it includes the archive the site's footer links to, with the converter's crates. - **Native modules:** npm's prebuilt ones (sharp, libvips) are patched to find the C++ runtime on NixOS. - **No network during builds:** everything builds in Nix's sandbox. ## `services.openchronology` - **Database:** PostgreSQL with `pgmp`, the database and its role, reached by peer authentication. - **Encryption key:** `AUTH_ENCRYPTION_KEY` is generated once in `/var/lib/openchronology`. - **The server:** it migrates the database as it starts and runs with the Debian unit's hardening. Switching to a new flake input migrates and restarts it. - **Configuration:** `settings` for configuration, and `environmentFile` for secrets, which stay out of the store. - **Optional services:** the mail worker, the syslog receiver and the journald follower, which runs in the `systemd-journal` group. - **Optional nginx virtual host:** it replaces `X-Forwarded-For` with the client's address, so `TRUST_PROXY` is set. Add `enableACME` and `forceSSL` for HTTPS. ## Tests - **`nix/test.nix` (`checks.x86_64-linux.nixos`)** boots a machine with the module and nginx. Its client signs in as the configured administrator, then saves, searches and downloads a timeline as `.och`. It also checks that the key survives a restart. - It passed on an Arch machine with KVM; the test itself took 28 seconds. - Without KVM it is emulated, so the test machine gives PostgreSQL and the server long start timeouts. - **Built locally with the sandbox on:** the server, the desktop app, `och-convert` and `pgmp`. The server also ran against Nix's PostgreSQL with `pgmp`: its migration, home page, editor, source archive and search API all worked. - **Not yet built:** the aarch64 packages. CI will build them first, on `ubuntu-24.04-arm`. ## CI and releases - **`nix.yml`:** builds the packages on both architectures and runs the NixOS test with KVM. `ci.yml` calls it on every push, and `release.yml` on releases. - **Cachix:** releases push there once a cache is configured, with the `CACHIX_CACHE` variable and the `CACHIX_AUTH_TOKEN` secret. Until then the job notes that it skipped. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_011fFY8eruEi1xAkkMBni13B https://github.com/openchronology/timeline-app/pull/462