Flakes: how to make `pkg-config` work with `nix shell`?

The following works:

λ nix-shell -p pkg-config zlib --run 'pkg-config --list-all'
zlib zlib - zlib compression library

The following doesn’t work:

λ nix shell nixpkgs#pkg-config nixpkgs#zlib -c pkg-config --list-all

How do I use pkg-config with flake-based workflows?

Context: I’ve switched to flakes, and I want to learn how to create ad-hoc dev environments, so that I can manually build some random package which uses ruby with native extensions without properly packaging the whole thing.

1 Like

pkg-config in a Nix context needs to be explicitly informed where stuff is via PKG_CONFIG_PATH. In nixpkgs this is done via a setup hook (plus a shell wrapper around pkg-config, so it understands e. g. cross compilation better). Setup Hooks are strictly a nixpkgs invention and don’t mean anything to Nix per se.

In nix-shell setup hooks used to just work because nix-shell just completely reused nixpkgs’ environment setup logic. The new nix shell just sets selected environment variables, not much more than PATH=${pkg1}/bin:${pkg2}/bin etc.

If you want to let nixpkgs set up the environment its way, you’ll presumably have to use nix develop or keep using the Nix 2.3 style nix-shell.