aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Van den Broeck <nick.van.den.broeck666@gmail.com>2019-03-21 09:30:16 +0100
committerNick Van den Broeck <nick.van.den.broeck666@gmail.com>2019-04-11 14:34:04 +0200
commit4bf3a8226badcdc70c013dfcfa266ee72f6cb89b (patch)
tree44d95c12609ad68b943ea73cb8c55123c7e8333b
parent87033f2c4e32f4851e8c2abf8ab3b56444b65590 (diff)
Automated lockfile updating with `nix build`
-rw-r--r--src/nix/build.cc16
-rw-r--r--src/nix/command.hh6
-rw-r--r--src/nix/installables.cc8
3 files changed, 24 insertions, 6 deletions
diff --git a/src/nix/build.cc b/src/nix/build.cc
index da7c7f614..608946378 100644
--- a/src/nix/build.cc
+++ b/src/nix/build.cc
@@ -11,7 +11,7 @@ struct CmdBuild : MixDryRun, InstallablesCommand
{
Path outLink = "result";
- std::optional<std::string> gitRepo = std::nullopt;
+ bool update = true;
CmdBuild()
{
@@ -28,9 +28,9 @@ struct CmdBuild : MixDryRun, InstallablesCommand
.set(&outLink, Path(""));
mkFlag()
- .longName("update-lock-file")
- .description("update the lock file")
- .dest(&gitRepo);
+ .longName("no-update")
+ .description("don't update the lock files")
+ .set(&update, false);
}
std::string name() override
@@ -78,8 +78,12 @@ struct CmdBuild : MixDryRun, InstallablesCommand
}
}
- if (gitRepo)
- updateLockFile(*evalState, *gitRepo);
+ if (update)
+ for (auto installable : installables) {
+ auto flakeUri = installable->installableToFlakeUri();
+ if (flakeUri)
+ updateLockFile(*evalState, *flakeUri);
+ }
}
};
diff --git a/src/nix/command.hh b/src/nix/command.hh
index 83959bf9a..5d0c0c82c 100644
--- a/src/nix/command.hh
+++ b/src/nix/command.hh
@@ -2,6 +2,7 @@
#include "args.hh"
#include "common-eval-args.hh"
+#include <optional>
namespace nix {
@@ -65,6 +66,11 @@ struct Installable
Buildable toBuildable();
+ virtual std::optional<std::string> installableToFlakeUri()
+ {
+ return std::nullopt;
+ }
+
virtual Value * toValue(EvalState & state)
{
throw Error("argument '%s' cannot be evaluated", what());
diff --git a/src/nix/installables.cc b/src/nix/installables.cc
index e792ce96d..43e15849b 100644
--- a/src/nix/installables.cc
+++ b/src/nix/installables.cc
@@ -176,6 +176,14 @@ struct InstallableFlake : InstallableValue
state.forceValue(*v);
return v;
}
+
+ std::optional<std::string> installableToFlakeUri() override
+ {
+ if (std::get_if<FlakeRef::IsPath>(&flakeRef.data))
+ return flakeRef.to_string();
+ else
+ return std::nullopt;
+ }
};
// FIXME: extend