Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot implicitly copy oddly-named files to nix store #6515

Open
tejing1 opened this issue May 10, 2022 · 5 comments
Open

Cannot implicitly copy oddly-named files to nix store #6515

tejing1 opened this issue May 10, 2022 · 5 comments
Labels
bug language The Nix expression language; parser, interpreter, primops, evaluation, etc

Comments

@tejing1
Copy link

tejing1 commented May 10, 2022

Describe the bug

Attempting to implicitly copy files to the nix store fails when the file's basename does not conform the the sanity requirements imposed on nix store paths.

Steps To Reproduce

$ touch test\ file
$ nix eval --impure --expr '"${./. + "/test file"}"'
error: store path 'rj4w2hxhanlcasa863zqln3yv98v6v61-test file' contains illegal character ' '

Expected behavior

Nix should sanitize the basename before constructing the store path, such that this operation always succeeds, just with a sanitized store path.

This shouldn't cause a reproducibility problem if implemented, since the behavior only differs in situations where there would have been a fatal error before. It's still fail-or-succeed-correctly.

nix-env --version output

Tried with 2.8.0, still a problem.

Additional context

I found this problem while trying to track down why a friend couldn't place his network manager connection files in /etc using the environment.etc options in configuration.nix. It was because the files were named after the SSIDs, and the SSIDs have unfortunate characters in their names. I was able to work around it with builtins.toFile + builtins.readFile + lib.strings.sanitizeDerivationName, but this really should "just work".

@tejing1 tejing1 added the bug label May 10, 2022
@matthewbauer
Copy link
Member

You can use builtins.path to specify a custom name to use. I think that's more efficient than builtins.toFile + builtins.readFile.

@tejing1
Copy link
Author

tejing1 commented Jan 30, 2023

Still a problem.

@stale stale bot removed the stale label Jan 30, 2023
@roberth roberth added the language The Nix expression language; parser, interpreter, primops, evaluation, etc label Mar 20, 2023
@arichtman
Copy link

arichtman commented Aug 7, 2023

I think I'm having the same issue but it's fetchUrl that's not sanitizing the file name

error: store path 'g179hjgfa2g6fji4s3gw1aq7hvxzkq1k-hugo,rust,linux,macos,direnv,python,windows,terraform,terragrunt,rust-analyzer,dotnetcore' contains illegal character ','

image

URL-encoding it still threw an error, just over the % character

@tejing1
Copy link
Author

tejing1 commented Aug 7, 2023

Just add a name field to the fetchurl args attrset. Should solve it. But yes, fetchurl should really sanitize the name as well.

@arichtman
Copy link

Thanks! I was able to get it working. I can see the argument for not wanting to apply a lossy sanitizing algorithm by default. Have a great day!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug language The Nix expression language; parser, interpreter, primops, evaluation, etc
Projects
None yet
Development

No branches or pull requests

4 participants