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

mkDerivation: cleaner handling of the name argument #55053

Merged
merged 3 commits into from Feb 4, 2019

Conversation

vbgl
Copy link
Contributor

@vbgl vbgl commented Feb 1, 2019

The logic in mkDerivation for checking whether the name  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 and attrs.name or …).

Consequently, we can revert e20b651, that was wrongly motivated.

Running nix-review yields: “Nothing changed”.

cc/ @matthewbauer.

@@ -177,14 +177,14 @@ rec {
"checkInputs" "installCheckInputs"
"__impureHostDeps" "__propagatedImpureHostDeps"
"sandboxProfile" "propagatedSandboxProfile"])
// (lib.optionalAttrs (name == "")) {
// (lib.optionalAttrs (!(attrs ? name))) {
Copy link
Member

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:

https://github.com/NixOS/nix/blob/6024dc1d97212130c19d3ff5ce6b1d102837eee6/src/libexpr/primops.cc#L530

@@ -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)) {
Copy link
Member

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
@matthewbauer
Copy link
Member

@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:

(import ./. {}).stdenv.mkDerivation {}

produces

error: derivation name missing

Which IMO is better than the old behavior where you would get something like:

error: attribute 'pname' missing, at /home/mbauer/nixpkgs/pkgs/stdenv/generic/make-derivation.nix:181:21

or even older:

error: illegal name: '.drv'

@vbgl
Copy link
Contributor Author

vbgl commented Feb 4, 2019

Looks good. Thanks.

@matthewbauer matthewbauer merged commit 2c31b95 into NixOS:master Feb 4, 2019
@vbgl vbgl deleted the mkderivation-lazy-name branch February 4, 2019 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants