Skip to content

Inconsistent behavior when using import on symlink #15981

@magic0whi

Description

@magic0whi

Describe the bug

Without import, Nix evaluates symlinks to a nix file on its target directory; with import, Nix evaluates within the directory where the symlink resides.

Steps To Reproduce

$ cat to-import.nix
import ./machine2

$ cat machine2/default.nix
{ networking.hostName = baseNameOf ./.; }

$ ls -l machine2/default.nix
machine2/default.nix -> ../machine1/default.nix

$ nix run nixpkgs#nixVersions.latest -- eval \
  --impure --file machine2/default.nix
{ networking = { hostName = "machine1"; }; }

$ nix run nixpkgs#nixVersions.latest -- eval \
  --impure --file machine2/default.nix
{ networking = { hostName = "machine2"; }; }

Expected behavior

Both should either report machine1 or machine2 consistently

Metadata

nix (Nix) 2.34.7

Additional context

Checklist


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