aboutsummaryrefslogtreecommitdiff
path: root/src/nix
diff options
context:
space:
mode:
Diffstat (limited to 'src/nix')
-rw-r--r--src/nix/build.cc14
-rw-r--r--src/nix/command.hh20
-rw-r--r--src/nix/flake.cc59
-rw-r--r--src/nix/installables.cc1
4 files changed, 93 insertions, 1 deletions
diff --git a/src/nix/build.cc b/src/nix/build.cc
index b329ac38a..5ab22e26c 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> gitRepo = 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("update-lock-file")
+ .description("update the lock file")
+ .dest(&gitRepo);
}
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,9 @@ struct CmdBuild : MixDryRun, InstallablesCommand
store2->addPermRoot(output.second, absPath(symlink), true);
}
}
+
+ if(gitRepo)
+ updateLockFile(*evalState, *gitRepo);
}
};
diff --git a/src/nix/command.hh b/src/nix/command.hh
index a08347945..c58d5d56e 100644
--- a/src/nix/command.hh
+++ b/src/nix/command.hh
@@ -34,6 +34,26 @@ struct Buildable
typedef std::vector<Buildable> Buildables;
+struct GitRepoCommand : virtual Args
+{
+ std::string gitPath = absPath(".");
+
+ GitRepoCommand ()
+ {
+ expectArg("git-path", &gitPath, true);
+ }
+};
+
+struct FlakeCommand : virtual Args, StoreCommand, MixEvalArgs
+{
+ std::string flakeUri;
+
+ FlakeCommand()
+ {
+ expectArg("flake-uri", &flakeUri);
+ }
+};
+
struct Installable
{
virtual std::string what() = 0;
diff --git a/src/nix/flake.cc b/src/nix/flake.cc
index 9b36c3cbd..a5a1d34db 100644
--- a/src/nix/flake.cc
+++ b/src/nix/flake.cc
@@ -4,6 +4,7 @@
#include "shared.hh"
#include "progress-bar.hh"
#include "eval.hh"
+#include <nlohmann/json.hpp>
using namespace nix;
@@ -33,10 +34,66 @@ struct CmdFlakeList : StoreCommand, MixEvalArgs
}
};
+struct CmdFlakeUpdate : StoreCommand, GitRepoCommand, MixEvalArgs
+{
+ 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");
+ int result = updateLockFile(*evalState, flakeUri);
+ if (result == 1) {
+ std::cout << "You can only update local flakes, not flakes on GitHub.\n";
+ } else if (result == 2) {
+ std::cout << "You can only update local flakes, not flakes through their FlakeId.\n";
+ }
+ }
+};
+
+struct CmdFlakeInfo : FlakeCommand, MixJSON
+{
+ std::string name() override
+ {
+ return "info";
+ }
+
+ std::string description() override
+ {
+ return "list info about a given flake";
+ }
+
+ void run(nix::ref<nix::Store> store) override
+ {
+ auto evalState = std::make_shared<EvalState>(searchPath, store);
+ nix::Flake flake = nix::getFlake(*evalState, FlakeRef(flakeUri));
+ if (json) {
+ nlohmann::json j;
+ j["location"] = flake.path;
+ j["description"] = flake.description;
+ std::cout << j.dump(4) << std::endl;
+ } else {
+ std::cout << "Description: " << flake.description << "\n";
+ std::cout << "Location: " << flake.path << "\n";
+ }
+ }
+};
+
struct CmdFlake : virtual MultiCommand, virtual Command
{
CmdFlake()
- : MultiCommand({make_ref<CmdFlakeList>()})
+ : MultiCommand({make_ref<CmdFlakeList>()
+ , make_ref<CmdFlakeInfo>()
+ , make_ref<CmdFlakeUpdate>()})
{
}
diff --git a/src/nix/installables.cc b/src/nix/installables.cc
index 0453c72c2..21e9e73b8 100644
--- a/src/nix/installables.cc
+++ b/src/nix/installables.cc
@@ -234,6 +234,7 @@ Buildables build(ref<Store> store, RealiseMode mode,
PathSet pathsToBuild;
for (auto & i : installables) {
+ std::cout << i->what() << std::endl;
for (auto & b : i->toBuildables()) {
if (b.drvPath != "") {
StringSet outputNames;