Skip to content

building path: flake urls produces incorrect output links when realpath . is in /nix/store #13367

@tejing1

Description

@tejing1

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-dir

That 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

Checklist

  • checked [latest Nix manual] ([source])
  • checked [open bug issues and pull requests] for possible duplicates

Add 👍 to issues you find important.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions