Paths are relative to the directory rather than the symlink target when passing a file to be eval'd explicitly and default.nix in the given directory is a symlink #554

Open
opened 2024-10-20 22:48:40 +00:00 by atemu · 2 comments

Describe the bug

When you have a default.nix symlink to an actual default.nix, paths referenced in that default.nix are relative to the symlink itself rather than the default.nix it points to if you explicitly pass the directory to Lix.

[atemu@THESEUS tmp]$ echo 42 > foo/somefile
[atemu@THESEUS tmp]$ echo 'import ./somefile' > foo/default.nix
[atemu@THESEUS tmp]$ ln -s foo/default.nix default.nix
[atemu@THESEUS tmp]$ nix-instantiate --eval 
42
[atemu@THESEUS tmp]$ nix-instantiate --eval .
error:
       … while calling the 'import' builtin
         at /tmp/default.nix:1:1:
            1| import ./somefile
             | ^
            2|

       error: getting status of '/tmp/somefile': No such file or directory

Expected behavior

nix-instantiate and nix-instantiate . should behave the same.

Ideally, both should resolve the symlink and make path references inside of it relative to the target file's dirname.

nix --version output

nix (Lix, like Nix) 2.91.0

Additional context

In the new CLI this is critical because, in contras to the old CLI, -f dir is the only possible way to reference a directory with default.nix.

## Describe the bug When you have a `default.nix` symlink to an actual `default.nix`, paths referenced in that `default.nix` are relative to the symlink itself rather than the `default.nix` it points to if you explicitly pass the directory to Lix. ``` [atemu@THESEUS tmp]$ echo 42 > foo/somefile [atemu@THESEUS tmp]$ echo 'import ./somefile' > foo/default.nix [atemu@THESEUS tmp]$ ln -s foo/default.nix default.nix [atemu@THESEUS tmp]$ nix-instantiate --eval 42 [atemu@THESEUS tmp]$ nix-instantiate --eval . error: … while calling the 'import' builtin at /tmp/default.nix:1:1: 1| import ./somefile | ^ 2| error: getting status of '/tmp/somefile': No such file or directory ``` ## Expected behavior `nix-instantiate` and `nix-instantiate .` should behave the same. Ideally, both should resolve the symlink and make path references inside of it relative to the target file's dirname. ## `nix --version` output nix (Lix, like Nix) 2.91.0 ## Additional context In the new CLI this is critical because, in contras to the old CLI, `-f dir` is the only possible way to reference a directory with `default.nix`.
atemu added the
bug
label 2024-10-20 22:48:40 +00:00
atemu changed title from Paths are relative to the directory rather than the symlink target when passing a file to be eval'd explicitly and default.nix in the given directory is a symlink to Paths are relative to the directory rather than the symlink target when passing a file to be eval'd explicitly and `default.nix` in the given directory is a symlink 2024-10-20 22:49:13 +00:00
Owner

To clarify, is this also the case if you explicitly give it the path to the default.nix symlink or just the directory?

To clarify, is this also the case if you explicitly give it the path to the default.nix symlink or just the directory?
Author

Only if you point it at a directory. If you point it at a symlink file, it's resolved correctly.

Only if you point it at a directory. If you point it at a symlink file, it's resolved correctly.
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: lix-project/lix#554
No description provided.