aboutsummaryrefslogtreecommitdiff
path: root/src/nix
diff options
context:
space:
mode:
Diffstat (limited to 'src/nix')
-rw-r--r--src/nix/command.hh21
-rw-r--r--src/nix/flake.cc18
-rw-r--r--src/nix/installables.cc41
3 files changed, 51 insertions, 29 deletions
diff --git a/src/nix/command.hh b/src/nix/command.hh
index 423ac5baa..a841b879a 100644
--- a/src/nix/command.hh
+++ b/src/nix/command.hh
@@ -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);
diff --git a/src/nix/flake.cc b/src/nix/flake.cc
index bc2f1cb5b..b4f0f67be 100644
--- a/src/nix/flake.cc
+++ b/src/nix/flake.cc
@@ -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);
}
};
diff --git a/src/nix/installables.cc b/src/nix/installables.cc
index 85ef2cb56..1a79f49fb 100644
--- a/src/nix/installables.cc
+++ b/src/nix/installables.cc
@@ -13,29 +13,42 @@
namespace nix {
-SourceExprCommand::SourceExprCommand()
+MixFlakeOptions::MixFlakeOptions()
{
mkFlag()
- .shortName('f')
- .longName("file")
- .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")
+ .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(&noRegistries, true);
+ .set(&useRegistries, false);
+}
+
+HandleLockFile MixFlakeOptions::getLockFileMode()
+{
+ return
+ useRegistries
+ ? recreateLockFile
+ ? (saveLockFile ? RecreateLockFile : UseNewLockFile)
+ : (saveLockFile ? UpdateLockFile : UseUpdatedLockFile)
+ : AllPure;
+}
+
+SourceExprCommand::SourceExprCommand()
+{
+ mkFlag()
+ .shortName('f')
+ .longName("file")
+ .label("file")
+ .description("evaluate a set of attributes from FILE (deprecated)")
+ .dest(&file);
}
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;