Skip to content

Commit

Permalink
Fix dirOf on the root of a flake
Browse files Browse the repository at this point in the history
  • Loading branch information
edolstra committed Nov 16, 2022
1 parent 4072024 commit 64a69b4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/libexpr/primops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions tests/flakes/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ writeSimpleFlake() {
# To test "nix flake init".
legacyPackages.x86_64-linux.hello = import ./simple.nix;
parent = builtins.dirOf ./.;
};
}
EOF
Expand Down
3 changes: 3 additions & 0 deletions tests/flakes/flakes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 64a69b4

Please sign in to comment.