building `path:` flake urls produces incorrect output links when `realpath .` is in `/nix/store`
Author: tejing1Created Jun 16, 2025Updated Sep 26, 2026
Labelsbug
Describe the bug
nix building a path: flake url with the current working directory located in the nix store produces a symlink pointing to the base storepath of the (realpath of the) current working directory rather than the output store path.
The same effect does not occur when given the directory not prefixed by path:.
Steps To Reproduce
Running:
#! /usr/bin/env bash
unset tmpdir
cleanup() {
while popd >/dev/null 2>&1; do :; done
[ -d "${tmpdir:-}" ] && rm -rf "$tmpdir"
}
trap cleanup EXIT
tmpdir="$(mktemp -td nix-path-issue-test-XXXXX)"
pushd "$tmpdir" >/dev/null
mkdir -p flake/dir/subdir
cat >flake/flake.nix <<'EOF'
{
outputs = {...}: {
foo = builtins.toFile "foo" "bar";
dir = "${./dir}";
};
}
EOF
nix build ./flake#.dir --out-link dir-in-nix-store
pushd dir-in-nix-store/subdir >/dev/null
nix build "$tmpdir"/flake#.foo --out-link "$tmpdir"/without-path
printf "without-path points to %s\n" "$(readlink "$tmpdir"/without-path)"
nix build path:"$tmpdir"/flake#.foo --out-link "$tmpdir"/with-path
printf "with-path points to %s\n" "$(readlink "$tmpdir"/with-path)"Produces:
without-path points to /nix/store/vxjiwkjkn7x4079qvh1jkl5pn05j2aw0-foo
with-path points to /nix/store/l9pp9z5306crjh3a4rckdp36hlkvfhdj-dirThat value for with-path is "bafflingly wrong", as colemickens put it in NixOS/nixpkgs#144811
Expected behavior
with-path should point to /nix/store/vxjiwkjkn7x4079qvh1jkl5pn05j2aw0-foo
Metadata
Tested with nix 2.29.0 as well as 2.24.10.
Additional context
- Root cause behind NixOS/nixpkgs#144811 which I just helped someone deal with recently... it seems to be back.
- See the less specific, but related #5510
Checklist
- checked [latest Nix manual] ([source])
- checked [open bug issues and pull requests] for possible duplicates
Add :+1: to issues you find important.
Source: NixOS/nix