From 39f1722f364d7ce95717161cc283e96250c14643 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 30 Aug 2018 21:18:56 +0200 Subject: [PATCH] nix upgrade-nix: Handle .nix-profile being a link to .../profiles/per-user/... Also some cosmetic improvements. --- release.nix | 4 ++-- src/nix/upgrade-nix.cc | 34 ++++++++++++++++++++++------------ 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/release.nix b/release.nix index fdf3fa946..e359ebcb2 100644 --- a/release.nix +++ b/release.nix @@ -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 <ensurePath(storePath); + 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); - } + 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"}); + 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/ 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);