mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-30 09:36:15 +02:00
Move flake-related flags into a separate class
Also, rename --dont-save-lock-file to --no-save-lock-file and change noRegistries to useRegistries.
This commit is contained in:
parent
bc0fb109a9
commit
70136a9bf4
4 changed files with 56 additions and 34 deletions
|
@ -64,7 +64,7 @@ typedef std::vector<std::shared_ptr<FlakeRegistry>> Registries;
|
||||||
|
|
||||||
Path getUserRegistryPath();
|
Path getUserRegistryPath();
|
||||||
|
|
||||||
enum HandleLockFile
|
enum HandleLockFile : unsigned int
|
||||||
{ AllPure // Everything is handled 100% purely
|
{ AllPure // Everything is handled 100% purely
|
||||||
, TopRefUsesRegistries // The top FlakeRef uses the registries, apart from that, everything happens 100% purely
|
, TopRefUsesRegistries // The top FlakeRef uses the registries, apart from that, everything happens 100% purely
|
||||||
, UpdateLockFile // Update the existing lockfile and write it to file
|
, UpdateLockFile // Update the existing lockfile and write it to file
|
||||||
|
|
|
@ -11,8 +11,8 @@ extern std::string programPath;
|
||||||
struct Value;
|
struct Value;
|
||||||
class Bindings;
|
class Bindings;
|
||||||
class EvalState;
|
class EvalState;
|
||||||
|
|
||||||
class Store;
|
class Store;
|
||||||
|
enum HandleLockFile : unsigned int;
|
||||||
|
|
||||||
/* A command that require a Nix store. */
|
/* A command that require a Nix store. */
|
||||||
struct StoreCommand : virtual Command
|
struct StoreCommand : virtual Command
|
||||||
|
@ -61,17 +61,24 @@ private:
|
||||||
std::shared_ptr<EvalState> evalState;
|
std::shared_ptr<EvalState> evalState;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SourceExprCommand : virtual Args, EvalCommand
|
struct MixFlakeOptions : virtual Args
|
||||||
{
|
{
|
||||||
std::optional<Path> file;
|
|
||||||
|
|
||||||
SourceExprCommand();
|
|
||||||
|
|
||||||
bool recreateLockFile = false;
|
bool recreateLockFile = false;
|
||||||
|
|
||||||
bool saveLockFile = true;
|
bool saveLockFile = true;
|
||||||
|
|
||||||
bool noRegistries = false;
|
bool useRegistries = true;
|
||||||
|
|
||||||
|
MixFlakeOptions();
|
||||||
|
|
||||||
|
HandleLockFile getLockFileMode();
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SourceExprCommand : virtual Args, EvalCommand, MixFlakeOptions
|
||||||
|
{
|
||||||
|
std::optional<Path> file;
|
||||||
|
|
||||||
|
SourceExprCommand();
|
||||||
|
|
||||||
std::vector<std::shared_ptr<Installable>> parseInstallables(
|
std::vector<std::shared_ptr<Installable>> parseInstallables(
|
||||||
ref<Store> store, std::vector<std::string> ss);
|
ref<Store> store, std::vector<std::string> ss);
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
using namespace nix;
|
using namespace nix;
|
||||||
|
|
||||||
class FlakeCommand : virtual Args, public EvalCommand
|
class FlakeCommand : virtual Args, public EvalCommand, public MixFlakeOptions
|
||||||
{
|
{
|
||||||
std::string flakeUri = ".";
|
std::string flakeUri = ".";
|
||||||
|
|
||||||
|
@ -32,7 +32,12 @@ public:
|
||||||
Flake getFlake()
|
Flake getFlake()
|
||||||
{
|
{
|
||||||
auto evalState = getEvalState();
|
auto evalState = getEvalState();
|
||||||
return nix::getFlake(*evalState, getFlakeRef(), true);
|
return nix::getFlake(*evalState, getFlakeRef(), useRegistries);
|
||||||
|
}
|
||||||
|
|
||||||
|
ResolvedFlake resolveFlake()
|
||||||
|
{
|
||||||
|
return nix::resolveFlake(*getEvalState(), getFlakeRef(), getLockFileMode());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -119,6 +124,7 @@ void printNonFlakeInfo(NonFlake & nonFlake, bool json) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: merge info CmdFlakeInfo?
|
||||||
struct CmdFlakeDeps : FlakeCommand, MixJSON
|
struct CmdFlakeDeps : FlakeCommand, MixJSON
|
||||||
{
|
{
|
||||||
std::string name() override
|
std::string name() override
|
||||||
|
@ -136,7 +142,7 @@ struct CmdFlakeDeps : FlakeCommand, MixJSON
|
||||||
auto evalState = getEvalState();
|
auto evalState = getEvalState();
|
||||||
evalState->addRegistryOverrides(registryOverrides);
|
evalState->addRegistryOverrides(registryOverrides);
|
||||||
|
|
||||||
ResolvedFlake resFlake = resolveFlake(*evalState, getFlakeRef(), UpdateLockFile);
|
auto resFlake = resolveFlake();
|
||||||
|
|
||||||
std::queue<ResolvedFlake> todo;
|
std::queue<ResolvedFlake> todo;
|
||||||
todo.push(resFlake);
|
todo.push(resFlake);
|
||||||
|
@ -334,7 +340,7 @@ struct CmdFlakeInit : virtual Args, Command
|
||||||
|
|
||||||
struct CmdFlakeClone : FlakeCommand
|
struct CmdFlakeClone : FlakeCommand
|
||||||
{
|
{
|
||||||
Path endDirectory = "";
|
Path destDir;
|
||||||
|
|
||||||
std::string name() override
|
std::string name() override
|
||||||
{
|
{
|
||||||
|
@ -348,7 +354,7 @@ struct CmdFlakeClone : FlakeCommand
|
||||||
|
|
||||||
CmdFlakeClone()
|
CmdFlakeClone()
|
||||||
{
|
{
|
||||||
expectArg("end-dir", &endDirectory, true);
|
expectArg("dest-dir", &destDir, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void run(nix::ref<nix::Store> store) override
|
void run(nix::ref<nix::Store> store) override
|
||||||
|
@ -356,7 +362,7 @@ struct CmdFlakeClone : FlakeCommand
|
||||||
auto evalState = getEvalState();
|
auto evalState = getEvalState();
|
||||||
|
|
||||||
Registries registries = evalState->getFlakeRegistries();
|
Registries registries = evalState->getFlakeRegistries();
|
||||||
gitCloneFlake(getFlakeRef().to_string(), *evalState, registries, endDirectory);
|
gitCloneFlake(getFlakeRef().to_string(), *evalState, registries, destDir);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,34 @@
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
|
MixFlakeOptions::MixFlakeOptions()
|
||||||
|
{
|
||||||
|
mkFlag()
|
||||||
|
.longName("recreate-lock-file")
|
||||||
|
.description("recreate lock file from scratch")
|
||||||
|
.set(&recreateLockFile, true);
|
||||||
|
|
||||||
|
mkFlag()
|
||||||
|
.longName("no-save-lock-file")
|
||||||
|
.description("do not save the newly generated lock file")
|
||||||
|
.set(&saveLockFile, false);
|
||||||
|
|
||||||
|
mkFlag()
|
||||||
|
.longName("no-registries")
|
||||||
|
.description("don't use flake registries")
|
||||||
|
.set(&useRegistries, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
HandleLockFile MixFlakeOptions::getLockFileMode()
|
||||||
|
{
|
||||||
|
return
|
||||||
|
useRegistries
|
||||||
|
? recreateLockFile
|
||||||
|
? (saveLockFile ? RecreateLockFile : UseNewLockFile)
|
||||||
|
: (saveLockFile ? UpdateLockFile : UseUpdatedLockFile)
|
||||||
|
: AllPure;
|
||||||
|
}
|
||||||
|
|
||||||
SourceExprCommand::SourceExprCommand()
|
SourceExprCommand::SourceExprCommand()
|
||||||
{
|
{
|
||||||
mkFlag()
|
mkFlag()
|
||||||
|
@ -21,21 +49,6 @@ SourceExprCommand::SourceExprCommand()
|
||||||
.label("file")
|
.label("file")
|
||||||
.description("evaluate a set of attributes from FILE (deprecated)")
|
.description("evaluate a set of attributes from FILE (deprecated)")
|
||||||
.dest(&file);
|
.dest(&file);
|
||||||
|
|
||||||
mkFlag()
|
|
||||||
.longName("recreate-lock-file")
|
|
||||||
.description("recreate lock file from scratch")
|
|
||||||
.set(&recreateLockFile, true);
|
|
||||||
|
|
||||||
mkFlag()
|
|
||||||
.longName("dont-save-lock-file")
|
|
||||||
.description("save the newly generated lock file")
|
|
||||||
.set(&saveLockFile, false);
|
|
||||||
|
|
||||||
mkFlag()
|
|
||||||
.longName("no-registries")
|
|
||||||
.description("don't use flake registries")
|
|
||||||
.set(&noRegistries, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ref<EvalState> EvalCommand::getEvalState()
|
ref<EvalState> EvalCommand::getEvalState()
|
||||||
|
@ -169,11 +182,7 @@ struct InstallableFlake : InstallableValue
|
||||||
{
|
{
|
||||||
auto vFlake = state.allocValue();
|
auto vFlake = state.allocValue();
|
||||||
|
|
||||||
HandleLockFile handle = cmd.noRegistries ? AllPure :
|
makeFlakeValue(state, flakeRef, cmd.getLockFileMode(), *vFlake);
|
||||||
cmd.recreateLockFile ?
|
|
||||||
(cmd.saveLockFile ? RecreateLockFile : UseNewLockFile)
|
|
||||||
: (cmd.saveLockFile ? UpdateLockFile : UseUpdatedLockFile);
|
|
||||||
makeFlakeValue(state, flakeRef, handle, *vFlake);
|
|
||||||
|
|
||||||
auto vProvides = (*vFlake->attrs->get(state.symbols.create("provides")))->value;
|
auto vProvides = (*vFlake->attrs->get(state.symbols.create("provides")))->value;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue