diff options
| author | tv <tv@krebsco.de> | 2026-11-11 19:01:03 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-11 19:01:03 +0000 |
| commit | 1598b34e590a3e94dd364bbada76a98115ffcf8a (patch) | |
| tree | 1bf3c67b0ca648ee9794cfbf1a3dba6c5e9586fe /pkgs/populate/default.nix | |
| parent | 8343006ff1154be2dd9ebf862afe5caed02044c7 (diff) | |
populate: add flake-input source type
The flake-input source type delivers an input of a flake, as recorded in the
flake's lock file, and the flake source type delivers the flake itself.
fetchOnTarget belongs to flake-input, because only a locked input can be
fetched on the target.
Diffstat (limited to 'pkgs/populate/default.nix')
| -rw-r--r-- | pkgs/populate/default.nix | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/pkgs/populate/default.nix b/pkgs/populate/default.nix index adf8479..c1bd9b8 100644 --- a/pkgs/populate/default.nix +++ b/pkgs/populate/default.nix @@ -190,10 +190,14 @@ let in rsync' target config sourcePath; - pop.flake = target: source: let + # Delivers the flake itself, as its input named null. Only inputs can be + # fetched on the target, so fetchOnTarget is always false here. + pop.flake = target: source: + pop.flake-input target (source // { name = null; fetchOnTarget = false; }); + + pop.flake-input = target: source: let nix' = "${nix}/bin/nix --extra-experimental-features ${quote "nix-command flakes"}"; - input = source.input or null; - inputPath = if input == null then [] else splitString "/" input; + inputPath = if source.name == null then [] else splitString "/" source.name; fetchOnTarget = source.fetchOnTarget or false; # Caches per-flake information, so it's obtained only once, even if # several sources use the same flake. @@ -211,12 +215,12 @@ let ''; noInput = /* sh */ '' >&2 printf 'error: flake %s has no input %s\n' \ - ${quote source.flake} ${quote (toString input)} + ${quote source.flake} ${quote (toString source.name)} exit 1 ''; # jq filter selecting the flake or input in nix flake archive's output. node = - if input == null then "." + if source.name == null then "." else concatMapStrings (name: ".inputs[${toJSON name}]") inputPath; # jq filter selecting the locked input and its own inputs in nix flake # metadata's output, as fetchTree arguments, the input first. @@ -287,10 +291,8 @@ let } ''; in - if fetchOnTarget && input == null then - throw "krops: flake source ${target.path}: fetching on the target needs an input" - else if !fetchOnTarget && !isLocalTarget target && target.sudo then - throw "krops: flake source ${target.path}: copying to targets with sudo is not supported" + if !fetchOnTarget && !isLocalTarget target && target.sudo then + throw "krops: source ${target.path}: copying flakes to targets with sudo is not supported" else if fetchOnTarget then /* sh */ '' set -efu |
