mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-27 16:16:16 +02:00
Add "nix profile upgrade" command
This commit is contained in:
parent
e30a0155d4
commit
af786432c5
1 changed files with 67 additions and 1 deletions
|
@ -239,7 +239,7 @@ struct CmdProfileRemove : virtual StoreCommand, MixDefaultProfile, MixProfileEle
|
|||
"nix profile remove packages.x86_64-linux.hello"
|
||||
},
|
||||
Example{
|
||||
"To remove all package:",
|
||||
"To remove all packages:",
|
||||
"nix profile remove '.*'"
|
||||
},
|
||||
Example{
|
||||
|
@ -277,6 +277,71 @@ struct CmdProfileRemove : virtual StoreCommand, MixDefaultProfile, MixProfileEle
|
|||
}
|
||||
};
|
||||
|
||||
struct CmdProfileUpgrade : virtual SourceExprCommand, MixDefaultProfile, MixProfileElementMatchers
|
||||
{
|
||||
std::string description() override
|
||||
{
|
||||
return "upgrade packages using their most recent flake";
|
||||
}
|
||||
|
||||
Examples examples() override
|
||||
{
|
||||
return {
|
||||
Example{
|
||||
"To upgrade all packages that were installed using a mutable flake reference:",
|
||||
"nix profile upgrade '.*'"
|
||||
},
|
||||
Example{
|
||||
"To upgrade a specific package:",
|
||||
"nix profile upgrade packages.x86_64-linux.hello"
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
void run(ref<Store> store) override
|
||||
{
|
||||
ProfileManifest manifest(*profile);
|
||||
|
||||
auto matchers = getMatchers(store);
|
||||
|
||||
// FIXME: code duplication
|
||||
PathSet pathsToBuild;
|
||||
|
||||
for (size_t i = 0; i < manifest.elements.size(); ++i) {
|
||||
auto & element(manifest.elements[i]);
|
||||
if (element.source
|
||||
&& !element.source->originalRef.isImmutable()
|
||||
&& matches(element, i, matchers))
|
||||
{
|
||||
Activity act(*logger, lvlChatty, actUnknown,
|
||||
fmt("checking '%s' for updates", element.source->attrPath));
|
||||
|
||||
InstallableFlake installable(*this, FlakeRef(element.source->originalRef), {element.source->attrPath});
|
||||
|
||||
auto [attrPath, resolvedRef, drv] = installable.toDerivation();
|
||||
|
||||
if (element.source->resolvedRef == resolvedRef) continue;
|
||||
|
||||
printInfo("upgrading '%s' from flake '%s' to '%s'",
|
||||
element.source->attrPath, element.source->resolvedRef, resolvedRef);
|
||||
|
||||
element.storePaths = {drv.outPath}; // FIXME
|
||||
element.source = ProfileElementSource{
|
||||
installable.flakeRef,
|
||||
resolvedRef,
|
||||
attrPath,
|
||||
};
|
||||
|
||||
pathsToBuild.insert(makeDrvPathWithOutputs(drv.drvPath, {"out"})); // FIXME
|
||||
}
|
||||
}
|
||||
|
||||
store->buildPaths(pathsToBuild);
|
||||
|
||||
updateProfile(manifest.build(store));
|
||||
}
|
||||
};
|
||||
|
||||
struct CmdProfileInfo : virtual StoreCommand, MixDefaultProfile
|
||||
{
|
||||
std::string description() override
|
||||
|
@ -314,6 +379,7 @@ struct CmdProfile : virtual MultiCommand, virtual Command
|
|||
: MultiCommand({
|
||||
{"install", []() { return make_ref<CmdProfileInstall>(); }},
|
||||
{"remove", []() { return make_ref<CmdProfileRemove>(); }},
|
||||
{"upgrade", []() { return make_ref<CmdProfileUpgrade>(); }},
|
||||
{"info", []() { return make_ref<CmdProfileInfo>(); }},
|
||||
})
|
||||
{ }
|
||||
|
|
Loading…
Reference in a new issue