How to Add pkg-config file to a Nix Package?

Hey there, I’m new to Nix and am kind of blown away by the potential. I’m trying to use it to create a nix-shell environment for building a Tauri project, but it appears that the dbus package doesn’t come with the dbus-1.pc pkg-config file that the Rust crate libdbus-sys needs in order to properly build against it.

My question is what is the best way to add the pkg-config file to the dbus package so that the Rust build will find it. Can I patch the dependency in the shell.nix configuration for this project, or should I update the dbus package to include the dbus-1.pc file. I’m assuming we’d want to update the dbus package for the long term so others don’t have to do locally patch it later, but I’m also curious if there is a good way to make local changes like this that are specific to a nix-shell environment.

Thanks!

4 Likes

The pkg-config file is in the dev output of the dbus package. It should
be sufficient to add dbus to the buildInputs and pkg-config to the
nativeBuildInputs and the setup hook from pkg-config should add it to
PKG_CONFIG_PATH automatically.

9 Likes

Wow, that’s beautiful:

let
  pkgs = import <nixpkgs> {};
in
  pkgs.mkShell {
    buildInputs = with pkgs; [
        dbus
        webkitgtk
        openssl
    ];
    nativeBuildInputs = with pkgs; [
        pkg-config
    ];
    dbus = pkgs.dbus;
  }

I can’t believe it’s that easy.

7 Likes

Happen to stumble on a similar issue when my project depend on editorconfig-core-c.

How to find the .pc file?
I try checking the path but can’t find it

with pkgs;
  mkShell {
    buildInputs = [ zig zigtools editorconfig-core-c dbus ];
    nativeBuildInputs = [ pkg-config ];
    DBUS_PATH = "${dbus}";
    EDITORCONFIG_PATH = "${editorconfig-core-c}";
    # LD_LIBRARY_PATH = "${editorconfig-core-c}/lib";
  }
$ tree -a $DBUS_PATH

/nix/store/015hl23jc3njsl1hg9b2fgr32lhzlzw1-dbus-1.12.20
├── bin
│   ├── dbus-cleanup-sockets
│   ├── dbus-daemon
│   ├── dbus-launch -> /nix/store/svvxq196imx6n9kv8alb9v7mh6j0lawd-dbus-1.12.20-lib/bin/dbus-launch
│   ├── dbus-monitor
│   ├── dbus-run-session
│   ├── dbus-send
│   ├── dbus-test-tool
│   ├── dbus-update-activation-environment
│   └── dbus-uuidgen
├── etc
│   ├── dbus-1
│   │   ├── session.conf
│   │   └── system.conf
│   └── systemd
│       ├── system
│       │   ├── dbus.service
│       │   ├── dbus.socket
│       │   ├── multi-user.target.wants
│       │   │   └── dbus.service -> ../dbus.service
│       │   └── sockets.target.wants
│       │       └── dbus.socket -> ../dbus.socket
│       └── user
│           ├── dbus.service
│           ├── dbus.socket
│           └── sockets.target.wants
│               └── dbus.socket -> ../dbus.socket
├── lib
│   ├── sysusers.d
│   │   └── dbus.conf
│   └── tmpfiles.d
│       └── dbus.conf
├── libexec
│   └── dbus-daemon-launch-helper
└── share
    ├── dbus-1
    │   ├── services
    │   ├── session.conf
    │   ├── session.d
    │   ├── system-services
    │   ├── system.conf
    │   └── system.d
    └── xml
        └── dbus-1
            ├── busconfig.dtd
            └── introspect.dtd

EDIT:
Nevermind. Found out it already in PKG_CONFIG_PATH

$ echo $PKG_CONFIG_PATH

/nix/store/gpwfh2f0s8spx54vaq39i3y0143ph8k0-dbus-1.12.20-dev/lib/pkgconfig /nix/store/5hwv4y1axmvwbsq3wgm2i4x3z95rs6cb-expat-2.2.10-dev/lib/pkgconfig /nix/store/gpwfh2f0s8spx54vaq39i3y0143ph8k0-dbus-1.12.20-dev/lib/pkgconfig /nix/store/5hwv4y1axmvwbsq3wgm2i4x3z95rs6cb-expat-2.2.10-dev/lib/pkgconfig

Now I should find a way to make pkg-config register editorconfig-core-c

i had to set PKG_CONFIG_PATH_FOR_TARGET

nix-build -A some-package

nix-shell -p pkg-config --run 'PKG_CONFIG_PATH_FOR_TARGET=$(readlink -f ./result/lib/pkgconfig/) pkg-config --list-all'

1 Like