aboutsummaryrefslogtreecommitdiff
path: root/src/nix
diff options
context:
space:
mode:
authorNick Van den Broeck <nick.van.den.broeck666@gmail.com>2019-02-21 06:53:01 +0100
committerNick Van den Broeck <nick.van.den.broeck666@gmail.com>2019-03-22 11:16:20 +0100
commitd4ee8afd59cd7935f59b730c432cf58460af8a84 (patch)
tree42f09e66ed56a03508b1b1b55fc03f2e8d6abd88 /src/nix
parent6542de98c298b6dc268b358166bd2f5bea2cc230 (diff)
Implemented --flake flag for nix build
Also fixed Eelco's PR comments
Diffstat (limited to 'src/nix')
-rw-r--r--src/nix/build.cc15
-rw-r--r--src/nix/command.cc9
-rw-r--r--src/nix/command.hh7
-rw-r--r--src/nix/flake.cc29
4 files changed, 41 insertions, 19 deletions
diff --git a/src/nix/build.cc b/src/nix/build.cc
index b329ac38a..12ef08679 100644
--- a/src/nix/build.cc
+++ b/src/nix/build.cc
@@ -1,3 +1,5 @@
+#include "primops/flake.hh"
+#include "eval.hh"
#include "command.hh"
#include "common-args.hh"
#include "shared.hh"
@@ -9,6 +11,8 @@ struct CmdBuild : MixDryRun, InstallablesCommand
{
Path outLink = "result";
+ std::optional<std::string> flakeUri = std::nullopt;
+
CmdBuild()
{
mkFlag()
@@ -22,6 +26,11 @@ struct CmdBuild : MixDryRun, InstallablesCommand
.longName("no-link")
.description("do not create a symlink to the build result")
.set(&outLink, Path(""));
+
+ mkFlag()
+ .longName("flake")
+ .description("update lock file of given flake")
+ .dest(&flakeUri);
}
std::string name() override
@@ -52,6 +61,8 @@ struct CmdBuild : MixDryRun, InstallablesCommand
{
auto buildables = build(store, dryRun ? DryRun : Build, installables);
+ auto evalState = std::make_shared<EvalState>(searchPath, store);
+
if (dryRun) return;
for (size_t i = 0; i < buildables.size(); ++i) {
@@ -66,6 +77,10 @@ struct CmdBuild : MixDryRun, InstallablesCommand
store2->addPermRoot(output.second, absPath(symlink), true);
}
}
+
+ if (flakeUri) {
+ updateLockFile(*evalState, *flakeUri);
+ }
}
};
diff --git a/src/nix/command.cc b/src/nix/command.cc
index e1e32aaae..5967ab36c 100644
--- a/src/nix/command.cc
+++ b/src/nix/command.cc
@@ -27,15 +27,6 @@ void StoreCommand::run()
run(getStore());
}
-JsonFormattable::JsonFormattable()
-{
- mkFlag()
- .longName("json-formattable")
- .shortName('j')
- .description("output will be printed as json")
- .handler([&]() { jsonFormatting = true; });
-}
-
StorePathsCommand::StorePathsCommand(bool recursive)
: recursive(recursive)
{
diff --git a/src/nix/command.hh b/src/nix/command.hh
index 5c2f8c304..b3248222e 100644
--- a/src/nix/command.hh
+++ b/src/nix/command.hh
@@ -26,13 +26,6 @@ private:
std::shared_ptr<Store> _store;
};
-struct JsonFormattable : virtual Command
-{
- bool jsonFormatting = false;;
-
- JsonFormattable();
-};
-
struct Buildable
{
Path drvPath; // may be empty
diff --git a/src/nix/flake.cc b/src/nix/flake.cc
index 22e5b297c..6cef38936 100644
--- a/src/nix/flake.cc
+++ b/src/nix/flake.cc
@@ -34,7 +34,28 @@ struct CmdFlakeList : StoreCommand, MixEvalArgs
}
};
-struct CmdFlakeInfo : FlakeCommand, JsonFormattable
+struct CmdFlakeUpdate : FlakeCommand
+{
+ std::string name() override
+ {
+ return "update";
+ }
+
+ std::string description() override
+ {
+ return "update flake lock file";
+ }
+
+ void run(nix::ref<nix::Store> store) override
+ {
+ auto evalState = std::make_shared<EvalState>(searchPath, store);
+
+ if (flakeUri == "") flakeUri = absPath("./flake.nix");
+ updateLockFile(*evalState, flakeUri);
+ }
+};
+
+struct CmdFlakeInfo : FlakeCommand, MixJSON
{
std::string name() override
{
@@ -50,7 +71,7 @@ struct CmdFlakeInfo : FlakeCommand, JsonFormattable
{
auto evalState = std::make_shared<EvalState>(searchPath, store);
nix::Flake flake = nix::getFlake(*evalState, FlakeRef(flakeUri));
- if (jsonFormatting) {
+ if (json) {
nlohmann::json j;
j["location"] = flake.path;
j["description"] = flake.description;
@@ -65,7 +86,9 @@ struct CmdFlakeInfo : FlakeCommand, JsonFormattable
struct CmdFlake : virtual MultiCommand, virtual Command
{
CmdFlake()
- : MultiCommand({make_ref<CmdFlakeList>(), make_ref<CmdFlakeInfo>()})
+ : MultiCommand({make_ref<CmdFlakeList>()
+ , make_ref<CmdFlakeInfo>()
+ , make_ref<CmdFlakeUpdate>()})
{
}