aboutsummaryrefslogtreecommitdiffstats
path: root/pkgs/populate/default.nix
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-13 21:28:11 +0100
committertv <tv@krebsco.de>2026-11-13 21:28:11 +0100
commitd36d2e631e4baceed0a8c0c00859ebb2ab8cb82f (patch)
tree98227d0091b8b23c0c69dcc3e5a770a0da291a37 /pkgs/populate/default.nix
parentbcffc9b0a00f3c49db71fe61e8185b9b8e281e55 (diff)
populate: drop the shell implementation
Populate is the program in Rust only. pkgs.populate checks its arguments, and returns a script running the program with them as JSON. The arguments it took for the shell implementation, dash, jq, and implementation, stay accepted and unused, so overrides setting them keep working. Copying flakes to remote targets using sudo gets refused during evaluation, as before, by checks.nix, and by the program for specs from elsewhere. The jq test goes with the jq programs; the program's unit tests cover their equivalents.
Diffstat (limited to 'pkgs/populate/default.nix')
-rw-r--r--pkgs/populate/default.nix68
1 files changed, 49 insertions, 19 deletions
diff --git a/pkgs/populate/default.nix b/pkgs/populate/default.nix
index c259b15..f0b3411 100644
--- a/pkgs/populate/default.nix
+++ b/pkgs/populate/default.nix
@@ -1,24 +1,54 @@
# Populate, which delivers sources to a target directory. Given populate's
-# arguments, it returns the command delivering them. implementation selects
-# how: "shell" generates a script from the arguments, "rust" runs the
-# program in this directory with the arguments as JSON. rustProgram is that
-# program, e.g. one built with cargo during development.
-{ coreutils, dash, findutils, git, jq, nix, openssh, pass, passage, rsync
-, writers
-, implementation ? "shell"
+# arguments, it checks them, and returns a script running the program in
+# this directory with them as JSON. rustProgram is that program, e.g. one
+# built with cargo during development. dash, jq, and implementation are
+# unused, and stay for overrides that set them.
+{ coreutils, dash ? null, findutils, git, jq ? null, nix, openssh, pass
+, passage, rsync, writers
+, implementation ? null
, rustPlatform ? null
, rustProgram ? import ./program.nix { inherit rustPlatform; }
}:
-if implementation == "shell" then
- import ./shell.nix {
- inherit coreutils dash findutils git jq nix openssh pass passage rsync
- writers;
- }
-else if implementation == "rust" then
- import ./rust.nix {
- inherit coreutils findutils git nix openssh pass passage rsync writers;
- program = rustProgram;
- }
-else
- throw "populate: unknown implementation ${builtins.toJSON implementation}"
+with import ../../lib;
+
+let
+ checks = import ./checks.nix;
+in
+
+{ backup ? false, force ? false, prune ? false, source, target }:
+assert checks.checkTargetPath target.path;
+assert all checks.checkSourceName (attrNames source);
+assert checks.checkInputs source;
+assert checks.checkCopyingWithSudo target source;
+let
+ # Store paths in the arguments stay dependencies of the script, so
+ # building it builds them.
+ spec = toJSON {
+ version = 1;
+ inherit backup force prune source;
+ target = {
+ inherit (target) host path;
+ user = target.user or null;
+ port = if target.port or null == null then null else toString target.port;
+ sudo = target.sudo or false;
+ extraOptions = target.extraOptions or [];
+ # Decided during evaluation, like the other functions of krops do.
+ local = isLocalTarget target;
+ };
+ };
+in
+writers.writeDash "populate.${target.host}" /* sh */ ''
+ set -efu
+ echo + "$0" >&2
+ # The tools populate depends on, in front of others of the same name.
+ PATH=${makeBinPath [
+ coreutils findutils git nix openssh pass passage rsync
+ ]}''${PATH:+:$PATH}
+ export PATH
+ # On a file descriptor of its own, so the commands populate runs keep
+ # standard input. The JSON is a single line, which can't be the delimiter.
+ exec ${rustProgram}/bin/populate /dev/fd/3 3<<'EOF'
+ ${spec}
+ EOF
+''