diff options
| author | tv <tv@krebsco.de> | 2026-11-13 20:11:00 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-13 21:56:24 +0100 |
| commit | cdca948326a61f21caf7a24090655b8404705e50 (patch) | |
| tree | b570d2a15cff7c5eaed6b0859d849fe525a8a499 /pkgs | |
| parent | d36d2e631e4baceed0a8c0c00859ebb2ab8cb82f (diff) | |
populate: warn about the arguments it doesn't use
dash, jq, and implementation, which overrides of the shell
implementation set, come through ..., because callPackage sets named
arguments, so populate can tell they're set, and warns that they're
unused. Other arguments populate doesn't know fail, as they do for
named arguments.
Diffstat (limited to 'pkgs')
| -rw-r--r-- | pkgs/populate/default.nix | 99 |
1 files changed, 57 insertions, 42 deletions
diff --git a/pkgs/populate/default.nix b/pkgs/populate/default.nix index f0b3411..c846826 100644 --- a/pkgs/populate/default.nix +++ b/pkgs/populate/default.nix @@ -1,54 +1,69 @@ # Populate, which delivers sources to a target directory. Given populate's # 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 +# built with cargo during development. +{ coreutils, findutils, git, nix, openssh, pass, passage, rsync, writers , rustPlatform ? null , rustProgram ? import ./program.nix { inherit rustPlatform; } -}: +, ... +}@args: 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; - }; - }; + # Arguments populate doesn't use, which overrides written for krops 1 may + # set. They come through ..., because callPackage would set named ones. + unused = filter (name: args ? ${name}) [ "dash" "implementation" "jq" ]; + unexpected = attrNames (removeAttrs args ([ + "coreutils" "findutils" "git" "nix" "openssh" "pass" "passage" "rsync" + "writers" "rustPlatform" "rustProgram" + ] ++ unused)); + + populate = + { 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 + 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 + ''; + 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 -'' + +if unexpected != [] then + throw "krops: populate called with unexpected argument ${head unexpected}" +else + foldr + (name: warn "krops: populate's argument ${name} is unused") + populate + unused |
