NixOS / nix

Nix, the purely functional package manager
https://nixos.org/
GNU Lesser General Public License v2.1
12.95k stars 1.53k forks source link

`nix repl` fails when arg path includes an "@" symbol #7151

Open jakehamilton opened 2 years ago

jakehamilton commented 2 years ago

Describe the bug

When calling nix repl --arg flakePath "/some/path/to/@directory", the command fails with an error stating "path has a trailing slash". This seems somewhat similar to #3189 where Nix may simply be over-restrictive of what characters can allow in a path. I found this issue a few weeks ago when trying to make use of flake-utils-plus's repl helper within a directory that had an @ in the file path. As it turned out, this problem happened with nix repl alone.

Steps To Reproduce

  1. Run nix repl --arg flakePath "/some/path/to/@directory"
  2. You will see the following output.
View Output ```bash $ nix repl --arg flakePath "/some/path/to/@directory" error: path has a trailing slash at «string»:1:15: 1| /some/path/to/@directory | ^ ```

Expected behavior

Nix should allow any valid path character within paths.

I understand that there may be quite a lot to consider for changing how paths work in Nix, so I would be happy to settle with adding support for @ at the moment. However, it would be a good thing for Nix to allow non-ascii characters in general.

nix-env --version output

nix-env (Nix) 2.8.1

Additional context

I don't believe it's necessary to resolve this issue since the problem seems to lie within Nix itself, but here is the line in flake-utils-plus's repl helper that calls nix repl --arg ...: https://github.com/gytis-ivaskevicius/flake-utils-plus/blob/2bf0f91643c2e5ae38c1b26893ac2927ac9bd82a/lib/overlay.nix#L19

dvetutnev commented 1 year ago

Possible solution:

diff --git a/src/libexpr/lexer.l b/src/libexpr/lexer.l
index a3a8608d9..b57a01cde 100644
--- a/src/libexpr/lexer.l
+++ b/src/libexpr/lexer.l
@@ -114,7 +114,7 @@ ANY         .|\n
 ID          [a-zA-Z\_][a-zA-Z0-9\_\'\-]*
 INT         [0-9]+
 FLOAT       (([1-9][0-9]*\.[0-9]*)|(0?\.[0-9]+))([Ee][+-]?[0-9]+)?
-PATH_CHAR   [a-zA-Z0-9\.\_\-\+]
+PATH_CHAR   [a-zA-Z0-9\.\_\-\+\@]
 PATH        {PATH_CHAR}*(\/{PATH_CHAR}+)+\/?
 PATH_SEG    {PATH_CHAR}*\/
 HPATH       \~(\/{PATH_CHAR}+)+\/?
[dvetutnev@vulpecula:~/nix]$ outputs/out/bin/nix eval --expr '/path/p@a'
/path/p@a