From 09551fabd092fe26d6b6a13417502a514fbd78b3 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 3 Apr 2024 15:28:13 +0200 Subject: [PATCH] Handle the case where a parent of ~/.nix-defexpr is a symlink Fixes https://github.com/DeterminateSystems/nix-installer/issues/912 and probably #10247. --- src/nix-env/nix-env.cc | 2 +- tests/functional/user-envs.sh | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/nix-env/nix-env.cc b/src/nix-env/nix-env.cc index 177344044..1cc33558f 100644 --- a/src/nix-env/nix-env.cc +++ b/src/nix-env/nix-env.cc @@ -109,7 +109,7 @@ static void getAllExprs(EvalState & state, const SourcePath & path, StringSet & seen, BindingsBuilder & attrs) { StringSet namesSorted; - for (auto & [name, _] : path.readDirectory()) namesSorted.insert(name); + for (auto & [name, _] : path.resolveSymlinks().readDirectory()) namesSorted.insert(name); for (auto & i : namesSorted) { /* Ignore the manifest.nix used by profiles. This is diff --git a/tests/functional/user-envs.sh b/tests/functional/user-envs.sh index dcd6b1b97..7c643f355 100644 --- a/tests/functional/user-envs.sh +++ b/tests/functional/user-envs.sh @@ -189,3 +189,9 @@ nix-env --set $outPath10 [ "$(nix-store -q --resolve $profiles/test)" = $outPath10 ] nix-env --set $drvPath10 [ "$(nix-store -q --resolve $profiles/test)" = $outPath10 ] + +# Test the case where $HOME contains a symlink. +mkdir -p $TEST_ROOT/real-home/alice/.nix-defexpr/channels +ln -sfn $TEST_ROOT/real-home $TEST_ROOT/home +ln -sfn $(pwd)/user-envs.nix $TEST_ROOT/home/alice/.nix-defexpr/channels/foo +HOME=$TEST_ROOT/home/alice nix-env -i foo-0.1