aboutsummaryrefslogtreecommitdiff
path: root/src/nix/profile.cc
diff options
context:
space:
mode:
authorEli Kogan-Wang <elikowa@gmail.com>2022-05-11 12:15:08 +0200
committerEli Kogan-Wang <elikowa@gmail.com>2022-05-11 12:16:35 +0200
commitaefc6c4f41bfac0c76807c234fd0a786dd40f140 (patch)
tree4e56e4d651ca1aa5d46a141b84311792754670dd /src/nix/profile.cc
parent54457382f948bff30e2879a7d9047616e134ac5b (diff)
Add priority for nix profile install
Diffstat (limited to 'src/nix/profile.cc')
-rw-r--r--src/nix/profile.cc29
1 files changed, 27 insertions, 2 deletions
diff --git a/src/nix/profile.cc b/src/nix/profile.cc
index 685776bec..fb8bef670 100644
--- a/src/nix/profile.cc
+++ b/src/nix/profile.cc
@@ -37,7 +37,7 @@ struct ProfileElement
StorePathSet storePaths;
std::optional<ProfileElementSource> source;
bool active = true;
- // FIXME: priority
+ int priority = 5;
std::string describe() const
{
@@ -116,6 +116,9 @@ struct ProfileManifest
for (auto & p : e["storePaths"])
element.storePaths.insert(state.store->parseStorePath((std::string) p));
element.active = e["active"];
+ if(e.contains("priority")) {
+ element.priority = e["priority"];
+ }
if (e.value(sUrl, "") != "") {
element.source = ProfileElementSource {
parseFlakeRef(e[sOriginalUrl]),
@@ -153,6 +156,7 @@ struct ProfileManifest
nlohmann::json obj;
obj["storePaths"] = paths;
obj["active"] = element.active;
+ obj["priority"] = element.priority;
if (element.source) {
obj["originalUrl"] = element.source->originalRef.to_string();
obj["url"] = element.source->resolvedRef.to_string();
@@ -177,7 +181,7 @@ struct ProfileManifest
for (auto & element : elements) {
for (auto & path : element.storePaths) {
if (element.active)
- pkgs.emplace_back(store->printStorePath(path), true, 5);
+ pkgs.emplace_back(store->printStorePath(path), true, element.priority);
references.insert(path);
}
}
@@ -259,6 +263,23 @@ builtPathsPerInstallable(
struct CmdProfileInstall : InstallablesCommand, MixDefaultProfile
{
+ std::optional<int> priority;
+ CmdProfileInstall() {
+ addFlag({
+ .longName = "priority",
+ .description = "The priority of the package to install.",
+ .labels = {"priority"},
+ .handler = {[&](std::string s) {
+ try{
+ priority = std::stoi(s);
+ } catch (std::invalid_argument & e) {
+ throw ParseError("invalid priority '%s'", s);
+ }
+ }},
+ // .completer = // no completer since number
+ });
+ };
+
std::string description() override
{
return "install a package into a profile";
@@ -282,6 +303,10 @@ struct CmdProfileInstall : InstallablesCommand, MixDefaultProfile
for (auto & installable : installables) {
ProfileElement element;
+ if(priority) {
+ element.priority = *priority;
+ };
+
if (auto installable2 = std::dynamic_pointer_cast<InstallableFlake>(installable)) {
// FIXME: make build() return this?
auto [attrPath, resolvedRef, drv] = installable2->toDerivation();