Skip to content

Commit 89f3425

Browse files
edolstraMinion3665
authored andcommitted
Revert "Merge pull request NixOS#6621 from Kha/nested-follows"
This reverts commit c530cda, reversing changes made to 4adcdff.
1 parent c861a9a commit 89f3425

File tree

3 files changed

+14
-95
lines changed

3 files changed

+14
-95
lines changed

src/libexpr/flake/flake.cc

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ static void expectType(EvalState & state, ValueType type,
9090

9191
static std::map<FlakeId, FlakeInput> parseFlakeInputs(
9292
EvalState & state, Value * value, const PosIdx pos,
93-
const std::optional<Path> & baseDir, InputPath lockRootPath, unsigned depth);
93+
const std::optional<Path> & baseDir, InputPath lockRootPath);
9494

9595
static FlakeInput parseFlakeInput(EvalState & state,
9696
const std::string & inputName, Value * value, const PosIdx pos,
97-
const std::optional<Path> & baseDir, InputPath lockRootPath, unsigned depth)
97+
const std::optional<Path> & baseDir, InputPath lockRootPath)
9898
{
9999
expectType(state, nAttrs, *value, pos);
100100

@@ -118,7 +118,7 @@ static FlakeInput parseFlakeInput(EvalState & state,
118118
expectType(state, nBool, *attr.value, attr.pos);
119119
input.isFlake = attr.value->boolean;
120120
} else if (attr.name == sInputs) {
121-
input.overrides = parseFlakeInputs(state, attr.value, attr.pos, baseDir, lockRootPath, depth + 1);
121+
input.overrides = parseFlakeInputs(state, attr.value, attr.pos, baseDir, lockRootPath);
122122
} else if (attr.name == sFollows) {
123123
expectType(state, nString, *attr.value, attr.pos);
124124
auto follows(parseInputPath(attr.value->string.s));
@@ -163,19 +163,15 @@ static FlakeInput parseFlakeInput(EvalState & state,
163163
input.ref = parseFlakeRef(*url, baseDir, true, input.isFlake);
164164
}
165165

166-
if (!input.follows && !input.ref && depth == 0)
167-
// in `input.nixops.inputs.nixpkgs.url = ...`, we assume `nixops` is from
168-
// the flake registry absent `ref`/`follows`, but we should not assume so
169-
// about `nixpkgs` (where `depth == 1`) as the `nixops` flake should
170-
// determine its default source
166+
if (!input.follows && !input.ref)
171167
input.ref = FlakeRef::fromAttrs({{"type", "indirect"}, {"id", inputName}});
172168

173169
return input;
174170
}
175171

176172
static std::map<FlakeId, FlakeInput> parseFlakeInputs(
177173
EvalState & state, Value * value, const PosIdx pos,
178-
const std::optional<Path> & baseDir, InputPath lockRootPath, unsigned depth)
174+
const std::optional<Path> & baseDir, InputPath lockRootPath)
179175
{
180176
std::map<FlakeId, FlakeInput> inputs;
181177

@@ -188,8 +184,7 @@ static std::map<FlakeId, FlakeInput> parseFlakeInputs(
188184
inputAttr.value,
189185
inputAttr.pos,
190186
baseDir,
191-
lockRootPath,
192-
depth));
187+
lockRootPath));
193188
}
194189

