From 435df0ee5c67a3d3ad3aae1b18716748ae6cb4dc Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 28 Feb 2025 14:39:14 +0100 Subject: [PATCH] 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`. --- src/libfetchers/registry.cc | 8 +++++--- src/libfetchers/registry.hh | 3 ++- src/nix/registry.cc | 4 ++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/libfetchers/registry.cc b/src/libfetchers/registry.cc index c18e12d2339..d2543c96a18 100644 --- a/src/libfetchers/registry.cc +++ b/src/libfetchers/registry.cc @@ -82,13 +82,15 @@ void Registry::write(const Path & path) void Registry::add( const Input & from, const Input & to, - const Attrs & extraAttrs) + const Attrs & extraAttrs, + bool exact) { entries.emplace_back( Entry { .from = from, .to = to, - .extraAttrs = extraAttrs + .extraAttrs = extraAttrs, + .exact = exact }); } @@ -142,7 +144,7 @@ void overrideRegistry( const Input & to, const Attrs & extraAttrs) { - getFlagRegistry(*from.settings)->add(from, to, extraAttrs); + getFlagRegistry(*from.settings)->add(from, to, extraAttrs, false); } static std::shared_ptr getGlobalRegistry(const Settings & settings, ref store) diff --git a/src/libfetchers/registry.hh b/src/libfetchers/registry.hh index 8f47e15905e..fc29b8e6df0 100644 --- a/src/libfetchers/registry.hh +++ b/src/libfetchers/registry.hh @@ -45,7 +45,8 @@ struct Registry void add( const Input & from, const Input & to, - const Attrs & extraAttrs); + const Attrs & extraAttrs, + bool exact); void remove(const Input & input); }; diff --git a/src/nix/registry.cc b/src/nix/registry.cc index ee45162302c..b5c8e0ad3f0 100644 --- a/src/nix/registry.cc +++ b/src/nix/registry.cc @@ -115,7 +115,7 @@ struct CmdRegistryAdd : MixEvalArgs, Command, RegistryCommand fetchers::Attrs extraAttrs; if (toRef.subdir != "") extraAttrs["dir"] = toRef.subdir; registry->remove(fromRef.input); - registry->add(fromRef.input, toRef.input, extraAttrs); + registry->add(fromRef.input, toRef.input, extraAttrs, false); registry->write(getRegistryPath()); } }; @@ -193,7 +193,7 @@ struct CmdRegistryPin : RegistryCommand, EvalCommand warn("flake '%s' is not locked", resolved.to_string()); fetchers::Attrs extraAttrs; if (ref.subdir != "") extraAttrs["dir"] = ref.subdir; - registry->add(ref.input, resolved, extraAttrs); + registry->add(ref.input, resolved, extraAttrs, true); registry->write(getRegistryPath()); } };