1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-25 10:41:16 +02:00

nix flake pin: Mark the resulting registry entry as exact

Since the resulting target flakeref contains attributes like
"lastModified" or "narHash", it's not suitable for overriding. This
led to errors like

  $ nix build nixpkgs/24.05#hello
  error: 'lastModified' attribute mismatch in input 'github:NixOS/nixpkgs/63dacb46bf939521bdc93981b4cbb7ecb58427a0', expected 1728538411, got 1717179513

after doing `nix registry pin nixpkgs`.
This commit is contained in:
Eelco Dolstra 2025-02-28 14:39:14 +01:00 committed by Jörg Thalheim
parent 3aed9c8dd4
commit e3300d4cde
3 changed files with 9 additions and 6 deletions

View file

@ -45,7 +45,8 @@ struct Registry
void add( void add(
const Input & from, const Input & from,
const Input & to, const Input & to,
const Attrs & extraAttrs); const Attrs & extraAttrs,
bool exact);
void remove(const Input & input); void remove(const Input & input);
}; };

View file

@ -84,13 +84,15 @@ void Registry::write(const Path & path)
void Registry::add( void Registry::add(
const Input & from, const Input & from,
const Input & to, const Input & to,
const Attrs & extraAttrs) const Attrs & extraAttrs,
bool exact)
{ {
entries.emplace_back( entries.emplace_back(
Entry { Entry {
.from = from, .from = from,
.to = to, .to = to,
.extraAttrs = extraAttrs .extraAttrs = extraAttrs,
.exact = exact
}); });
} }
@ -144,7 +146,7 @@ void overrideRegistry(
const Input & to, const Input & to,
const Attrs & extraAttrs) const Attrs & extraAttrs)
{ {
getFlagRegistry(*from.settings)->add(from, to, extraAttrs); getFlagRegistry(*from.settings)->add(from, to, extraAttrs, false);
} }
static std::shared_ptr<Registry> getGlobalRegistry(const Settings & settings, ref<Store> store) static std::shared_ptr<Registry> getGlobalRegistry(const Settings & settings, ref<Store> store)

View file

@ -115,7 +115,7 @@ struct CmdRegistryAdd : MixEvalArgs, Command, RegistryCommand
fetchers::Attrs extraAttrs; fetchers::Attrs extraAttrs;
if (toRef.subdir != "") extraAttrs["dir"] = toRef.subdir; if (toRef.subdir != "") extraAttrs["dir"] = toRef.subdir;
registry->remove(fromRef.input); registry->remove(fromRef.input);
registry->add(fromRef.input, toRef.input, extraAttrs); registry->add(fromRef.input, toRef.input, extraAttrs, false);
registry->write(getRegistryPath()); registry->write(getRegistryPath());
} }
}; };
@ -193,7 +193,7 @@ struct CmdRegistryPin : RegistryCommand, EvalCommand
warn("flake '%s' is not locked", resolved.to_string()); warn("flake '%s' is not locked", resolved.to_string());
fetchers::Attrs extraAttrs; fetchers::Attrs extraAttrs;
if (ref.subdir != "") extraAttrs["dir"] = ref.subdir; if (ref.subdir != "") extraAttrs["dir"] = ref.subdir;
registry->add(ref.input, resolved, extraAttrs); registry->add(ref.input, resolved, extraAttrs, true);
registry->write(getRegistryPath()); registry->write(getRegistryPath());
} }
}; };