-
-
Notifications
You must be signed in to change notification settings - Fork 13.5k
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
Always sanitize derivation name #166383
Always sanitize derivation name #166383
Conversation
2714486
to
2999ab1
Compare
lib/strings.nix
Outdated
@@ -756,7 +756,14 @@ rec { | |||
sanitizeDerivationName pkgs.hello | |||
=> "-nix-store-2g75chlbpxlrqn15zlby2dfh8hr9qwbk-hello-2.10" | |||
*/ | |||
sanitizeDerivationName = string: lib.pipe string [ | |||
sanitizeDerivationName = | |||
let okRegex = match "^[[:alnum:]+_?=-][[:alnum:]+._?=-]*$"; |
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.
I wonder if we could do all the regex matches from this function in one go. Like a regex that only matches invalid names, in which case it returns all the valid parts.
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.
You don't have to do it for performance anyway, because you'll be optmizing for the rare case.
I can see how it might improve maintainability by DRY, but that may be offset by how ugly the expression may become. You can prove me wrong in a follow-up pr, after we decide whether this whole sanitize-everything idea is good or not :)
lib/strings.nix
Outdated
@@ -756,7 +756,14 @@ rec { | |||
sanitizeDerivationName pkgs.hello | |||
=> "-nix-store-2g75chlbpxlrqn15zlby2dfh8hr9qwbk-hello-2.10" | |||
*/ | |||
sanitizeDerivationName = string: lib.pipe string [ | |||
sanitizeDerivationName = | |||
let okRegex = match "^[[:alnum:]+_?=-][[:alnum:]+._?=-]*$"; |
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.
Small nit: Nix's regex engine always adds an implicit ^
/$
the beginning/end respectively, so these aren't needed here
`^` and `$` are implicit in `match`.
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.
Looks good to me!
Description of changes
Make
mkDerivation
robust.Fixes #166265
Naive change stats: https://github.com/NixOS/nixpkgs/pull/166383/checks?check_run_id=57511133542.7% total alloc, 8% call increaseWith optimization: mixed stats.
TODO
Before
After
Things done
sandbox = true
set innix.conf
? (See Nix manual)nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)nixos/doc/manual/md-to-db.sh
to update generated release notes