From 1598b34e590a3e94dd364bbada76a98115ffcf8a Mon Sep 17 00:00:00 2001 From: tv Date: Wed, 11 Nov 2026 19:01:03 +0000 Subject: 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. --- pkgs/populate/default.nix | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'pkgs') 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 -- cgit v1.3.1