nix3-upgrade-nix: allow manually specifying new nix

This allows manually specifying a store path for the new Nix that
gets linked into Nix's profile.

Change-Id: Ib71711ffb466febf4a6892e3fdbda644e053770d
This commit is contained in:
Qyriad 2024-04-27 23:09:02 -06:00
parent aae12f5848
commit ee5a1b5a4c
2 changed files with 23 additions and 0 deletions

View file

@ -0,0 +1,6 @@
---
synopsis: add --store-path argument to `nix upgrade-nix`, to manually specify the Nix to upgrade to
cls: 953
---
`nix upgrade-nix` by default downloads a manifest to find the new Nix version to upgrade to, but now you can specify `--store-path` to upgrade Nix to an arbitrary version from the Nix store.

View file

@ -21,6 +21,8 @@ struct CmdUpgradeNix : MixDryRun, EvalCommand
Path profileDir; Path profileDir;
std::string storePathsUrl = "https://github.com/NixOS/nixpkgs/raw/master/nixos/modules/installer/tools/nix-fallback-paths.nix"; std::string storePathsUrl = "https://github.com/NixOS/nixpkgs/raw/master/nixos/modules/installer/tools/nix-fallback-paths.nix";
std::optional<Path> overrideStorePath;
CmdUpgradeNix() CmdUpgradeNix()
{ {
addFlag({ addFlag({
@ -31,6 +33,13 @@ struct CmdUpgradeNix : MixDryRun, EvalCommand
.handler = {&profileDir} .handler = {&profileDir}
}); });
addFlag({
.longName = "store-path",
.description = "A specific store path to upgrade Nix to",
.labels = {"store-path"},
.handler = {&overrideStorePath},
});
addFlag({ addFlag({
.longName = "nix-store-paths-url", .longName = "nix-store-paths-url",
.description = "The URL of the file that contains the store paths of the latest Nix release.", .description = "The URL of the file that contains the store paths of the latest Nix release.",
@ -246,6 +255,14 @@ struct CmdUpgradeNix : MixDryRun, EvalCommand
/* Return the store path of the latest stable Nix. */ /* Return the store path of the latest stable Nix. */
StorePath getLatestNix(ref<Store> store) StorePath getLatestNix(ref<Store> store)
{ {
if (this->overrideStorePath) {
printTalkative(
"skipping Nix version query and using '%s' as latest Nix",
*this->overrideStorePath
);
return store->parseStorePath(*this->overrideStorePath);
}
Activity act(*logger, lvlInfo, actUnknown, "querying latest Nix version"); Activity act(*logger, lvlInfo, actUnknown, "querying latest Nix version");
// FIXME: use nixos.org? // FIXME: use nixos.org?