forked from lix-project/lix
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();
|
||||
|
||||
enum HandleLockFile
|
||||
enum HandleLockFile : unsigned int
|
||||
{ AllPure // Everything is handled 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
|
||||
|
|
|
@ -11,8 +11,8 @@ extern std::string programPath;
|
|||
struct Value;
|
||||
class Bindings;
|
||||
class EvalState;
|
||||
|
||||
class Store;
|
||||
enum HandleLockFile : unsigned int;
|
||||
|
||||
/* A command that require a Nix store. */
|
||||
struct StoreCommand : virtual Command
|
||||
|
@ -61,17 +61,24 @@ private:
|
|||
std::shared_ptr<EvalState> evalState;
|
||||
};
|
||||
|
||||
struct SourceExprCommand : virtual Args, EvalCommand
|
||||
struct MixFlakeOptions : virtual Args
|
||||
{
|
||||
std::optional<Path> file;
|
||||
|
||||
SourceExprCommand();
|
||||
|
||||
bool recreateLockFile = false;
|
||||
|
||||
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(
|
||||
ref<Store> store, std::vector<std::string> ss);
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
using namespace nix;
|
||||
|
||||
class FlakeCommand : virtual Args, public EvalCommand
|
||||
class FlakeCommand : virtual Args, public EvalCommand, public MixFlakeOptions
|
||||
{
|
||||
std::string flakeUri = ".";
|
||||
|
||||
|
@ -32,7 +32,12 @@ public:
|
|||
Flake getFlake()
|
||||
{
|
||||
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
|
||||
{
|
||||
std::string name() override
|
||||
|
@ -136,7 +142,7 @@ struct CmdFlakeDeps : FlakeCommand, MixJSON
|
|||
auto evalState = getEvalState();
|
||||
evalState->addRegistryOverrides(registryOverrides);
|
||||
|
||||
ResolvedFlake resFlake = resolveFlake(*evalState, getFlakeRef(), UpdateLockFile);
|
||||
auto resFlake = resolveFlake();
|
||||
|
||||
std::queue<ResolvedFlake> todo;
|
||||
todo.push(resFlake);
|
||||
|
@ -334,7 +340,7 @@ struct CmdFlakeInit : virtual Args, Command
|
|||
|
||||
struct CmdFlakeClone : FlakeCommand
|
||||
{
|
||||
Path endDirectory = "";
|
||||
Path destDir;
|
||||
|
||||
std::string name() override
|
||||
{
|
||||
|
@ -348,7 +354,7 @@ struct CmdFlakeClone : FlakeCommand
|
|||
|
||||
CmdFlakeClone()
|
||||
{
|
||||
expectArg("end-dir", &endDirectory, true);
|
||||
expectArg("dest-dir", &destDir, true);
|
||||
}
|
||||
|
||||
void run(nix::ref<nix::Store> store) override
|
||||
|
@ -356,7 +362,7 @@ struct CmdFlakeClone : FlakeCommand
|
|||
auto evalState = getEvalState();
|
||||
|
||||
Registries registries = evalState->getFlakeRegistries();
|
||||
gitCloneFlake(getFlakeRef().to_string(), *evalState, registries, endDirectory);
|
||||
gitCloneFlake(getFlakeRef().to_string(), *evalState, registries, destDir);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -13,6 +13,34 @@
|
|||
|
||||
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()
|
||||
{
|
||||
mkFlag()
|
||||
|
@ -21,21 +49,6 @@ SourceExprCommand::SourceExprCommand()
|
|||
.label("file")
|
||||
.description("evaluate a set of attributes from FILE (deprecated)")
|
||||
.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()
|
||||
|
@ -169,11 +182,7 @@ struct InstallableFlake : InstallableValue
|
|||
{
|
||||
auto vFlake = state.allocValue();
|
||||
|
||||
HandleLockFile handle = cmd.noRegistries ? AllPure :
|
||||
cmd.recreateLockFile ?
|
||||
(cmd.saveLockFile ? RecreateLockFile : UseNewLockFile)
|
||||
: (cmd.saveLockFile ? UpdateLockFile : UseUpdatedLockFile);
|
||||
makeFlakeValue(state, flakeRef, handle, *vFlake);
|
||||
makeFlakeValue(state, flakeRef, cmd.getLockFileMode(), *vFlake);
|
||||
|
||||
auto vProvides = (*vFlake->attrs->get(state.symbols.create("provides")))->value;
|
||||
|
||||
|
|
Loading…
Reference in a new issue