diff options
-rw-r--r-- | src/libexpr/common-eval-args.cc | 9 | ||||
-rw-r--r-- | src/libexpr/common-eval-args.hh | 2 | ||||
-rw-r--r-- | src/libexpr/eval.hh | 7 | ||||
-rw-r--r-- | src/libexpr/primops/flake.cc | 22 | ||||
-rw-r--r-- | src/nix/build.cc | 2 | ||||
-rw-r--r-- | src/nix/flake.cc | 1 |
6 files changed, 31 insertions, 12 deletions
diff --git a/src/libexpr/common-eval-args.cc b/src/libexpr/common-eval-args.cc index 3e5400052..8e94d358e 100644 --- a/src/libexpr/common-eval-args.cc +++ b/src/libexpr/common-eval-args.cc @@ -33,6 +33,15 @@ MixEvalArgs::MixEvalArgs() .handler([&](std::vector<std::string> ss) { evalSettings.pureEval = false; }); + + mkFlag() + .longName("override-flake") + .labels({"original-ref", "resolved-ref"}) + .description("override a flake registry value") + .arity(2) + .handler([&](std::vector<std::string> ss) { + registryOverrides.push_back(std::make_pair(ss[0], ss[1])); + }); } Bindings * MixEvalArgs::getAutoArgs(EvalState & state) diff --git a/src/libexpr/common-eval-args.hh b/src/libexpr/common-eval-args.hh index be7fda783..54fb731de 100644 --- a/src/libexpr/common-eval-args.hh +++ b/src/libexpr/common-eval-args.hh @@ -16,6 +16,8 @@ struct MixEvalArgs : virtual Args Strings searchPath; + std::vector<std::pair<std::string, std::string>> registryOverrides; + private: std::map<std::string, std::string> autoArgs; diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh index 3f537da89..44988cd70 100644 --- a/src/libexpr/eval.hh +++ b/src/libexpr/eval.hh @@ -63,6 +63,8 @@ typedef std::list<SearchPathElem> SearchPath; /* Initialise the Boehm GC, if applicable. */ void initGC(); +typedef std::vector<std::pair<std::string, std::string>> RegistryOverrides; + class EvalState { @@ -89,6 +91,9 @@ public: const ref<Store> store; + RegistryOverrides registryOverrides; + + private: SrcToStore srcToStore; @@ -211,6 +216,8 @@ public: path. Nothing is copied to the store. */ Path coerceToPath(const Pos & pos, Value & v, PathSet & context); + void addRegistryOverrides(RegistryOverrides overrides) { registryOverrides = overrides; } + public: /* The base environment, containing the builtin functions and diff --git a/src/libexpr/primops/flake.cc b/src/libexpr/primops/flake.cc index f6744a1f7..5af0c49c7 100644 --- a/src/libexpr/primops/flake.cc +++ b/src/libexpr/primops/flake.cc @@ -140,10 +140,13 @@ std::shared_ptr<FlakeRegistry> getUserRegistry() return readRegistry(getUserRegistryPath()); } -std::shared_ptr<FlakeRegistry> getFlagRegistry() +std::shared_ptr<FlakeRegistry> getFlagRegistry(RegistryOverrides registryOverrides) { - // TODO (Nick): Implement this. - return std::make_shared<FlakeRegistry>(); + auto flagRegistry = std::make_shared<FlakeRegistry>(); + for (auto const & x : registryOverrides) { + flagRegistry->entries.insert_or_assign(FlakeRef(x.first), FlakeRef(x.second)); + } + return flagRegistry; } // This always returns a vector with flakeRef, userReg, globalReg. @@ -151,7 +154,7 @@ std::shared_ptr<FlakeRegistry> getFlagRegistry() const Registries EvalState::getFlakeRegistries() { Registries registries; - registries.push_back(getFlagRegistry()); + registries.push_back(getFlagRegistry(registryOverrides)); registries.push_back(getUserRegistry()); registries.push_back(getGlobalRegistry()); return registries; @@ -357,9 +360,8 @@ NonFlake getNonFlake(EvalState & state, const FlakeRef & flakeRef, FlakeAlias al ResolvedFlake resolveFlake(EvalState & state, const FlakeRef & topRef, RegistryAccess registryAccess, bool isTopFlake) { - Flake flake = getFlake(state, topRef, - registryAccess == AllowRegistry || (registryAccess == AllowRegistryAtTop && isTopFlake)); - + bool allowRegistries = registryAccess == AllowRegistry || (registryAccess == AllowRegistryAtTop && isTopFlake); + Flake flake = getFlake(state, topRef, allowRegistries); LockFile lockFile; if (isTopFlake) @@ -405,10 +407,8 @@ static LockFile makeLockFile(EvalState & evalState, FlakeRef & flakeRef) void updateLockFile(EvalState & state, const Path & path) { - // FIXME: don't copy 'path' to the store (especially since we - // dirty it immediately afterwards). - - FlakeRef flakeRef = FlakeRef(path); // FIXME: ugly + // FIXME: We are writing the lockfile to the store here! Very bad practice! + FlakeRef flakeRef = FlakeRef(path); auto lockFile = makeLockFile(state, flakeRef); writeLockFile(lockFile, path + "/flake.lock"); diff --git a/src/nix/build.cc b/src/nix/build.cc index 07b6b2f02..c08ec0e62 100644 --- a/src/nix/build.cc +++ b/src/nix/build.cc @@ -54,7 +54,7 @@ struct CmdBuild : MixDryRun, InstallablesCommand auto buildables = build(store, dryRun ? DryRun : Build, installables); auto evalState = std::make_shared<EvalState>(searchPath, store); - + evalState->addRegistryOverrides(registryOverrides); if (dryRun) return; for (size_t i = 0; i < buildables.size(); ++i) { diff --git a/src/nix/flake.cc b/src/nix/flake.cc index a25493f79..00c1c384c 100644 --- a/src/nix/flake.cc +++ b/src/nix/flake.cc @@ -92,6 +92,7 @@ struct CmdFlakeDeps : FlakeCommand, MixJSON, StoreCommand, MixEvalArgs void run(nix::ref<nix::Store> store) override { auto evalState = std::make_shared<EvalState>(searchPath, store); + evalState->addRegistryOverrides(registryOverrides); FlakeRef flakeRef(flakeUri); |