Skip to content

bgamari/nix-pkgconfig

Repository files navigation

nix-pkgconfig

nix-pkgconfig is a wrapper for pkg-config allowing nix-unaware applications (e.g. cabal-install) to use packages from nixpkgs (to satisfy native library dependencies).

Getting started

nix-pkgconfig relies on a database of mappings between pkg-config .pc files and the nixpkgs attribute they are provided by. A minimal example database (default-database.json) is included which can be installed via:

$ mkdir -p $XDG_CONFIG_HOME/nix-pkgconfig
$ cp default-database.json $XDG_CONFIG_HOME/nix-pkgconfig/001-default.json

However, it is recommended that you build a more complete database covering nearly all of nixpkgs. This can be built using the build-database.sh script:

$ ./build-database.sh

A nix derivation is provided through default.nix which creates a wrapper for the pkg-config script, enabling convenient use on NixOS:

$ nix build -f . --no-link
$ PATH=$(nix eval --raw -f ./default.nix outPath)/bin:$PATH

When called the pkg-config wrapper will consult the database looking for the nix derivation providing each requested package, build it, and run the requested pkg-config invocation. For instance, we can run:

$ pkg-config --cflags libpq
-I/nix/store/53kwps1ndh29wgjjwa7qf06ygvjxfs09-postgresql-9.6.11/include

Usage with cabal-install

To use this with cabal-install you may either place pkg-config in PATH as described above or explicitly point cabal at the pkg-config script:

cabal new-build --with-pkg-config=$PATH_TO_THIS_REPO/pkg-config

Alternatively, you might consider either adding nix-pkgconfig to environment.systemPackages or your account's mutable environment (e.g. nix-env -i -f .).

Note that some packages respect the pkg-config flag to enable pkg-config-based native library discovery. The included cabal.project.local includes some project stanzas to enable the necessary flags with cabal new-build. Copy these into your project's cabal.project.local if you intend on using nix-pkgconfig.

About

A pkg-config wrapper exposing nixpkgs packages

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published