From d63531d2d42524f5150d138000bec42fd49d1e71 Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 12 Nov 2026 02:33:43 +0000 Subject: populate: draw inputs from sources that aren't flakes Generated flakes declared every source they draw inputs from as a flake, so drawing an input declared with flake = false from a source without flake.nix failed, although the README says it works. Such sources get declared with flake = false now. An edge case draws a non-flake input from a source without flake.nix. --- pkgs/populate/default.nix | 5 +++++ tests/fixtures.sh | 11 +++++++++++ tests/scenarios.nix | 11 +++++++++++ 3 files changed, 27 insertions(+) diff --git a/pkgs/populate/default.nix b/pkgs/populate/default.nix index 06197b6..08a624b 100644 --- a/pkgs/populate/default.nix +++ b/pkgs/populate/default.nix @@ -108,6 +108,11 @@ let printf ' inputs.%s.url = "%s";\n' ${quote (toJSON name)} "$url" ${concatImapStrings (i: source: /* sh */ '' printf ' inputs.%s.url = "%s";\n' ${quote (toJSON source)} "$url${toString i}" + ${optionalString (!generated ? ${source}) /* sh */ '' + if ! test -e "$(readlink -f ${quote "${target.path}/${source}"})"/flake.nix; then + printf ' inputs.%s.flake = false;\n' ${quote (toJSON source)} + fi + ''} '') drawn} ${concatMapStrings (x: /* sh */ '' printf ' %s\n' ${quote (override x)} diff --git a/tests/fixtures.sh b/tests/fixtures.sh index 8222b13..1f6c478 100755 --- a/tests/fixtures.sh +++ b/tests/fixtures.sh @@ -233,6 +233,17 @@ cat > /fixtures/c2/flake.nix <<'NIX' { outputs = _: { who = "c2"; }; } NIX +# usedata, data: a flake with an input that isn't a flake, and a directory +# to draw it from. +mkdir /fixtures/usedata /fixtures/data +cat > /fixtures/usedata/flake.nix <<'NIX' +{ + inputs.data = { url = "path:/nonexistent"; flake = false; }; + outputs = { data, ... }: { msg = "data:${builtins.readFile (data + "/value")}"; }; +} +NIX +printf hello > /fixtures/data/value + # noflake: a directory without flake.nix. mkdir /fixtures/noflake echo noflake > /fixtures/noflake/README diff --git a/tests/scenarios.nix b/tests/scenarios.nix index 5dd44db..eeeb665 100644 --- a/tests/scenarios.nix +++ b/tests/scenarios.nix @@ -883,6 +883,17 @@ assert !(krops.isLocalTarget (targets.remote "/")); ''; }; }) + (s "nonflake-input" { + phases = twice { + sources = { + x.file = { path = "/fixtures/usedata"; inputs.data.follows = "data"; }; + data.file = "/fixtures/data"; + }; + check = '' + expect_eq msg "$(nix_eval "$T"/.populate/flakes/x#msg)" data:hello + ''; + }; + }) ] ++ lib.optional (targetKind == "local") # The target has the path the input is locked to. (s "uselocal" { -- cgit v1.3.1