diff options
| author | tv <tv@krebsco.de> | 2026-11-12 02:33:43 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-12 02:33:43 +0000 |
| commit | 408fcc6584ca598533a0f8c9012d60450db148a8 (patch) | |
| tree | c5681ad8830b8ee9939f2e6eb35bec210f7e8f59 | |
| parent | 55f41b5f04efee81b4ab48899214bc59448af325 (diff) | |
populate: place overrides on sources with generated flakes correctly
An override below an input drawn from a source that has a generated
flake itself got placed on that generated flake, which has no such
input, so Nix ignored it with a warning. Generated flakes have their
source as input of the same name, so the override goes below that.
An edge case overrides an input of a source with a generated flake.
| -rw-r--r-- | pkgs/populate/default.nix | 3 | ||||
| -rwxr-xr-x | tests/fixtures.sh | 17 | ||||
| -rw-r--r-- | tests/scenarios.nix | 16 |
3 files changed, 36 insertions, 0 deletions
diff --git a/pkgs/populate/default.nix b/pkgs/populate/default.nix index 7a52ca9..06197b6 100644 --- a/pkgs/populate/default.nix +++ b/pkgs/populate/default.nix @@ -89,6 +89,9 @@ let rest = if parent == null then x.path else drop (length parent) x.path; in "inputs.${toJSON base}" + + # A source with a generated flake has itself as input therein. + optionalString (parent != null && generated ? ${base}) + ".inputs.${toJSON base}" + concatMapStrings (name: ".inputs.${toJSON name}") rest + ".follows = ${toJSON x.source};"; in /* sh */ '' diff --git a/tests/fixtures.sh b/tests/fixtures.sh index 9813c8f..8222b13 100755 --- a/tests/fixtures.sh +++ b/tests/fixtures.sh @@ -216,6 +216,23 @@ cat > /fixtures/rel/flake.nix <<'NIX' NIX (cd /fixtures/rel && nix flake lock && git init -q && commit rel) +# two, c1, c2: a flake with two inputs, and two flakes to draw them from. +mkdir /fixtures/two /fixtures/c1 /fixtures/c2 +cat > /fixtures/two/flake.nix <<NIX +{ + inputs.p.url = "$url/inner.tar.gz"; + inputs.q.url = "$url/inner.tar.gz"; + outputs = { p, q, ... }: { greeting = "two:\${p.who}+\${q.who}"; }; +} +NIX +(cd /fixtures/two && nix flake lock) +cat > /fixtures/c1/flake.nix <<'NIX' +{ outputs = _: { who = "c1"; }; } +NIX +cat > /fixtures/c2/flake.nix <<'NIX' +{ outputs = _: { who = "c2"; }; } +NIX + # 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 307e521..5dd44db 100644 --- a/tests/scenarios.nix +++ b/tests/scenarios.nix @@ -867,6 +867,22 @@ assert !(krops.isLocalTarget (targets.remote "/")); } ]; })) + (s "override-generated" { + phases = twice { + sources = { + x.flake = { + flake = "/fixtures/top"; inherit fetchOnTarget; + inputs.dep = { follows = "b"; inputs.q.follows = "c2"; }; + }; + b.file = { path = "/fixtures/two"; inputs.p.follows = "c1"; }; + c1.file = "/fixtures/c1"; + c2.file = "/fixtures/c2"; + }; + check = '' + expect_eq msg "$(nix_eval_online "$T"/.populate/flakes/x#msg)" top:two:c1+c2,sub + ''; + }; + }) ] ++ lib.optional (targetKind == "local") # The target has the path the input is locked to. (s "uselocal" { |
