aboutsummaryrefslogtreecommitdiffstats
path: root/pkgs/populate/src/main.rs
Commit message (Collapse)AuthorAgeFilesLines
* populate: a lock, a journal, and a record of each runtv10 days1-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* populate: populate shell, running shell code on a targettv2026-11-141-11/+13
| | | | | | | | | | | | | | | | populate shell [OPTION]... TARGET SCRIPT runs SCRIPT with /bin/sh on TARGET, reached like populate reaches it, deciding whether it's local when it runs, with local or remote as $1, so SCRIPT can tell. It takes populate's target options but --path, and --tty, giving SCRIPT a terminal on a remote target, and --local-only, failing before connecting unless the target is local. It replaces itself with the command running SCRIPT, so the exit status, the terminal, and signals are SCRIPT's. krops can run nixos-rebuild with it, which needs whether the target is local, unless it decides that during evaluation, which pure evaluation can't. The command line's parsing is shared between populate and populate shell.
* populate: a command line instead of a spectv2026-11-141-20/+45
| | | | | | | | | | | | | | | | | | | | | The program takes populate's arguments on its command line, like other programs: populate [OPTION]... SOURCES [TARGET], with the sources as JSON in the file SOURCES, or on standard input for -. TARGET has the syntax of krops' lib's mkTarget, [USER@][HOST][:PORT][PATH], parsed the same way, and what it leaves out gets filled in when populate runs, as mkTarget would, from LOGNAME and the machine's name. Options set what the syntax can't express, or override its parts: --sudo, --ssh-arg, --user, --host, --port, --path, and --local or --remote for whether the target is the machine populate runs on, which populate otherwise decides like isLocalTarget. The sources carry no version. pkgs.populate passes a target attribute set, as mkTarget returns it, part by part, with --local or --remote as evaluation decides, so nothing changes for krops. A target string goes to the program as it is. The program also refuses target hosts and users starting with -, which ssh would take for options, now that a command line can give them.
* populate: exit with the status of the command that failedtv2026-11-131-1/+1
| | | | | | | | | | | The shell implementation runs under set -e, so it exits with the status of the command that failed, e.g. 255 if ssh can't reach the target, which wrappers retrying on connection failures rely on, or 128 if git fetch fails. The program does the same, instead of exiting with 1, and with 128 plus the signal for a command a signal ended. A phase's expect.status is the exit status it expects populate to fail with; git-status checks git fetch's.
* populate: deliver flake and flake-input sources natively in Rusttv2026-11-131-0/+1
| | | | | | | | | | | src/flake_input.rs reads what nix flake metadata and nix flake archive print as JSON itself: it selects the flake or input, decides what the target fetches or gets copied, and computes the store paths to root, which are what selected.jq, selfIsRemote.jq, selfLocked.jq, and the Nix expressions of the shell implementation do there. On the target, fixed snippets in sh::flake run Nix, getting values as positional parameters, and send JSON or store paths back. The jq test's cases are unit tests of the Rust equivalents.
* populate: deliver flakes and draw inputs with the Rust programtv2026-11-131-0/+1
| | | | | | | | | | | | | The program delivers flake and flake-input sources, draws inputs from sources, and removes state that sources don't need anymore, so it does everything the shell implementation does, and passes all scenarios. src/flake.rs builds the same shell code as shell.nix generates for these, with every value quoted, so both implementations behave alike while that code moves to Rust piece by piece. The ssh scripts in the temporary directory run the ssh that was in PATH when populate started, so one can be ssh in PATH for nix copy. The other one is for nix copy's ssh:// store, without the control socket.
* populate: deliver sources other than flakes with the Rust programtv2026-11-131-2/+29
| | | | | | | | | | | | | | | | | | | | | | The program delivers derivation, file, git, pass, passage, pipe, and symlink sources, makes backups, and prunes, as the shell implementation does, with the same messages. Commands on the target are fixed shell snippets in src/sh.rs, which get values as positional parameters, run directly for local targets and over ssh, sharing one master connection, for remote ones. rsync's transfers and its check for .rsync-filter files it can't read are in src/rsync.rs. Given flake or flake-input sources, or sources drawing inputs from others, the program fails before changing anything, saying that these aren't implemented yet. SIGHUP, SIGINT, and SIGTERM make populate stop once the command it waits for ends, stop the ssh master, remove its temporary directory, and exit with 128 plus the signal's number. The spec's target gets local, which rust.nix sets during evaluation, like the other functions of krops decide, and which the program decides when it runs if it's null. The spec comes on file descriptor 3, so the commands populate runs keep standard input, and the tools populate runs come first in PATH.
* populate: add a Rust implementation, selectable for the teststv2026-11-131-0/+55
pkgs.populate takes implementation: "shell", the default, generates a script from populate's arguments, and "rust" passes them as JSON to the program in pkgs/populate, built from the crate there by program.nix. The program checks the spec as checks.nix does during evaluation, with the same messages, and reports that delivering sources isn't implemented yet. rustProgram replaces the program, e.g. with one built some other way. checks.nix holds the checks of populate's arguments during evaluation. Both implementations check the names of sources and the target path with it, and the Rust one's wrapper also checks drawing inputs, which the shell implementation checks where it draws them. nix-build tests --argstr implementation rust runs the scenarios with the Rust implementation. They expect it to refuse copying flakes to targets using sudo when it runs, not during evaluation, because only then it decides whether the target is local.