-
-
Notifications
You must be signed in to change notification settings - Fork 15.5k
lib/strings: Add sanitizeDerivationName
function
#83241
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
Conversation
@rpearce I think the |
Would adding tests in something like https://github.com/NixOS/nixpkgs/blob/master/lib/tests/misc.nix be useful? I must confess that I don't know how to run them, though |
👍 works perfectly for me |
From the title of this PR I foolishly expected a |
17ca3e8
to
8a41faf
Compare
Changed the name to the suggested one and added some tests. Ideally the tests would generate random strings, put them through the function, then try to create a derivation with it. But our test infrastructure isn't really set up for that (yet?). So for now there's just a bunch of hardcoded ones. |
sanitizeDerivationName
function
Some test improvements:
|
lib/strings.nix
Outdated
sanitizeDerivationName pkgs.hello | ||
=> "-nix-store-2g75chlbpxlrqn15zlby2dfh8hr9qwbk-hello-2.10" | ||
*/ | ||
sanitizeDerivationName = lib.flip lib.pipe [ |
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.
How much overhead do these compose function actually add?
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.
Shouldn't be too much. Though I have a change to it here which would improve performance a bit: 8022565
lib/strings.nix
Outdated
sanitizeDerivationName pkgs.hello | ||
=> "-nix-store-2g75chlbpxlrqn15zlby2dfh8hr9qwbk-hello-2.10" | ||
*/ | ||
sanitizeDerivationName = lib.flip lib.pipe [ |
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.
sanitizeDerivationName = lib.flip lib.pipe [ | |
sanitizeDerivationName = string: lib.pipe string [ |
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.
(noob question about how this works!)
Does this remove the dependency on lib.flip
by explicitly accepting the string
as an argument before passing it on to pipe
's first argument? In essence, this sacrifices the point-free solution for 1 less dependency?
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.
It's less about reducing dependencies, but rather reducing mental overhead. By not using flip
one doesn't need to know what flip
does to understand this function.
57fb955
to
c30a9f6
Compare
@roberth Now did that, and found 2 bugs in the function while doing so :D
@Profpatsch Also applied your suggestion |
One question to discuss: If the name is too long, should it be trimmed from the left or the right? Currently the function trims from the left, which would be better when names represent file names, where the left-most chars are the least specific. But trimming from the right would make more sense when it's a "${name}-${version}" like string, where the ${name} shouldn't be removed. |
51f27dc
to
d9e992a
Compare
d9e992a
to
4b206ac
Compare
Motivation for this change
Was part of #78640, but put into its own PR after the discussion in #83223
Ping @Profpatsch @rpearce @Mic92 @roberth
Things done