diff options
| author | tv <tv@krebsco.de> | 2026-11-20 00:51:27 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-20 00:51:27 +0000 |
| commit | 61840ec59bc13b9b2ae6d29fff7276c849684941 (patch) | |
| tree | 0b5299e337758b34cd4982ed4e0c2d8eb3655f0f /pkgs/populate/README.md | |
| parent | 275b9f6102e6f3011099752ec1023a11b326fc45 (diff) | |
populate: a lock, a journal, and a record of each run
For consumers of the target directory on the target, e.g. a CI service,
which should act after a run that delivered everything, and know what it
delivered.
Populate holds an exclusive flock on .populate/lock from right after
checking the sentinel until it's done. The command holding it runs over
the shared connection, or directly, keeping the lock until its input
ends, which populate's ending ends as well, so no lock stays behind.
Runs wait for each other, and for consumers holding a shared lock,
saying so. The sentinel is a directory, which a sentinel file becomes,
since there's always state to keep now, and the target needs flock.
Populate keeps a journal in .populate/journal, a line of JSON for each
entry: a run starting, beginning to deliver or change a source, what
that changed, and pruning. The entries go with the next command on the
target, before what that changes, so the journal needs no commands of
its own. After delivering everything, populate replaces
.populate/run.json with the record of the run, which sums up the
journal, and removes the journal. A run that doesn't finish leaves it,
so changed in the record means changed since the last record: a source
the journal tells began changing, without what it changed, counts as
changed. The record has, for each source, its type, whether it changed,
and what got delivered: the commit of a git source, the store path of a
flake, flake-input, or derivation source, and the derived one, and a
symlink's target. Nothing about secrets, nor files.
Each source type is a Kind, whose deliver returns the Outcome: whether
anything changed, and what got delivered. rsync tells changes by what
it itemizes, the snippets by printing changed: the git source if it
cloned, reset, or submodule updates or cleaning printed anything, links
if they point elsewhere, and lock files and generated flakes if they
differ. Symlinks in place of the lock or the journal get refused.
A file or git source whose lock file populate rewrites in place counts
as changed on every run, since delivering it brings back the original.
Diffstat (limited to 'pkgs/populate/README.md')
| -rw-r--r-- | pkgs/populate/README.md | 68 |
1 files changed, 60 insertions, 8 deletions
diff --git a/pkgs/populate/README.md b/pkgs/populate/README.md index e0015fa..8e3232d 100644 --- a/pkgs/populate/README.md +++ b/pkgs/populate/README.md @@ -27,9 +27,10 @@ fetches the program's dependencies from [crates.io](https://crates.io). populate runs rsync, ssh, Git, Nix, pass, and passage as the sources need them, found in `PATH`, as well as a POSIX shell, coreutils, and findutils. -The target needs a POSIX shell, coreutils, findutils, rsync, `patch` for -sources with `patches`, Git for `git` sources, and Nix, and, if remote, -ssh access as root, or, with `--sudo`, as a user who may use `sudo`. +The target needs a POSIX shell, coreutils, findutils, `flock`, rsync, +`patch` for sources with `patches`, Git for `git` sources, and Nix, and, if +remote, ssh access as root, or, with `--sudo`, as a user who may use +`sudo`. NixOS has all of them but Git, and rsync as long as `environment.defaultPackages` contains it. Features that say so need Nix with flake support (Nix 2.4 or later) on the machine that uses them. @@ -205,9 +206,61 @@ everything else. It doesn't change or remove anything outside: and replaces lock files it rewrites, by renaming new files into place, and only makes directories writable that it removes. -* Populate keeps its state in the sentinel, `.populate`, which becomes a - directory once there is state to keep. Populating fails if the sentinel, - or a directory populate needs therein, is a symlink. +* Populate keeps its state in the sentinel, `.populate`, a directory, which + a sentinel file becomes. Populating fails if the sentinel, or a directory + populate needs therein, is a symlink. + +### The run record and the lock + +Populate holds an exclusive lock on `.populate/lock`, with `flock`, from +before it changes anything in the target directory until it's done. Runs +wait for each other, and a consumer of the target directory, e.g. a service +building what got deployed, can take a shared lock while it uses what's +there, which populate waits for, saying so, so it never sees a half +delivered target directory: + +```sh +flock --shared /var/src/.populate/lock cp -R /var/src/some-source /build +``` + +After delivering all sources, populate replaces `.populate/run.json` with +the record of the run, which a systemd path unit can watch, e.g.: + +```json +{ + "version": 0, + "populate": "2.0.0", + "started": "2026-11-20T12:34:56Z", + "finished": "2026-11-20T12:35:01Z", + "changed": true, + "sources": { + "nixos-config": { "type": "file", "changed": false }, + "nixpkgs": { "type": "git", "changed": true, "commit": "ac588ef1c914..." }, + "dotnix": { "type": "flake-input", "changed": false, + "storePath": "/nix/store/...-source", "derived": "/nix/store/...-source" }, + "current": { "type": "symlink", "changed": false, "target": "nixos-config" } + } +} +``` + +- `version` is the record's format, and `populate` populate's version. +- `started` and `finished` are in UTC, by the clock of the machine populate + runs on. +- `changed` tells whether anything in the target directory changed since + the last record, also in runs that didn't finish, and so does each + source's. Pruning anything counts as a change of the target directory. + `file`, `pipe`, `pass`, and `passage` sources get nothing else, so the + record holds nothing about secrets. +- What got delivered: `commit` for `git` sources, `storePath` for `flake`, + `flake-input`, and `derivation` sources, `derived` for `flake` and + `flake-input` sources whose copy got patched or got its lock file + rewritten, and `target` for `symlink` sources. + +Until a run finishes, populate keeps a journal in `.populate/journal` of +what it began changing, and what that changed, which the next run that +finishes sums up in its record. A `file` or `git` source whose lock file +populate rewrites in place gets its original lock file back, and rewritten +again, on every run, so it counts as changed every time. ## Source Types @@ -286,8 +339,7 @@ if it lacks any of them, and the target path becomes a symlink to the flake's store path, registered as garbage collector root. For flakes in a subdirectory, e.g. `git+file:/src/mono?dir=sub`, the symlink points at that subdirectory of the store path. The inputs get garbage collector roots in -`.populate/flake-inputs/<name>`, which turns the sentinel file into a -directory. +`.populate/flake-inputs/<name>`. Supported attributes: |
