-
-
Notifications
You must be signed in to change notification settings - Fork 15.5k
mkDerivation: cleaner handling of the name
argument
#55053
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
@@ -177,14 +177,14 @@ rec { | |||
"checkInputs" "installCheckInputs" | |||
"__impureHostDeps" "__propagatedImpureHostDeps" | |||
"sandboxProfile" "propagatedSandboxProfile"]) | |||
// (lib.optionalAttrs (name == "")) { | |||
// (lib.optionalAttrs (!(attrs ? name))) { |
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.
We probably should also do && attrs ? pname && attrs ? version
to let Nix show it's default message if name is missing:
@@ -177,14 +177,14 @@ rec { | |||
"checkInputs" "installCheckInputs" | |||
"__impureHostDeps" "__propagatedImpureHostDeps" | |||
"sandboxProfile" "propagatedSandboxProfile"]) | |||
// (lib.optionalAttrs (name == "")) { | |||
// (lib.optionalAttrs (!(attrs ? name))) { | |||
name = "${attrs.pname}-${attrs.version}"; | |||
} // (lib.optionalAttrs (stdenv.hostPlatform != stdenv.buildPlatform && !dontAddHostSuffix)) { |
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.
This one also should probably make sure either name is set or pname & version are set.
This preserves Nix’s native error handling of missing name: error: derivation name missing
@vbgl I pushed one commit on top of this that hopefully is okay with you. It doesn't set name to pname-version unless name is actually given. This means that something like this:
produces
Which IMO is better than the old behavior where you would get something like:
or even older:
|
Looks good. Thanks. |
The logic in
mkDerivation
for checking whether thename
argument is given or not is wrong.It gets a default value, and then to detect if
name
was present, its value is compared to the default one.This in wrong in that: 1. it is too convoluted; and 2. it forces the evaluation of the value of the
name
attribute when we only care about it being here or not.In this PR, we directly use standard constructs of the Nix language to detect whether attributes are present (
attrs ? name
andattrs.name or …
).Consequently, we can revert e20b651, that was wrongly motivated.
Running
nix-review
yields: “Nothing changed”.cc/ @matthewbauer.