nix upgrade-nix: Handle .nix-profile being a link to .../profiles/per-user/...
Also some cosmetic improvements.
This commit is contained in:
parent
f08b14c9d0
commit
39f1722f36
2 changed files with 24 additions and 14 deletions
|
@ -241,6 +241,7 @@ let
|
|||
{ diskImage = vmTools.diskImages.ubuntu1204x86_64;
|
||||
}
|
||||
''
|
||||
set -x
|
||||
useradd -m alice
|
||||
su - alice -c 'tar xf ${binaryTarball.x86_64-linux}/*.tar.*'
|
||||
mkdir /dest-nix
|
||||
|
@ -251,14 +252,13 @@ let
|
|||
su - alice -c 'PAGER= nix-store -qR ${build.x86_64-linux}'
|
||||
|
||||
# Check whether 'nix upgrade-nix' works.
|
||||
(! [ -L /nix/var/nix/profiles/per-user/alice/profile-2-link ])
|
||||
cat > /tmp/paths.nix <<EOF
|
||||
{
|
||||
x86_64-linux = "${build.x86_64-linux}";
|
||||
}
|
||||
EOF
|
||||
su - alice -c 'nix upgrade-nix -vvv --nix-store-paths-url file:///tmp/paths.nix'
|
||||
[ -L /nix/var/nix/profiles/per-user/alice/profile-2-link ]
|
||||
(! [ -L /home/alice/.profile-1-link ])
|
||||
su - alice -c 'PAGER= nix-store -qR ${build.x86_64-linux}'
|
||||
|
||||
mkdir -p $out/nix-support
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
#include "download.hh"
|
||||
#include "eval.hh"
|
||||
#include "attr-path.hh"
|
||||
#include "names.hh"
|
||||
#include "progress-bar.hh"
|
||||
|
||||
using namespace nix;
|
||||
|
||||
|
@ -67,28 +69,36 @@ struct CmdUpgradeNix : MixDryRun, StoreCommand
|
|||
storePath = getLatestNix(store);
|
||||
}
|
||||
|
||||
auto version = DrvName(storePathToName(storePath)).version;
|
||||
|
||||
if (dryRun) {
|
||||
stopProgressBar();
|
||||
printError("would upgrade to version %s", version);
|
||||
return;
|
||||
}
|
||||
|
||||
{
|
||||
Activity act(*logger, lvlInfo, actUnknown, fmt("downloading '%s'...", storePath));
|
||||
if (!dryRun)
|
||||
store->ensurePath(storePath);
|
||||
}
|
||||
|
||||
{
|
||||
Activity act(*logger, lvlInfo, actUnknown, fmt("verifying that '%s' works...", storePath));
|
||||
if (!dryRun) {
|
||||
auto program = storePath + "/bin/nix-env";
|
||||
auto s = runProgram(program, false, {"--version"});
|
||||
if (s.find("Nix") == std::string::npos)
|
||||
throw Error("could not verify that '%s' works", program);
|
||||
}
|
||||
}
|
||||
|
||||
stopProgressBar();
|
||||
|
||||
{
|
||||
Activity act(*logger, lvlInfo, actUnknown, fmt("installing '%s' into profile '%s'...", storePath, profileDir));
|
||||
if (!dryRun)
|
||||
runProgram(settings.nixBinDir + "/nix-env", false,
|
||||
{"--profile", profileDir, "-i", storePath, "--no-sandbox"});
|
||||
}
|
||||
|
||||
printError(ANSI_GREEN "upgrade to version %s done" ANSI_NORMAL, version);
|
||||
}
|
||||
|
||||
/* Return the profile in which Nix is installed. */
|
||||
|
@ -113,7 +123,7 @@ struct CmdUpgradeNix : MixDryRun, StoreCommand
|
|||
Path profileDir = dirOf(where);
|
||||
|
||||
// Resolve profile to /nix/var/nix/profiles/<name> link.
|
||||
while (baseNameOf(dirOf(canonPath(profileDir))) != "profiles" && isLink(profileDir))
|
||||
while (canonPath(profileDir).find("/profiles/") == std::string::npos && isLink(profileDir))
|
||||
profileDir = readLink(profileDir);
|
||||
|
||||
printInfo("found profile '%s'", profileDir);
|
||||
|
|
Loading…
Reference in a new issue