NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.65k stars 13.8k forks source link

Tracking pkg-config provides #295047

Closed Ericson2314 closed 1 year ago

Ericson2314 commented 1 year ago

Issue description

The world really needs to know which distro package provides which pkg-config package. This is important because pkg-config package names are the defacto way to refer to C / "foreign" libraries in a distro-agnostic way, and we generally want upstream package managers to use them vs more ad-hoc methods.

This would be really good for upstream language-based tools, our lang2nix tools, really everybody.

In https://github.com/repology/repology-updater/issues/1309, the Repology maintainer @AMDmi3 has kindly offered:

If you propose to publish pkgconfig names for nix[pkgs] (and I suppose use these to map pkgconfig files to package names for all other repos), that should be easy to implement in repology.

That sounds amazing!

Goal

We should have

  1. Something like a meta.pkg-config field, which is either a single string or list of strings
  2. Some sort of setup hook or separate test derivation that verifies the package, when built, indeed provides this pkg-config .pc file.

CC @dcbaker

Ericson2314 commented 1 year ago

CC @hamishmack and @sternenseemann, as I imagine both Haskell infrastructures have a pretty good list initial list we could use to get started on this.

sternenseemann commented 1 year ago

We have a lookup table, but it is very aggressive: It maps names to nixpkgs attribute paths, but those names may either be the name you'd pass to pkg-config or the name you'd pass to the linker via -l. Consequently, the data would need quite a bit of manual cleaning up. For the curious libNixName in Distribution.Nixpkgs.Haskell.FromCabal.Name in cabal2nix'

Artturin commented 1 year ago

nix-index can be used to find all the pc files

nix-locate --regex --top-level '/lib/pkgconfig/.*.pc'

The output format is

abseil-cpp.out                                      502 r /nix/store/wsi5wc7qhmix5f6aiz6p1yyhnhcwrdrp-abseil-cpp-20210324.2/lib/pkgconfig/absl_wyhash.pc
grahamc commented 1 year ago

@Ericson2314 pinged me because of our work on Riff.sh. We looked at doing something similar back in September, but never took steps on it. Maybe this is useful info:

Investigate indexing pkg-config files

go.mod allows listing pkg-config packages

cgo directives also allow listing pkg-config packages

It would be useful to be able to look up nix packages by pkg-config name.

We could probably generate an index mapping pkg-config package names to nixpkgs attr names from a nix-index database, and plonk that into the registry. See how feasible this is, how much data comes out, etc.

We were planning on doing it through something like nix-index instead of adding metadata preemptively to Nixpkgs. But I think either way could work.

Ericson2314 commented 1 year ago

And I was totally unaware that Go leverages this too! Good to see more newer languages going with pkg-config out of the box.

Ericson2314 commented 1 year ago

https://github.com/NixOS/nixpkgs/pull/214304

Ericson2314 commented 1 year ago

That is merged so this is done! Just need to go annotate all the packages now :)