From 812c0dfbe24c8fe93992f77abbf1e5a975ea42f4 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 2 Jun 2016 13:33:49 +0200 Subject: Allow setting the state directory as a store parameter E.g. "local?store=/tmp/store&state=/tmp/var". --- src/nix-env/nix-env.cc | 5 ++++- src/nix-env/user-env.cc | 24 ++++++++++++++---------- 2 files changed, 18 insertions(+), 11 deletions(-) (limited to 'src/nix-env') diff --git a/src/nix-env/nix-env.cc b/src/nix-env/nix-env.cc index fbb0f61a19d2..3f0486bb6541 100644 --- a/src/nix-env/nix-env.cc +++ b/src/nix-env/nix-env.cc @@ -692,6 +692,9 @@ static void opSetFlag(Globals & globals, Strings opFlags, Strings opArgs) static void opSet(Globals & globals, Strings opFlags, Strings opArgs) { + auto store2 = globals.state->store.dynamic_pointer_cast(); + if (!store2) throw Error("--set is not supported for this Nix store"); + for (Strings::iterator i = opFlags.begin(); i != opFlags.end(); ) { string arg = *i++; if (parseInstallSourceOptions(globals, i, opFlags, arg)) ; @@ -722,7 +725,7 @@ static void opSet(Globals & globals, Strings opFlags, Strings opArgs) } debug(format("switching to new user environment")); - Path generation = createGeneration(globals.state->store, globals.profile, drv.queryOutPath()); + Path generation = createGeneration(ref(store2), globals.profile, drv.queryOutPath()); switchLink(globals.profile, generation); } diff --git a/src/nix-env/user-env.cc b/src/nix-env/user-env.cc index ca27a7248107..f239f63776c2 100644 --- a/src/nix-env/user-env.cc +++ b/src/nix-env/user-env.cc @@ -131,18 +131,22 @@ bool createUserEnv(EvalState & state, DrvInfos & elems, state.store->buildPaths({topLevelDrv}, state.repair ? bmRepair : bmNormal); /* Switch the current user environment to the output path. */ - PathLocks lock; - lockProfile(lock, profile); + auto store2 = state.store.dynamic_pointer_cast(); - Path lockTokenCur = optimisticLockProfile(profile); - if (lockToken != lockTokenCur) { - printMsg(lvlError, format("profile ‘%1%’ changed while we were busy; restarting") % profile); - return false; - } + if (store2) { + PathLocks lock; + lockProfile(lock, profile); + + Path lockTokenCur = optimisticLockProfile(profile); + if (lockToken != lockTokenCur) { + printMsg(lvlError, format("profile ‘%1%’ changed while we were busy; restarting") % profile); + return false; + } - debug(format("switching to new user environment")); - Path generation = createGeneration(state.store, profile, topLevelOut); - switchLink(profile, generation); + debug(format("switching to new user environment")); + Path generation = createGeneration(ref(store2), profile, topLevelOut); + switchLink(profile, generation); + } return true; } -- cgit 1.4.1