195190
return inputs;
@@ -235,7 +230,7 @@ static Flake getFlake(
235230
auto sInputs = state.symbols.create("inputs");
236231

237232
if (auto inputs = vInfo.attrs->get(sInputs))
238-
flake.inputs = parseFlakeInputs(state, inputs->value, inputs->pos, flakeDir, lockRootPath, 0);
233+
flake.inputs = parseFlakeInputs(state, inputs->value, inputs->pos, flakeDir, lockRootPath);
239234

240235
auto sOutputs = state.symbols.create("outputs");
241236

@@ -318,19 +313,6 @@ Flake getFlake(EvalState & state, const FlakeRef & originalRef, bool allowLookup
318313
return getFlake(state, originalRef, allowLookup, flakeCache);
319314
}
320315

321-
/* Recursively merge `overrides` into `overrideMap` */
322-
static void updateOverrides(std::map<InputPath, FlakeInput> & overrideMap, const FlakeInputs & overrides,
323-
const InputPath & inputPathPrefix)
324-
{
325-
for (auto & [id, input] : overrides) {
326-
auto inputPath(inputPathPrefix);
327-
inputPath.push_back(id);
328-
// Do not override existing assignment from outer flake
329-
overrideMap.insert({inputPath, input});
330-
updateOverrides(overrideMap, input.overrides, inputPath);
331-
}
332-
}
333-
334316
/* Compute an in-memory lock file for the specified top-level flake,
335317
and optionally write it to file, if the flake is writable. */
336318
LockedFlake lockFlake(
@@ -393,9 +375,12 @@ LockedFlake lockFlake(
393375
/* Get the overrides (i.e. attributes of the form
394376
'inputs.nixops.inputs.nixpkgs.url = ...'). */
395377
for (auto & [id, input] : flakeInputs) {
396-
auto inputPath(inputPathPrefix);
397-
inputPath.push_back(id);
398-
updateOverrides(overrides, input.overrides, inputPath);
378+
for (auto & [idOverride, inputOverride] : input.overrides) {
379+
auto inputPath(inputPathPrefix);
380+
inputPath.push_back(id);
381+
inputPath.push_back(idOverride);
382+
overrides.insert_or_assign(inputPath, inputOverride);
383+
}
399384
}
400385

401386
/* Check whether this input has overrides for a
@@ -430,12 +415,6 @@ LockedFlake lockFlake(
430415
// Respect the “flakeness” of the input even if we
431416
// override it
432417
i->second.isFlake = input2.isFlake;
433-
if (!i->second.ref)
434-
i->second.ref = input2.ref;
435-
if (!i->second.follows)
436-
i->second.follows = input2.follows;
437-
// Note that `input.overrides` is not used in the following,
438-
// so no need to merge it here (already done by `updateOverrides`)
439418
}
440419
auto & input = hasOverride ? i->second : input2;
441420

src/libexpr/flake/lockfile.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ void LockFile::check()
338338

339339
for (auto & [inputPath, input] : inputs) {
340340
if (auto follows = std::get_if<1>(&input)) {
341-
if (!follows->empty() && !findInput(*follows))
341+
if (!follows->empty() && !get(inputs, *follows))
342342
throw Error("input '%s' follows a non-existent input '%s'",
343343
printInputPath(inputPath),
344344
printInputPath(*follows));

tests/flakes/follow-paths.sh

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -148,63 +148,3 @@ git -C $flakeFollowsA add flake.nix
148148

149149
nix flake lock $flakeFollowsA 2>&1 | grep "warning: input 'B' has an override for a non-existent input 'invalid'"
150150
nix flake lock $flakeFollowsA 2>&1 | grep "warning: input 'B' has an override for a non-existent input 'invalid2'"
151-
152-
# Test nested flake overrides: A overrides B/C/D
153-
154-
cat <<EOF > $flakeFollowsD/flake.nix
155-
{ outputs = _: {}; }
156-
EOF
157-
cat <<EOF > $flakeFollowsC/flake.nix
158-
{
159-
inputs.D.url = "path:nosuchflake";
160-
outputs = _: {};
161-
}
162-
EOF
163-
cat <<EOF > $flakeFollowsB/flake.nix
164-
{
165-
inputs.C.url = "path:$flakeFollowsC";
166-
outputs = _: {};
167-
}
168-
EOF
169-
cat <<EOF > $flakeFollowsA/flake.nix
170-
{
171-
inputs.B.url = "path:$flakeFollowsB";
172-
inputs.D.url = "path:$flakeFollowsD";
173-
inputs.B.inputs.C.inputs.D.follows = "D";
174-
outputs = _: {};
175-
}
176-
EOF
177-
178-
nix flake lock $flakeFollowsA
179-
180-
[[ $(jq -c .nodes.C.inputs.D $flakeFollowsA/flake.lock) = '["D"]' ]]
181-
182-
# Test overlapping flake follows: B has D follow C/D, while A has B/C follow C
183-
184-
cat <<EOF > $flakeFollowsC/flake.nix
185-
{
186-
inputs.D.url = "path:$flakeFollowsD";
187-
outputs = _: {};
188-
}
189-
EOF
190-
cat <<EOF > $flakeFollowsB/flake.nix
191-
{
192-
inputs.C.url = "path:nosuchflake";
193-
inputs.D.url = "path:nosuchflake";
194-
inputs.D.follows = "C/D";
195-
outputs = _: {};
196-
}
197-
EOF
198-
cat <<EOF > $flakeFollowsA/flake.nix
199-
{
200-
inputs.B.url = "path:$flakeFollowsB";
201-
inputs.C.url = "path:$flakeFollowsC";
202-
inputs.B.inputs.C.follows = "C";
203-
outputs = _: {};
204-
}
205-
EOF
206-
207-
# bug was not triggered without recreating the lockfile
208-
nix flake lock $flakeFollowsA --recreate-lock-file
209-
210-
[[ $(jq -c .nodes.B.inputs.D $flakeFollowsA/flake.lock) = '["B","C","D"]' ]]

0 commit comments

Comments
 (0)