forked from lix-project/lix
Merge remote-tracking branch 'tweag/flakeFlags' into flakes
This commit is contained in:
commit
4588a6ff3c
6 changed files with 31 additions and 12 deletions
|
@ -33,6 +33,15 @@ MixEvalArgs::MixEvalArgs()
|
||||||
.handler([&](std::vector<std::string> ss) {
|
.handler([&](std::vector<std::string> ss) {
|
||||||
evalSettings.pureEval = false;
|
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)
|
Bindings * MixEvalArgs::getAutoArgs(EvalState & state)
|
||||||
|
|
|
@ -16,6 +16,8 @@ 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;
|
||||||
|
|
|
@ -63,6 +63,8 @@ typedef std::list<SearchPathElem> SearchPath;
|
||||||
/* Initialise the Boehm GC, if applicable. */
|
/* Initialise the Boehm GC, if applicable. */
|
||||||
void initGC();
|
void initGC();
|
||||||
|
|
||||||
|
typedef std::vector<std::pair<std::string, std::string>> RegistryOverrides;
|
||||||
|
|
||||||
|
|
||||||
class EvalState
|
class EvalState
|
||||||
{
|
{
|
||||||
|
@ -89,6 +91,9 @@ public:
|
||||||
|
|
||||||
const ref<Store> store;
|
const ref<Store> store;
|
||||||
|
|
||||||
|
RegistryOverrides registryOverrides;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SrcToStore srcToStore;
|
SrcToStore srcToStore;
|
||||||
|
|
||||||
|
@ -211,6 +216,8 @@ public:
|
||||||
path. Nothing is copied to the store. */
|
path. Nothing is copied to the store. */
|
||||||
Path coerceToPath(const Pos & pos, Value & v, PathSet & context);
|
Path coerceToPath(const Pos & pos, Value & v, PathSet & context);
|
||||||
|
|
||||||
|
void addRegistryOverrides(RegistryOverrides overrides) { registryOverrides = overrides; }
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/* The base environment, containing the builtin functions and
|
/* The base environment, containing the builtin functions and
|
||||||
|
|
|
@ -140,10 +140,13 @@ std::shared_ptr<FlakeRegistry> getUserRegistry()
|
||||||
return readRegistry(getUserRegistryPath());
|
return readRegistry(getUserRegistryPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<FlakeRegistry> getFlagRegistry()
|
std::shared_ptr<FlakeRegistry> getFlagRegistry(RegistryOverrides registryOverrides)
|
||||||
{
|
{
|
||||||
// TODO (Nick): Implement this.
|
auto flagRegistry = std::make_shared<FlakeRegistry>();
|
||||||
return 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 flakeReg, userReg, globalReg.
|
// This always returns a vector with flakeReg, userReg, globalReg.
|
||||||
|
@ -151,7 +154,7 @@ std::shared_ptr<FlakeRegistry> getFlagRegistry()
|
||||||
const Registries EvalState::getFlakeRegistries()
|
const Registries EvalState::getFlakeRegistries()
|
||||||
{
|
{
|
||||||
Registries registries;
|
Registries registries;
|
||||||
registries.push_back(getFlagRegistry());
|
registries.push_back(getFlagRegistry(registryOverrides));
|
||||||
registries.push_back(getUserRegistry());
|
registries.push_back(getUserRegistry());
|
||||||
registries.push_back(getGlobalRegistry());
|
registries.push_back(getGlobalRegistry());
|
||||||
return registries;
|
return registries;
|
||||||
|
@ -357,9 +360,8 @@ NonFlake getNonFlake(EvalState & state, const FlakeRef & flakeRef, FlakeAlias al
|
||||||
ResolvedFlake resolveFlake(EvalState & state, const FlakeRef & topRef,
|
ResolvedFlake resolveFlake(EvalState & state, const FlakeRef & topRef,
|
||||||
RegistryAccess registryAccess, bool isTopFlake)
|
RegistryAccess registryAccess, bool isTopFlake)
|
||||||
{
|
{
|
||||||
Flake flake = getFlake(state, topRef,
|
bool allowRegistries = registryAccess == AllowRegistry || (registryAccess == AllowRegistryAtTop && isTopFlake);
|
||||||
registryAccess == AllowRegistry || (registryAccess == AllowRegistryAtTop && isTopFlake));
|
Flake flake = getFlake(state, topRef, allowRegistries);
|
||||||
|
|
||||||
LockFile lockFile;
|
LockFile lockFile;
|
||||||
|
|
||||||
if (isTopFlake)
|
if (isTopFlake)
|
||||||
|
@ -405,10 +407,8 @@ static LockFile makeLockFile(EvalState & evalState, FlakeRef & flakeRef)
|
||||||
|
|
||||||
void updateLockFile(EvalState & state, const Path & path)
|
void updateLockFile(EvalState & state, const Path & path)
|
||||||
{
|
{
|
||||||
// FIXME: don't copy 'path' to the store (especially since we
|
// FIXME: We are writing the lockfile to the store here! Very bad practice!
|
||||||
// dirty it immediately afterwards).
|
FlakeRef flakeRef = FlakeRef(path);
|
||||||
|
|
||||||
FlakeRef flakeRef = FlakeRef(path); // FIXME: ugly
|
|
||||||
auto lockFile = makeLockFile(state, flakeRef);
|
auto lockFile = makeLockFile(state, flakeRef);
|
||||||
writeLockFile(lockFile, path + "/flake.lock");
|
writeLockFile(lockFile, path + "/flake.lock");
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ struct CmdBuild : MixDryRun, InstallablesCommand
|
||||||
auto buildables = build(store, dryRun ? DryRun : Build, installables);
|
auto buildables = build(store, dryRun ? DryRun : Build, installables);
|
||||||
|
|
||||||
auto evalState = std::make_shared<EvalState>(searchPath, store);
|
auto evalState = std::make_shared<EvalState>(searchPath, store);
|
||||||
|
evalState->addRegistryOverrides(registryOverrides);
|
||||||
if (dryRun) return;
|
if (dryRun) return;
|
||||||
|
|
||||||
for (size_t i = 0; i < buildables.size(); ++i) {
|
for (size_t i = 0; i < buildables.size(); ++i) {
|
||||||
|
|
|
@ -92,6 +92,7 @@ struct CmdFlakeDeps : FlakeCommand, MixJSON, StoreCommand, MixEvalArgs
|
||||||
void run(nix::ref<nix::Store> store) override
|
void run(nix::ref<nix::Store> store) override
|
||||||
{
|
{
|
||||||
auto evalState = std::make_shared<EvalState>(searchPath, store);
|
auto evalState = std::make_shared<EvalState>(searchPath, store);
|
||||||
|
evalState->addRegistryOverrides(registryOverrides);
|
||||||
|
|
||||||
FlakeRef flakeRef(flakeUri);
|
FlakeRef flakeRef(flakeUri);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue