Fix --override-flake and add a test

This commit is contained in:
Eelco Dolstra 2020-01-22 20:00:58 +01:00
parent 90d55ed275
commit b5c9dbc84f
5 changed files with 34 additions and 15 deletions

View file

@ -3,6 +3,8 @@
#include "download.hh" #include "download.hh"
#include "util.hh" #include "util.hh"
#include "eval.hh" #include "eval.hh"
#include "fetchers/registry.hh"
#include "flake/flakeref.hh"
namespace nix { namespace nix {
@ -40,7 +42,9 @@ MixEvalArgs::MixEvalArgs()
.description("override a flake registry value") .description("override a flake registry value")
.arity(2) .arity(2)
.handler([&](std::vector<std::string> ss) { .handler([&](std::vector<std::string> ss) {
registryOverrides.push_back(std::make_pair(ss[0], ss[1])); fetchers::overrideRegistry(
parseFlakeRef(ss[0], absPath(".")).input,
parseFlakeRef(ss[1], absPath(".")).input);
}); });
} }

View file

@ -16,8 +16,6 @@ struct MixEvalArgs : virtual Args
Strings searchPath; Strings searchPath;
std::vector<std::pair<std::string, std::string>> registryOverrides;
private: private:
std::map<std::string, std::string> autoArgs; std::map<std::string, std::string> autoArgs;

View file

@ -11,11 +11,10 @@ namespace nix::fetchers {
std::shared_ptr<Registry> Registry::read( std::shared_ptr<Registry> Registry::read(
const Path & path, RegistryType type) const Path & path, RegistryType type)
{ {
auto registry = std::make_shared<Registry>(); auto registry = std::make_shared<Registry>(type);
registry->type = type;
if (!pathExists(path)) if (!pathExists(path))
return std::make_shared<Registry>(); return std::make_shared<Registry>(type);
auto json = nlohmann::json::parse(readFile(path)); auto json = nlohmann::json::parse(readFile(path));
@ -74,17 +73,20 @@ std::shared_ptr<Registry> getUserRegistry()
return Registry::read(getUserRegistryPath(), Registry::User); return Registry::read(getUserRegistryPath(), Registry::User);
} }
#if 0 static std::shared_ptr<Registry> flagRegistry =
std::shared_ptr<Registry> getFlagRegistry(RegistryOverrides registryOverrides) std::make_shared<Registry>(Registry::Flag);
std::shared_ptr<Registry> getFlagRegistry()
{ {
auto flagRegistry = std::make_shared<Registry>();
for (auto const & x : registryOverrides)
flagRegistry->entries.insert_or_assign(
parseFlakeRef2(x.first),
parseFlakeRef2(x.second));
return flagRegistry; return flagRegistry;
} }
#endif
void overrideRegistry(
const std::shared_ptr<const Input> & from,
const std::shared_ptr<const Input> & to)
{
flagRegistry->add(from, to);
}
static std::shared_ptr<Registry> getGlobalRegistry(ref<Store> store) static std::shared_ptr<Registry> getGlobalRegistry(ref<Store> store)
{ {
@ -107,7 +109,7 @@ static std::shared_ptr<Registry> getGlobalRegistry(ref<Store> store)
Registries getRegistries(ref<Store> store) Registries getRegistries(ref<Store> store)
{ {
Registries registries; Registries registries;
//registries.push_back(getFlagRegistry(registryOverrides)); registries.push_back(getFlagRegistry());
registries.push_back(getUserRegistry()); registries.push_back(getUserRegistry());
registries.push_back(getGlobalRegistry(store)); registries.push_back(getGlobalRegistry(store));
return registries; return registries;

View file

@ -20,6 +20,10 @@ struct Registry
std::vector<std::pair<std::shared_ptr<const Input>, std::shared_ptr<const Input>>> entries; std::vector<std::pair<std::shared_ptr<const Input>, std::shared_ptr<const Input>>> entries;
Registry(RegistryType type)
: type(type)
{ }
static std::shared_ptr<Registry> read( static std::shared_ptr<Registry> read(
const Path & path, RegistryType type); const Path & path, RegistryType type);
@ -40,6 +44,10 @@ Path getUserRegistryPath();
Registries getRegistries(ref<Store> store); Registries getRegistries(ref<Store> store);
void overrideRegistry(
const std::shared_ptr<const Input> & from,
const std::shared_ptr<const Input> & to);
std::shared_ptr<const Input> lookupInRegistries( std::shared_ptr<const Input> lookupInRegistries(
ref<Store> store, ref<Store> store,
std::shared_ptr<const Input> input); std::shared_ptr<const Input> input);

View file

@ -293,6 +293,13 @@ nix build -o $TEST_ROOT/result --flake-registry $registry flake3#xyzzy flake3#fn
# Test doing multiple `lookupFlake`s # Test doing multiple `lookupFlake`s
nix build -o $TEST_ROOT/result --flake-registry $registry flake4#xyzzy 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 # Make branch "removeXyzzy" where flake3 doesn't have xyzzy anymore
git -C $flake3Dir checkout -b removeXyzzy git -C $flake3Dir checkout -b removeXyzzy
rm $flake3Dir/flake.nix rm $flake3Dir/flake.nix