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.testMetaPkgConfig` to check that the final built package matches that list. 11Additionally, the [`validatePkgConfig` setup hook](https://nixos.org/manual/nixpkgs/stable/#validatepkgconfig), will do extra checks on to-be-installed pkg-config modules. 12 13A good example of all these things is zlib: 14 15``` 16{ pkg-config, testers, ... }: 17 18stdenv.mkDerivation (finalAttrs: { 19 ... 20 21 nativeBuildInputs = [ pkg-config validatePkgConfig ]; 22 23 passthru.tests.pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage; 24 25 meta = { 26 ... 27 pkgConfigModules = [ "zlib" ]; 28 }; 29}) 30``` 31 32## Accessing packages via pkg-config module name {#sec-pkg-config-usage} 33 34### Within Nixpkgs {#sec-pkg-config-usage-internal} 35 36A [setup hook](#setup-hook-pkg-config) is bundled in the `pkg-config` package to bring a derivation's declared build inputs into the environment. 37This will populate environment variables like `PKG_CONFIG_PATH`, `PKG_CONFIG_PATH_FOR_BUILD`, and `PKG_CONFIG_PATH_HOST` based on: 38 39 - how `pkg-config` itself is depended upon 40 41 - how other dependencies are depended upon 42 43For more details see the section on [specifying dependencies in general](#ssec-stdenv-dependencies). 44 45Normal pkg-config commands to look up dependencies by name will then work with those environment variables defined by the hook. 46 47### Externally {#sec-pkg-config-usage-external} 48 49The `defaultPkgConfigPackages` package set is a set of aliases, named after the modules they provide. 50This is meant to be used by language-to-nix integrations. 51Hand-written packages should use the normal Nixpkgs attribute name instead.