@@ -90,11 +90,11 @@ static void expectType(EvalState & state, ValueType type,
9090
9191static 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
9595static 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
176172static 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. */
336318LockedFlake 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
0 commit comments