-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
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
nixos/nixpkgs/lib/strings: add stringToValidNixPath #83223
Conversation
When using tools like nixpkgs.lib.attrsets.mapAttrsToList and trying to build derivations where nix store file names are to be created, set attributes like ".stack/config.yml" are invalid, so stringToValidNixPath cleans them up to allow them to be created in the nix store.
@infinisil If that's better than this, then by all means go for it. Or if you think I could adjust this to incorporate some of your concerns, like length, then I'm happy to update this (with your guidance) and accomplish the same goal |
|
||
sanitizeNixPath = prefix: path: | ||
let | ||
safePrefix = if replaceStrings [" "] [""] prefix == "" then "safePrefix_" else prefix; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should prefixing be left to consumers to figure out themselves?
I'm obviously biased towards my solution :). Some arguments for my solution are that it uses regex-based replacement, which should be faster than |
@infinisil If you get that into a PR, I'll test it out for you with what I'm testing with on my side, and if we get that to 👍, I'll close this. How does that sound? |
Done that :) #83241 |
(This is my first time contributing like this to nixpkgs... please be gentle)
Motivation for this change
When using tools like
nixpkgs.lib.attrsets.mapAttrsToList
and trying to build derivations where nix store file names
are to be created, set attributes like
".stack/config.yml"
are invalid, so
sanitizeNixPath
cleans them up to allowthem to be created in the nix store.
I did not include
-
as a valid character because of rycee's reasoning here.If no prefix is provided, the string
safePrefix_
is used.Things done
strings.sanitizeNixPath
strings.sanitizeNixPath
sandbox
innix.conf
on non-NixOS linux)nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
./result/bin/
)nix path-info -S
before and after)I'm not sure how to run the tests locally and could use some help doing that.