forked from lix-project/lix
Integrate review changes
This commit is contained in:
parent
aefc6c4f41
commit
be2b19041e
|
@ -609,7 +609,7 @@ InstallableFlake::InstallableFlake(
|
||||||
throw UsageError("'--arg' and '--argstr' are incompatible with flakes");
|
throw UsageError("'--arg' and '--argstr' are incompatible with flakes");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::tuple<std::string, FlakeRef, InstallableValue::DerivationInfo> InstallableFlake::toDerivation()
|
std::tuple<std::string, FlakeRef, InstallableValue::DerivationInfo, std::optional<NixInt>> InstallableFlake::toDerivation()
|
||||||
{
|
{
|
||||||
auto attr = getCursor(*state);
|
auto attr = getCursor(*state);
|
||||||
|
|
||||||
|
@ -621,11 +621,15 @@ std::tuple<std::string, FlakeRef, InstallableValue::DerivationInfo> InstallableF
|
||||||
auto drvPath = attr->forceDerivation();
|
auto drvPath = attr->forceDerivation();
|
||||||
|
|
||||||
std::set<std::string> outputsToInstall;
|
std::set<std::string> outputsToInstall;
|
||||||
|
std::optional<NixInt> priority;
|
||||||
|
|
||||||
if (auto aMeta = attr->maybeGetAttr(state->sMeta))
|
if (auto aMeta = attr->maybeGetAttr(state->sMeta)) {
|
||||||
if (auto aOutputsToInstall = aMeta->maybeGetAttr("outputsToInstall"))
|
if (auto aOutputsToInstall = aMeta->maybeGetAttr("outputsToInstall"))
|
||||||
for (auto & s : aOutputsToInstall->getListOfStrings())
|
for (auto & s : aOutputsToInstall->getListOfStrings())
|
||||||
outputsToInstall.insert(s);
|
outputsToInstall.insert(s);
|
||||||
|
if (auto aPriority = aMeta->maybeGetAttr("priority"))
|
||||||
|
priority = aPriority->getInt();
|
||||||
|
}
|
||||||
|
|
||||||
if (outputsToInstall.empty() || std::get_if<AllOutputs>(&outputsSpec)) {
|
if (outputsToInstall.empty() || std::get_if<AllOutputs>(&outputsSpec)) {
|
||||||
outputsToInstall.clear();
|
outputsToInstall.clear();
|
||||||
|
@ -643,9 +647,10 @@ std::tuple<std::string, FlakeRef, InstallableValue::DerivationInfo> InstallableF
|
||||||
auto drvInfo = DerivationInfo {
|
auto drvInfo = DerivationInfo {
|
||||||
.drvPath = std::move(drvPath),
|
.drvPath = std::move(drvPath),
|
||||||
.outputsToInstall = std::move(outputsToInstall),
|
.outputsToInstall = std::move(outputsToInstall),
|
||||||
|
.priority = priority,
|
||||||
};
|
};
|
||||||
|
|
||||||
return {attrPath, getLockedFlake()->flake.lockedRef, std::move(drvInfo)};
|
return {attrPath, getLockedFlake()->flake.lockedRef, std::move(drvInfo), priority};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<InstallableValue::DerivationInfo> InstallableFlake::toDerivations()
|
std::vector<InstallableValue::DerivationInfo> InstallableFlake::toDerivations()
|
||||||
|
|
|
@ -142,6 +142,7 @@ struct InstallableValue : Installable
|
||||||
{
|
{
|
||||||
StorePath drvPath;
|
StorePath drvPath;
|
||||||
std::set<std::string> outputsToInstall;
|
std::set<std::string> outputsToInstall;
|
||||||
|
std::optional<NixInt> priority;
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual std::vector<DerivationInfo> toDerivations() = 0;
|
virtual std::vector<DerivationInfo> toDerivations() = 0;
|
||||||
|
@ -176,7 +177,7 @@ struct InstallableFlake : InstallableValue
|
||||||
|
|
||||||
Value * getFlakeOutputs(EvalState & state, const flake::LockedFlake & lockedFlake);
|
Value * getFlakeOutputs(EvalState & state, const flake::LockedFlake & lockedFlake);
|
||||||
|
|
||||||
std::tuple<std::string, FlakeRef, DerivationInfo> toDerivation();
|
std::tuple<std::string, FlakeRef, DerivationInfo, std::optional<NixInt>> toDerivation();
|
||||||
|
|
||||||
std::vector<DerivationInfo> toDerivations() override;
|
std::vector<DerivationInfo> toDerivations() override;
|
||||||
|
|
||||||
|
|
|
@ -621,6 +621,28 @@ bool AttrCursor::getBool()
|
||||||
return v.boolean;
|
return v.boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NixInt AttrCursor::getInt()
|
||||||
|
{
|
||||||
|
if (root->db) {
|
||||||
|
if (!cachedValue)
|
||||||
|
cachedValue = root->db->getAttr(getKey());
|
||||||
|
if (cachedValue && !std::get_if<placeholder_t>(&cachedValue->second)) {
|
||||||
|
if (auto i = std::get_if<NixInt>(&cachedValue->second)) {
|
||||||
|
debug("using cached Integer attribute '%s'", getAttrPathStr());
|
||||||
|
return *i;
|
||||||
|
} else
|
||||||
|
throw TypeError("'%s' is not an Integer", getAttrPathStr());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
auto & v = forceValue();
|
||||||
|
|
||||||
|
if (v.type() != nInt)
|
||||||
|
throw TypeError("'%s' is not an Integer", getAttrPathStr());
|
||||||
|
|
||||||
|
return v.integer;
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<std::string> AttrCursor::getListOfStrings()
|
std::vector<std::string> AttrCursor::getListOfStrings()
|
||||||
{
|
{
|
||||||
if (root->db) {
|
if (root->db) {
|
||||||
|
|
|
@ -63,6 +63,7 @@ typedef std::variant<
|
||||||
misc_t,
|
misc_t,
|
||||||
failed_t,
|
failed_t,
|
||||||
bool,
|
bool,
|
||||||
|
NixInt,
|
||||||
std::vector<std::string>
|
std::vector<std::string>
|
||||||
> AttrValue;
|
> AttrValue;
|
||||||
|
|
||||||
|
@ -116,6 +117,8 @@ public:
|
||||||
|
|
||||||
bool getBool();
|
bool getBool();
|
||||||
|
|
||||||
|
NixInt getInt();
|
||||||
|
|
||||||
std::vector<std::string> getListOfStrings();
|
std::vector<std::string> getListOfStrings();
|
||||||
|
|
||||||
std::vector<Symbol> getAttrs();
|
std::vector<Symbol> getAttrs();
|
||||||
|
|
|
@ -95,7 +95,7 @@ static void createLinks(State & state, const Path & srcDir, const Path & dstDir,
|
||||||
throw Error(
|
throw Error(
|
||||||
"files '%1%' and '%2%' have the same priority %3%; "
|
"files '%1%' and '%2%' have the same priority %3%; "
|
||||||
"use 'nix-env --set-flag priority NUMBER INSTALLED_PKGNAME' "
|
"use 'nix-env --set-flag priority NUMBER INSTALLED_PKGNAME' "
|
||||||
"or 'nix profile --priority NUMBER INSTALLED_PKGNAME' "
|
"or 'nix profile install --priority NUMBER INSTALLED_PKGNAME' "
|
||||||
"to change the priority of one of the conflicting packages"
|
"to change the priority of one of the conflicting packages"
|
||||||
" (0 being the highest priority)",
|
" (0 being the highest priority)",
|
||||||
srcFile, readLink(dstFile), priority);
|
srcFile, readLink(dstFile), priority);
|
||||||
|
|
|
@ -269,14 +269,7 @@ struct CmdProfileInstall : InstallablesCommand, MixDefaultProfile
|
||||||
.longName = "priority",
|
.longName = "priority",
|
||||||
.description = "The priority of the package to install.",
|
.description = "The priority of the package to install.",
|
||||||
.labels = {"priority"},
|
.labels = {"priority"},
|
||||||
.handler = {[&](std::string s) {
|
.handler = {&priority},
|
||||||
try{
|
|
||||||
priority = std::stoi(s);
|
|
||||||
} catch (std::invalid_argument & e) {
|
|
||||||
throw ParseError("invalid priority '%s'", s);
|
|
||||||
}
|
|
||||||
}},
|
|
||||||
// .completer = // no completer since number
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -303,21 +296,27 @@ struct CmdProfileInstall : InstallablesCommand, MixDefaultProfile
|
||||||
for (auto & installable : installables) {
|
for (auto & installable : installables) {
|
||||||
ProfileElement element;
|
ProfileElement element;
|
||||||
|
|
||||||
if(priority) {
|
|
||||||
element.priority = *priority;
|
|
||||||
};
|
|
||||||
|
|
||||||
if (auto installable2 = std::dynamic_pointer_cast<InstallableFlake>(installable)) {
|
if (auto installable2 = std::dynamic_pointer_cast<InstallableFlake>(installable)) {
|
||||||
// FIXME: make build() return this?
|
// FIXME: make build() return this?
|
||||||
auto [attrPath, resolvedRef, drv] = installable2->toDerivation();
|
auto [attrPath, resolvedRef, drv, priority] = installable2->toDerivation();
|
||||||
element.source = ProfileElementSource {
|
element.source = ProfileElementSource {
|
||||||
installable2->flakeRef,
|
installable2->flakeRef,
|
||||||
resolvedRef,
|
resolvedRef,
|
||||||
attrPath,
|
attrPath,
|
||||||
installable2->outputsSpec
|
installable2->outputsSpec
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if(drv.priority) {
|
||||||
|
element.priority = *drv.priority;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(priority) { // if --priority was specified we want to override the priority of the installable
|
||||||
|
element.priority = *priority;
|
||||||
|
};
|
||||||
|
|
||||||
element.updateStorePaths(getEvalStore(), store, builtPaths[installable.get()]);
|
element.updateStorePaths(getEvalStore(), store, builtPaths[installable.get()]);
|
||||||
|
|
||||||
manifest.elements.push_back(std::move(element));
|
manifest.elements.push_back(std::move(element));
|
||||||
|
@ -476,7 +475,7 @@ struct CmdProfileUpgrade : virtual SourceExprCommand, MixDefaultProfile, MixProf
|
||||||
Strings{},
|
Strings{},
|
||||||
lockFlags);
|
lockFlags);
|
||||||
|
|
||||||
auto [attrPath, resolvedRef, drv] = installable->toDerivation();
|
auto [attrPath, resolvedRef, drv, priority] = installable->toDerivation();
|
||||||
|
|
||||||
if (element.source->resolvedRef == resolvedRef) continue;
|
if (element.source->resolvedRef == resolvedRef) continue;
|
||||||
|
|
||||||
|
|
|
@ -136,3 +136,5 @@ nix profile install $flake2Dir --priority 100
|
||||||
[[ $($TEST_HOME/.nix-profile/bin/hello) = "Hello World" ]]
|
[[ $($TEST_HOME/.nix-profile/bin/hello) = "Hello World" ]]
|
||||||
nix profile install $flake2Dir --priority 0
|
nix profile install $flake2Dir --priority 0
|
||||||
[[ $($TEST_HOME/.nix-profile/bin/hello) = "Hello World2" ]]
|
[[ $($TEST_HOME/.nix-profile/bin/hello) = "Hello World2" ]]
|
||||||
|
# nix profile install $flake1Dir --priority 100
|
||||||
|
# [[ $($TEST_HOME/.nix-profile/bin/hello) = "Hello World" ]]
|
||||||
|
|
Loading…
Reference in a new issue