I have a flake here that is showing a strange behavior with nativeBuildInputs
. Basically, if I put the udev
dependency into a pkgs.lib.optional
block for Linux, pkg-config is somehow unable to find it. But if I move it out, suddenly it becomes available.
For instance, this flake doesn’t work:
{
description = "testing pkg-config and libudev";
inputs = { nixpkgs.url = "nixpkgs/nixos-22.05"; };
outputs = { self, nixpkgs }:
let
pkgs = import nixpkgs { system = "x86_64-linux"; };
in {
devShell."x86_64-linux" = pkgs.mkShell {
name = "flake-test";
nativeBuildInputs = pkgs.lib.optional pkgs.stdenv.isLinux [ pkgs.pkg-config pkgs.udev ];
};
};
}
~/src/nix via ❄️ impure (flake-test)
❯ pkg-config --libs --cflags libudev
Package libudev was not found in the pkg-config search path.
Perhaps you should add the directory containing `libudev.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libudev' found
But when I move pkgs.udev
out of the optional block, pkg-config
has no trouble finding it.
{
description = "testing pkg-config and libudev";
inputs = { nixpkgs.url = "nixpkgs/nixos-22.05"; };
outputs = { self, nixpkgs }:
let
pkgs = import nixpkgs { system = "x86_64-linux"; };
in {
devShell."x86_64-linux" = pkgs.mkShell {
name = "flake-test";
nativeBuildInputs = [ pkgs.udev ] ++ pkgs.lib.optional pkgs.stdenv.isLinux [ pkgs.pkg-config ];
};
};
}
❯ pkg-config --libs --cflags libudev
-I/nix/store/yx6l4ch95n1g7xr0ryp176zflvvaq8ph-systemd-250.4-dev/include -L/nix/store/m6qj9brj0xmigvsadsq5n86kp36cxqb5-systemd-250.4/lib -ludev
To be clear… if I remove pkg-config
from the dependency list, pkg-config
stops being in my environment. So it really appears that pkgs.stdenv.isLinux
is working correctly, but there is something strange about how the flake works with udev
.
The goal is to only include dependencies like pkg-config
and udev
on Linux platforms, where the flake is actually going to be shared amongst Mac and Linux developers.
Can any of you pinpoint what I’m doing wrong here?