nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at fix-function-merge 55 lines 2.1 kB view raw view rendered
1# pkg-config {#sec-pkg-config} 2 3*pkg-config* is a unified interface for declaring and querying built C/C++ libraries. 4 5Nixpkgs provides a couple of facilities for working with this tool. 6 7## Writing packages providing pkg-config modules {#pkg-config-writing-packages} 8 9Packages should set `meta.pkgConfigModules` with the list of package config modules they provide. 10They should also use `testers.hasPkgConfigModules` to check that the final built package matches that list, 11and optionally check that the pkgconf modules' version metadata matches the derivation's. 12Additionally, the [`validatePkgConfig` setup hook](https://nixos.org/manual/nixpkgs/stable/#validatepkgconfig), will do extra checks on to-be-installed pkg-config modules. 13 14A good example of all these things is miniz: 15 16```nix 17{ pkg-config, testers, ... }: 18 19stdenv.mkDerivation (finalAttrs: { 20 /* ... */ 21 22 nativeBuildInputs = [ pkg-config validatePkgConfig ]; 23 24 passthru.tests.pkg-config = testers.hasPkgConfigModules { 25 package = finalAttrs.finalPackage; 26 versionCheck = true; 27 }; 28 29 meta = { 30 /* ... */ 31 pkgConfigModules = [ "miniz" ]; 32 }; 33}) 34``` 35 36## Accessing packages via pkg-config module name {#sec-pkg-config-usage} 37 38### Within Nixpkgs {#sec-pkg-config-usage-internal} 39 40A [setup hook](#setup-hook-pkg-config) is bundled in the `pkg-config` package to bring a derivation's declared build inputs into the environment. 41This will populate environment variables like `PKG_CONFIG_PATH`, `PKG_CONFIG_PATH_FOR_BUILD`, and `PKG_CONFIG_PATH_HOST` based on: 42 43 - how `pkg-config` itself is depended upon 44 45 - how other dependencies are depended upon 46 47For more details see the section on [specifying dependencies in general](#ssec-stdenv-dependencies). 48 49Normal pkg-config commands to look up dependencies by name will then work with those environment variables defined by the hook. 50 51### Externally {#sec-pkg-config-usage-external} 52 53The `defaultPkgConfigPackages` package set is a set of aliases, named after the modules they provide. 54This is meant to be used by language-to-nix integrations. 55Hand-written packages should use the normal Nixpkgs attribute name instead.