From 64a69b40548f609a760b19f6b31d80e58aa49e3b Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 16 Nov 2022 14:21:07 +0100 Subject: [PATCH] Fix dirOf on the root of a flake --- src/libexpr/primops.cc | 2 +- tests/flakes/common.sh | 2 ++ tests/flakes/flakes.sh | 3 +++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index aaac98aab..19530d896 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -1521,7 +1521,7 @@ static void prim_dirOf(EvalState & state, const PosIdx pos, Value * * args, Valu state.forceValue(*args[0], pos); if (args[0]->type() == nPath) { auto path = args[0]->path(); - v.mkPath(path.parent()); + v.mkPath(path.path.isRoot() ? path : path.parent()); } else { auto path = state.coerceToString(pos, *args[0], context, false, false); auto dir = dirOf(*path); diff --git a/tests/flakes/common.sh b/tests/flakes/common.sh index c333733c2..67adf80ff 100644 --- a/tests/flakes/common.sh +++ b/tests/flakes/common.sh @@ -23,6 +23,8 @@ writeSimpleFlake() { # To test "nix flake init". legacyPackages.x86_64-linux.hello = import ./simple.nix; + + parent = builtins.dirOf ./.; }; } EOF diff --git a/tests/flakes/flakes.sh b/tests/flakes/flakes.sh index fc5cd3b03..17ac4451b 100644 --- a/tests/flakes/flakes.sh +++ b/tests/flakes/flakes.sh @@ -121,6 +121,9 @@ nix build -o $TEST_ROOT/result --expr "(builtins.getFlake \"$flake1Dir\").packag # 'getFlake' on a locked flakeref should succeed even in pure mode. nix build -o $TEST_ROOT/result --expr "(builtins.getFlake \"git+file://$flake1Dir?rev=$hash2\").packages.$system.default" +# Regression test for dirOf on the root of the flake. +[[ $(nix eval --json flake1#parent) = '"/"' ]] + # Building a flake with an unlocked dependency should fail in pure mode. (! nix build -o $TEST_ROOT/result flake2#bar --no-registries) (! nix build -o $TEST_ROOT/result flake2#bar --no-use-registries)