From b5c9dbc84f31a1e9d1e5b6642b1716daa13c18ed Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 22 Jan 2020 20:00:58 +0100 Subject: [PATCH] Fix --override-flake and add a test --- src/libexpr/common-eval-args.cc | 6 +++++- src/libexpr/common-eval-args.hh | 2 -- src/libstore/fetchers/registry.cc | 26 ++++++++++++++------------ src/libstore/fetchers/registry.hh | 8 ++++++++ tests/flakes.sh | 7 +++++++ 5 files changed, 34 insertions(+), 15 deletions(-) diff --git a/src/libexpr/common-eval-args.cc b/src/libexpr/common-eval-args.cc index 7c0d268bd..e3135b472 100644 --- a/src/libexpr/common-eval-args.cc +++ b/src/libexpr/common-eval-args.cc @@ -3,6 +3,8 @@ #include "download.hh" #include "util.hh" #include "eval.hh" +#include "fetchers/registry.hh" +#include "flake/flakeref.hh" namespace nix { @@ -40,7 +42,9 @@ MixEvalArgs::MixEvalArgs() .description("override a flake registry value") .arity(2) .handler([&](std::vector ss) { - registryOverrides.push_back(std::make_pair(ss[0], ss[1])); + fetchers::overrideRegistry( + parseFlakeRef(ss[0], absPath(".")).input, + parseFlakeRef(ss[1], absPath(".")).input); }); } diff --git a/src/libexpr/common-eval-args.hh b/src/libexpr/common-eval-args.hh index 54fb731de..be7fda783 100644 --- a/src/libexpr/common-eval-args.hh +++ b/src/libexpr/common-eval-args.hh @@ -16,8 +16,6 @@ struct MixEvalArgs : virtual Args Strings searchPath; - std::vector> registryOverrides; - private: std::map autoArgs; diff --git a/src/libstore/fetchers/registry.cc b/src/libstore/fetchers/registry.cc index dd74e16c1..9c74f118d 100644 --- a/src/libstore/fetchers/registry.cc +++ b/src/libstore/fetchers/registry.cc @@ -11,11 +11,10 @@ namespace nix::fetchers { std::shared_ptr Registry::read( const Path & path, RegistryType type) { - auto registry = std::make_shared(); - registry->type = type; + auto registry = std::make_shared(type); if (!pathExists(path)) - return std::make_shared(); + return std::make_shared(type); auto json = nlohmann::json::parse(readFile(path)); @@ -74,17 +73,20 @@ std::shared_ptr getUserRegistry() return Registry::read(getUserRegistryPath(), Registry::User); } -#if 0 -std::shared_ptr getFlagRegistry(RegistryOverrides registryOverrides) +static std::shared_ptr flagRegistry = + std::make_shared(Registry::Flag); + +std::shared_ptr getFlagRegistry() { - auto flagRegistry = std::make_shared(); - for (auto const & x : registryOverrides) - flagRegistry->entries.insert_or_assign( - parseFlakeRef2(x.first), - parseFlakeRef2(x.second)); return flagRegistry; } -#endif + +void overrideRegistry( + const std::shared_ptr & from, + const std::shared_ptr & to) +{ + flagRegistry->add(from, to); +} static std::shared_ptr getGlobalRegistry(ref store) { @@ -107,7 +109,7 @@ static std::shared_ptr getGlobalRegistry(ref store) Registries getRegistries(ref store) { Registries registries; - //registries.push_back(getFlagRegistry(registryOverrides)); + registries.push_back(getFlagRegistry()); registries.push_back(getUserRegistry()); registries.push_back(getGlobalRegistry(store)); return registries; diff --git a/src/libstore/fetchers/registry.hh b/src/libstore/fetchers/registry.hh index 1757ce323..e29f78486 100644 --- a/src/libstore/fetchers/registry.hh +++ b/src/libstore/fetchers/registry.hh @@ -20,6 +20,10 @@ struct Registry std::vector, std::shared_ptr>> entries; + Registry(RegistryType type) + : type(type) + { } + static std::shared_ptr read( const Path & path, RegistryType type); @@ -40,6 +44,10 @@ Path getUserRegistryPath(); Registries getRegistries(ref store); +void overrideRegistry( + const std::shared_ptr & from, + const std::shared_ptr & to); + std::shared_ptr lookupInRegistries( ref store, std::shared_ptr input); diff --git a/tests/flakes.sh b/tests/flakes.sh index 334f750fb..337645fb4 100644 --- a/tests/flakes.sh +++ b/tests/flakes.sh @@ -293,6 +293,13 @@ nix build -o $TEST_ROOT/result --flake-registry $registry flake3#xyzzy flake3#fn # Test doing multiple `lookupFlake`s nix build -o $TEST_ROOT/result --flake-registry $registry flake4#xyzzy +# Test 'nix flake update' and --override-flake. +nix flake update --flake-registry $registry $flake3Dir +[[ -z $(git -C $flake3Dir diff master) ]] + +nix flake update --flake-registry $registry $flake3Dir --recreate-lock-file --override-flake flake2 nixpkgs +[[ ! -z $(git -C $flake3Dir diff master) ]] + # Make branch "removeXyzzy" where flake3 doesn't have xyzzy anymore git -C $flake3Dir checkout -b removeXyzzy rm $flake3Dir/flake.nix