Skip to content

Nix Tips 'n Tricks

When using issuing cmake or cpack with Nix CMAKE_INSTALL_PREFIX is autoset to /var/empty/local. To override that at build time, use

sh
cmake -CMAKE_BUILD_PREFIX=/usr/local
cmake -CMAKE_BUILD_PREFIX=/usr/local

Pkg Config with Nix

When working with udev rules, glibc headers, and pkg-config, you may run into quite a headache. The reason this occurs is because pkg-config uses .pc files to located its libraries. It searches all the location outlined in PKG_CONFIG_PATH, but many of the libraries you need are in the /nix/store. As use you need to updated the PKG_CONFIG_PATH with the paths to the nix store libraries. See this GitHub issue.

For example, when using the serialport-rs crate (Rust), you may have to add the following paths to PKG_CONFIG_PATH (newlines added for readability).

PKG_CONFIG_PATH=
/nix/store/db4c9glr7fr77sgb10cmjh61db0lxs1g-dpkg-1.22.1/lib/pkgconfig:
/nix/store/crrplyaja8kwn8z6kz80j065v8919pz4-ipc/lib/pkgconfig:
/nix/store/8w35pcj0dxbv02mkspbfrnd5n480jsfx-liboorb/lib/pkgconfig:
/nix/store/hq1zn6xmgwkawp86bhdyfsmx89ma1923-zstd-1.5.5-dev/lib/pkgconfig:
/nix/store/i1prwl31qab280l7kjmkznqggsgkd8ny-spdlog/lib/pkgconfig:
/nix/store/vd29gqs6fgqdrz95kx232az1xf905l58-nlohmann_json-3.11.2/share/pkgconfig:
/nix/store/fk54356zpjfvym5hyp34zyd3794x7f25-libsodium-1.0.18-dev/lib/pkgconfig:
/nix/store/xl5hlkzbq4vmb38dyih33j92hya87g3p-libzmq3-dev/lib/pkgconfig:
/nix/store/lhgj80qbyazybi5cb6kkxr8f9vj141xq-openssl-3.0.12-dev/lib/pkgconfig:
/nix/store/hks7d5aa2wcw0nbh67g0s7z3dq5vvxva-jq-1.7-dev/lib/pkgconfig:
/nix/store/3ghnv1f2qbhzzjxswy511p7whxm41d1r-systemd-minimal-libs-254.3-dev/lib/pkgconfig:
/nix/store/3ghnv1f2qbhzzjxswy511p7whxm41d1r-systemd-minimal-libs-254.3-dev/share/pkgconfig:
$PKG_CONFIG_PATH
PKG_CONFIG_PATH=
/nix/store/db4c9glr7fr77sgb10cmjh61db0lxs1g-dpkg-1.22.1/lib/pkgconfig:
/nix/store/crrplyaja8kwn8z6kz80j065v8919pz4-ipc/lib/pkgconfig:
/nix/store/8w35pcj0dxbv02mkspbfrnd5n480jsfx-liboorb/lib/pkgconfig:
/nix/store/hq1zn6xmgwkawp86bhdyfsmx89ma1923-zstd-1.5.5-dev/lib/pkgconfig:
/nix/store/i1prwl31qab280l7kjmkznqggsgkd8ny-spdlog/lib/pkgconfig:
/nix/store/vd29gqs6fgqdrz95kx232az1xf905l58-nlohmann_json-3.11.2/share/pkgconfig:
/nix/store/fk54356zpjfvym5hyp34zyd3794x7f25-libsodium-1.0.18-dev/lib/pkgconfig:
/nix/store/xl5hlkzbq4vmb38dyih33j92hya87g3p-libzmq3-dev/lib/pkgconfig:
/nix/store/lhgj80qbyazybi5cb6kkxr8f9vj141xq-openssl-3.0.12-dev/lib/pkgconfig:
/nix/store/hks7d5aa2wcw0nbh67g0s7z3dq5vvxva-jq-1.7-dev/lib/pkgconfig:
/nix/store/3ghnv1f2qbhzzjxswy511p7whxm41d1r-systemd-minimal-libs-254.3-dev/lib/pkgconfig:
/nix/store/3ghnv1f2qbhzzjxswy511p7whxm41d1r-systemd-minimal-libs-254.3-dev/share/pkgconfig:
$PKG_CONFIG_PATH