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: Expose pname & version in meta #68620

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jtojnar
Copy link
Member

@jtojnar jtojnar commented Sep 12, 2019

Nix only knows of name attribute and considers pname what parseDrvName spits out. Unfortunately, that fails to account for many real-life packages that have variants or dashes followed by number in their name. Since many of packages in nixpkgs already have pname corresponding to project name, we will export it here. We will fallback to the parseDrvName algorithm when pname is not present.
We handle the version similarly.

This will be useful for Repology as well as any other scripted processing of Nixpkgs JSON dump.

See: https://github.com/NixOS/nixos-homepage/issues/306

@ofborg ofborg bot added the 6.topic: stdenv Standard environment label Sep 12, 2019
Nix only knows of `name` attribute and considers `pname` what parseDrvName
spits out. Unfortunately, that fails to account for many real-life packages
that have variants or dashes followed by number in their name.
Since many of packages in nixpkgs already have pname corresponding
to project name, we will export it here. We will fallback to the parseDrvName
algorithm when pname is not present.
We handle the version similarly.

This will be useful for Repology as well as any other scripted processing of
Nixpkgs JSON dump.

See: https://github.com/NixOS/nixos-homepage/issues/306
@jtojnar
Copy link
Member Author

jtojnar commented Sep 12, 2019

Well, we need to get the project name somehow, even when pname attribute is not set. We could promote it to meta only when it is in attrs as you suggest but then scripts would still need fall back to parseDrvName themselves (or use the pname attribute introduced in NixOS/nix@cd933b2). This will at least provide an uniform interface.

On the other hand, going your proposed route route would allow us to consider meta.pname vetted, which might be beneficial. Repology could decide to consider packages without meta.pname untrusted or drop them altogether. cc @AMDmi3

@jtojnar
Copy link
Member Author

jtojnar commented Sep 13, 2019

If pname is not set then it is not a project (in repology's sense and also with the meaning that name does not contain project name and/or version)

As fair as I know, we do not have formally defined semantics for pname.

Would it be correct to extract pname and version from names like "CVE-2017-6827+CVE-2017-6828+CVE-2017-6832+CVE-2017-6835+CVE-2017-6837.patch", "unit-user-.service", "ntfs-3g_ntfsprogs-2017.3.23.tgz" or "daemon.conf" ?

Those derivations would not be listed by nix-env. Which makes me wonder how does nix-env which attributes are packages and which are not.

@jtojnar
Copy link
Member Author

jtojnar commented Sep 13, 2019

Those derivations would not be listed by nix-env. Which makes me wonder how does nix-env which attributes are packages and which are not.

It looks like recurseForDerivations is used by nix-env to traverse nested atribute sets:

https://github.com/NixOS/nixpkgs/blob/83aa6f5d7f540a088e79941e103bd85a2f0114afP/pkgs/top-level/all-packages.nix#L67

And things like auto-patchelf-hook are not filtered out. Weirdly, Repology ignores it, even though I did not see any relevant ignore rule.

@vcunat
Copy link
Member

vcunat commented Sep 13, 2019

nix-env anyway will stay with Nix heuristic split (so it will split "package-unstable-20190101" as "package-unstable" and "20190101" irregardless of whether pname is "package", "package-unstable" or absent).

That's one of the reasons I really dislike this "unstable-" versions naming. It confuses things, and I can see almost no advantages of that scheme. For example, I use nix-env -i /some/nix/store/path and there it's not even possible to detect where version starts.

@7c6f434c
Copy link
Member

7c6f434c commented Sep 13, 2019 via email

# algorithm when pname is not present.
# We handle the version similarly.
pname = attrs.pname or (builtins.parseDrvName attrs.name).name;
version = attrs.version or ((x: if x != "" then x else null) (builtins.parseDrvName attrs.name).version);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @volth that we should not have these fallbacks to parseDrvName because it is surprising to me that it would work like that. pname typically goes into name, so it is weird for name to go into pname in some cases.

Without these fallbacks the change seems quite uncontroversial. You are just saying make the attrs available in meta if they were passed in to mkDerivation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to make something like nameForRepology in the website export code with this logic, we could do that.

@edolstra
Copy link
Member

edolstra commented Nov 7, 2019

I don't think this is a good idea because it creates the possibility of the attributes in the derivation being inconsistent with the ones in meta. (In other words, it denormalizes the derivation, providing possibly conflicting sources of truth.)

@jtojnar
Copy link
Member Author

jtojnar commented Nov 7, 2019

Yeah, this is definitely a concern but we do need some way to find the version. Since is not extractable from name in general case (for projects containing a -[0-9] or versions starting with [^0-9]), we either need to pass it through some channel that nix-env recognizes (like done using meta here), or teach Nix about version and pname.

@ryantm
Copy link
Member

ryantm commented Nov 7, 2019

Can we add pname and version to derivationArg instead? Is there still a concern they can be desynced by overrides?

@danbst
Copy link
Contributor

danbst commented Mar 15, 2020

related #75813

@FRidh
Copy link
Member

FRidh commented Mar 29, 2020

I think that, when pname is explicitly passed, we should check that parseDrvName pname return an empty version.

FRidh added a commit to FRidh/nixpkgs that referenced this pull request Mar 29, 2020
The `pname` passed to `stdenv.mkDerivation` consists of the name prefix
as well as the `pname` passed to `stdenv.mkDerivation`.

This is needed in case we want to test for valid `pname` in
`stdenv.mkDerivation`.
NixOS#68620 (comment)
@jtojnar jtojnar marked this pull request as draft June 1, 2020 05:20
@stale
Copy link

stale bot commented Nov 28, 2020

I marked this as stale due to inactivity. → More info

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Nov 28, 2020
@davidak
Copy link
Member

davidak commented Nov 28, 2020

What is the status? What need to happen that this can get merged?

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Nov 28, 2020
@stale
Copy link

stale bot commented Jun 3, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jun 3, 2021
@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Mar 20, 2024
@wegank wegank added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jul 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.status: merge conflict 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md 6.topic: repology https://repology.org/ 6.topic: stdenv Standard environment 10.rebuild-darwin: 0 10.rebuild-linux: 0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants