forked from lix-project/lix
parent
2955732baa
commit
7d1ce1420b
|
@ -307,7 +307,22 @@ std::string optimisticLockProfile(const Path & profile)
|
||||||
|
|
||||||
Path profilesDir()
|
Path profilesDir()
|
||||||
{
|
{
|
||||||
return fmt("%s/profiles/per-user/%s", settings.nixStateDir, getUserName());
|
Path const dir = fmt("%s/profiles/per-user/%s", settings.nixStateDir, getUserName());
|
||||||
|
return dir;
|
||||||
|
|
||||||
|
try {
|
||||||
|
createNixStateDir();
|
||||||
|
} catch (SysError const & e) {
|
||||||
|
warn("ignoring error creating Nix XDG state dir: %s", e.what());
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
createDirs(dir);
|
||||||
|
} catch (SysError const & e) {
|
||||||
|
warn("ignoring error creating home profiles link: %s", e.what());
|
||||||
|
}
|
||||||
|
|
||||||
|
return dir;
|
||||||
|
|
||||||
auto profileRoot =
|
auto profileRoot =
|
||||||
(getuid() == 0)
|
(getuid() == 0)
|
||||||
|
@ -340,31 +355,25 @@ Path ensureDefaultProfile()
|
||||||
Path const profileLink = getDefaultProfileLink();
|
Path const profileLink = getDefaultProfileLink();
|
||||||
try {
|
try {
|
||||||
Path const profile = profilesDir() + "/profile";
|
Path const profile = profilesDir() + "/profile";
|
||||||
|
|
||||||
if (!pathExists(profileLink)) {
|
if (!pathExists(profileLink)) {
|
||||||
try {
|
|
||||||
replaceSymlink(profile, profileLink);
|
replaceSymlink(profile, profileLink);
|
||||||
} catch (SysError const & e) {
|
|
||||||
std::cerr << fmt("error while replaceSymlink(%s, %s)\n", profile, profileLink);
|
|
||||||
std::cerr << fmt("(attempted because %s does not exist)\n", profileLink);
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Backwards compatibiliy measure: Make root's profile available as
|
// Backwards compatibiliy measure: Make root's profile available as
|
||||||
// `.../default` as it's what NixOS and most of the init scripts expect
|
// `.../default` as it's what NixOS and most of the init scripts expect
|
||||||
Path const globalProfileLink = settings.nixStateDir + "/profiles/default";
|
Path const globalProfileLink = settings.nixStateDir + "/profiles/default";
|
||||||
if (getuid() == 0 && !pathExists(globalProfileLink)) {
|
if (getuid() == 0 && !pathExists(globalProfileLink)) {
|
||||||
try {
|
|
||||||
replaceSymlink(profile, globalProfileLink);
|
replaceSymlink(profile, globalProfileLink);
|
||||||
} catch (SysError const & e) {
|
|
||||||
std::cerr << fmt("error while uid0 replaceSymlink(%s, %s)\n", profile, globalProfileLink);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
auto const absProfile = absPath(readLink(profileLink), dirOf(profileLink));
|
return absPath(readLink(profileLink), dirOf(profileLink));
|
||||||
return absProfile;
|
|
||||||
} catch (Error const & e) {
|
} catch (Error const & e) {
|
||||||
std::cerr << "returning original profileLink " << profileLink << std::endl;
|
throw;
|
||||||
std::cerr << "err was " << e.what() << "\n";
|
//return profileLink;
|
||||||
return profileLink;
|
//std::cerr << "returning original profileLink " << profileLink << std::endl;
|
||||||
|
//std::cerr << "err was " << e.what() << "\n";
|
||||||
|
//return profileLink;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -383,8 +392,6 @@ Path getDefaultProfile()
|
||||||
}
|
}
|
||||||
|
|
||||||
return profileLink;
|
return profileLink;
|
||||||
|
|
||||||
//Path const globalProfileLink = settings.nixStateDir + "/profiles/default";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Path defaultChannelsDir()
|
Path defaultChannelsDir()
|
||||||
|
|
|
@ -503,7 +503,7 @@ static bool keep(DrvInfo & drv)
|
||||||
static void installDerivations(Globals & globals,
|
static void installDerivations(Globals & globals,
|
||||||
const Strings & args, const Path & profile)
|
const Strings & args, const Path & profile)
|
||||||
{
|
{
|
||||||
debug("installing derivations");
|
debug("installing derivations into profile %s", profile);
|
||||||
|
|
||||||
/* Get the set of user environment elements to be installed. */
|
/* Get the set of user environment elements to be installed. */
|
||||||
DrvInfos newElems, newElemsTmp;
|
DrvInfos newElems, newElemsTmp;
|
||||||
|
@ -554,8 +554,17 @@ static void installDerivations(Globals & globals,
|
||||||
|
|
||||||
if (globals.dryRun) return;
|
if (globals.dryRun) return;
|
||||||
|
|
||||||
if (createUserEnv(*globals.state, allElems,
|
bool success = createUserEnv(
|
||||||
profile, settings.envKeepDerivations, lockToken)) break;
|
*globals.state,
|
||||||
|
allElems,
|
||||||
|
profile,
|
||||||
|
settings.envKeepDerivations,
|
||||||
|
lockToken
|
||||||
|
);
|
||||||
|
|
||||||
|
if (success) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ bool createUserEnv(EvalState & state, DrvInfos & elems,
|
||||||
const Path & profile, bool keepDerivations,
|
const Path & profile, bool keepDerivations,
|
||||||
const std::string & lockToken)
|
const std::string & lockToken)
|
||||||
{
|
{
|
||||||
|
debug("asked to create a user env %s for %u drvs", profile, elems.size());
|
||||||
/* Build the components in the user environment, if they don't
|
/* Build the components in the user environment, if they don't
|
||||||
exist already. */
|
exist already. */
|
||||||
std::vector<StorePathWithOutputs> drvsToBuild;
|
std::vector<StorePathWithOutputs> drvsToBuild;
|
||||||
|
@ -131,10 +132,11 @@ bool createUserEnv(EvalState & state, DrvInfos & elems,
|
||||||
state.repair ? bmRepair : bmNormal);
|
state.repair ? bmRepair : bmNormal);
|
||||||
|
|
||||||
/* Switch the current user environment to the output path. */
|
/* Switch the current user environment to the output path. */
|
||||||
auto store2 = state.store.dynamic_pointer_cast<LocalFSStore>();
|
auto localStore = state.store.dynamic_pointer_cast<LocalFSStore>();
|
||||||
|
|
||||||
if (store2) {
|
if (localStore) {
|
||||||
PathLocks lock;
|
PathLocks lock;
|
||||||
|
debug("locking profile %s", profile);
|
||||||
lockProfile(lock, profile);
|
lockProfile(lock, profile);
|
||||||
|
|
||||||
Path lockTokenCur = optimisticLockProfile(profile);
|
Path lockTokenCur = optimisticLockProfile(profile);
|
||||||
|
@ -144,7 +146,7 @@ bool createUserEnv(EvalState & state, DrvInfos & elems,
|
||||||
}
|
}
|
||||||
|
|
||||||
debug("switching to new user environment");
|
debug("switching to new user environment");
|
||||||
Path generation = createGeneration(*store2, profile, topLevelOut);
|
Path generation = createGeneration(*localStore, profile, topLevelOut);
|
||||||
switchLink(profile, generation);
|
switchLink(profile, generation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,8 +37,10 @@ nix-env -qa '*' --description | grepQuiet silly
|
||||||
# Query the system.
|
# Query the system.
|
||||||
nix-env -qa '*' --system | grepQuiet $system
|
nix-env -qa '*' --system | grepQuiet $system
|
||||||
|
|
||||||
|
readlink $HOME/.nix-profile || true
|
||||||
|
eza --tree -la $HOME/.local/state/nix || true
|
||||||
# Install "foo-1.0".
|
# Install "foo-1.0".
|
||||||
nix-env -i foo-1.0
|
nix-env --debug -i foo-1.0
|
||||||
|
|
||||||
# Query installed: should contain foo-1.0 now (which should be
|
# Query installed: should contain foo-1.0 now (which should be
|
||||||
# executable).
|
# executable).
|
||||||
|
|
|
@ -21,11 +21,12 @@ in {
|
||||||
users.users.alice.isNormalUser = true;
|
users.users.alice.isNormalUser = true;
|
||||||
#virtualisation.additionalPaths = [ pkgs.hello.drvPath ];
|
#virtualisation.additionalPaths = [ pkgs.hello.drvPath ];
|
||||||
#nix.settings.substituters = lib.mkForce [ ];
|
#nix.settings.substituters = lib.mkForce [ ];
|
||||||
nix.settings.experimental-features = [ "nix-command" "flakes" ];
|
#nix.settings.experimental-features = [ "nix-command" "flakes" ];
|
||||||
nix.settings = {
|
nix.settings = {
|
||||||
substituters = lib.mkForce [ ];
|
substituters = lib.mkForce [ ];
|
||||||
#experimental-features = [ "nix-command" "flakes" ];
|
experimental-features = [ "nix-command" "flakes" ];
|
||||||
allowed-users = [ "alice" ];
|
allowed-users = [ "alice" ];
|
||||||
|
use-xdg-base-directories = true;
|
||||||
};
|
};
|
||||||
nix.nixPath = [ "nixpkgs=${pkgs.path}" ];
|
nix.nixPath = [ "nixpkgs=${pkgs.path}" ];
|
||||||
#nix.package = pkgs.nixVersions.nix_2_18;
|
#nix.package = pkgs.nixVersions.nix_2_18;
|
||||||
|
@ -38,8 +39,6 @@ in {
|
||||||
# fmt: off
|
# fmt: off
|
||||||
|
|
||||||
start_all()
|
start_all()
|
||||||
machine.wait_for_unit("getty@tty1.service")
|
|
||||||
machine.wait_for_unit("nix-daemon.socket")
|
|
||||||
machine.wait_for_unit("multi-user.target")
|
machine.wait_for_unit("multi-user.target")
|
||||||
|
|
||||||
machine.succeed("nix -vv --version >&2")
|
machine.succeed("nix -vv --version >&2")
|
||||||
|
@ -52,6 +51,8 @@ in {
|
||||||
nix-env --version -vv >&2
|
nix-env --version -vv >&2
|
||||||
""")
|
""")
|
||||||
|
|
||||||
|
print(machine.succeed("systemctl cat nix-daemon.service"))
|
||||||
|
|
||||||
# Initial state.
|
# Initial state.
|
||||||
machine.succeed("""
|
machine.succeed("""
|
||||||
su --login alice -c '
|
su --login alice -c '
|
||||||
|
@ -86,6 +87,15 @@ in {
|
||||||
:' >&2
|
:' >&2
|
||||||
""")
|
""")
|
||||||
|
|
||||||
|
machine.succeed("""
|
||||||
|
su --login alice -c '
|
||||||
|
set -euxo pipefail
|
||||||
|
PAGER=cat nix-env --option use-xdg-base-directories false --query '*'
|
||||||
|
${ezaTree} ~
|
||||||
|
${ezaTree} /nix/var/nix/profiles
|
||||||
|
:' >&2
|
||||||
|
""")
|
||||||
|
|
||||||
machine.succeed("""
|
machine.succeed("""
|
||||||
su --login alice -c '
|
su --login alice -c '
|
||||||
set -euxo pipefail
|
set -euxo pipefail
|
||||||
|
|
Loading…
Reference in a new issue