Implemented --flake flag for nix build
Also fixed Eelco's PR comments
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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
|
||||
|
||||
+26
-3
@@ -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>()})
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user