NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
18.22k stars 14.21k forks source link

pkg-config does not know any libraries. #64530

Open kindaro opened 5 years ago

kindaro commented 5 years ago

Issue description

I need to have some libraries, such as libsystemd, available and visible with pkg-config to do my programming. Unfortunately, I discover that pkg-config --list-all output is completely blank. I can fix it by an appropriate assignment of PKG_CONFIG_PATH, but I would expect it to work out of the box.

Steps to reproduce

Install Nix and then install systemd and pkg-config via nix-env.

% pkg-config --modversion libsystemd
Package libsystemd was not found in the pkg-config search path.
Perhaps you should add the directory containing `libsystemd.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libsystemd' found
% export PKG_CONFIG_PATH=$(dirname `find /nix -name 'libsystemd.pc'`)
% pkg-config --modversion libsystemd
242

Technical details

% nix-shell -p nix-info --run "nix-info -m"
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels/nixpkgs' does not exist, ignoring
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels/nixpkgs' does not exist, ignoring
 - system: `"x86_64-linux"`
 - host os: `Linux 5.1.16-arch1-1-ARCH, Arch Linux, noversion`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.2.2`
 - channels(kindaro): `"nixpkgs-19.09pre184803.d567c486ca5"`
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels/nixpkgs' does not exist, ignoring
 - nixpkgs: `/home/kindaro/.nix-defexpr/channels/nixpkgs`
matthewbauer commented 5 years ago

Nixpkgs does not install headers and pkgconfig meta by default - only runtime dependencies are made available in $HOME/.nix-profile. If you need a development environment like you would get in a Nix builder, you can use nix-shell:

$ nix-shell -p systemd pkgconfig --run 'echo $PKG_CONFIG_PATH'
colemickens commented 5 years ago

@matthewbauer Is this documented? I was just scrolling through issues and saw this. The distinction between nix-env and nix-shell is subtle but rather important, especially for new nixos users...

lheckemann commented 5 years ago

https://nixos.wiki/wiki/FAQ/Libraries

stale[bot] commented 4 years ago

Thank you for your contributions.

This has been automatically marked as stale because it has had no activity for 180 days.

If this is still important to you, we ask that you leave a comment below. Your comment can be as simple as "still important to me". This lets people see that at least one person still cares about this. Someone will have to do this at most twice a year if there is no other activity.

Here are suggestions that might help resolve this more quickly:

  1. Search for maintainers and people that previously touched the related code and @ mention them in a comment.
  2. Ask on the NixOS Discourse.
  3. Ask on the #nixos channel on irc.freenode.net.
andreykaipov commented 3 years ago

Just ran into this. Thought I was going crazy. Figured it must be something Nix is doing so I went searching for issues. I don't know if it's possible, but maybe nix-env can output a warning and link to https://nixos.wiki/wiki/FAQ/Libraries when a user tries to install libraries?

Related issue: https://github.com/NixOS/nixpkgs/issues/41825.

stale[bot] commented 3 years ago

I marked this as stale due to inactivity. → More info

tv42 commented 2 years ago

The command from https://github.com/NixOS/nixpkgs/issues/64530#issuecomment-509695590 does not set PKG_CONFIG_PATH:

$ nix-shell -p systemd pkgconfig --run 'echo $PKG_CONFIG_PATH'
lheckemann commented 2 years ago

@tv42 it now sets PKG_CONFIG_PATH_FOR_TARGET as part of improved cross-compilation support. Nonetheless, pkg-config works correctly:

$ nix-shell -p systemd pkgconfig --run 'pkg-config --libs libsystemd'
-L/nix/store/zc9r3iin18bccr3sjgwsgd6snp8g9g27-systemd-249.7/lib -lsystemd
chris-martin commented 1 year ago

It doesn't seem like pkg-config is picking up anything?

$ nix shell nixpkgs#systemd nixpkgs#pkgconfig nixpkgs#zlib -c pkg-config --list-all
[ no output ]
tv42 commented 1 year ago

Seems to be a difference between nix-shell and nix shell:

$ nix-shell -p systemd pkgconfig --run 'pkg-config --libs libsystemd'
-L/nix/store/cfqfzy5k6l7b2f3bxy2zdhp9sjiw8ijd-systemd-249.5/lib -lsystemd
$ nix shell nixpkgs#systemd nixpkgs#pkgconfig -c pkg-config --libs libsystemd
Package libsystemd was not found in the pkg-config search path.
Perhaps you should add the directory containing `libsystemd.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libsystemd' found
Lord-Valen commented 1 year ago

It doesn't seem like pkg-config is picking up anything?

$ nix shell nixpkgs#systemd nixpkgs#pkgconfig nixpkgs#zlib -c pkg-config --list-all
[ no output ]

Seems to be a difference between nix-shell and nix shell:

$ nix-shell -p systemd pkgconfig --run 'pkg-config --libs libsystemd'
-L/nix/store/cfqfzy5k6l7b2f3bxy2zdhp9sjiw8ijd-systemd-249.5/lib -lsystemd
$ nix shell nixpkgs#systemd nixpkgs#pkgconfig -c pkg-config --libs libsystemd
Package libsystemd was not found in the pkg-config search path.
Perhaps you should add the directory containing `libsystemd.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libsystemd' found

It seems to me that this should be another issue (possibly a nix issue?), since this issue is concerned with documenting pkg-config behaviour (or lackthereof) in nix-env and nix-shell, not nix-shell andnix shell. Curious behaviour, though. The same problem occurs with nix develop.

Seems numtide devshells remove a lot of the usual hooks which would ordinarily handle this. It probably works with the normal mkShell. Speaking of which... https://discourse.nixos.org/t/flakes-how-to-make-pkg-config-work-with-nix-shell/16305/2

tv42 commented 1 year ago

It seems documenting "it does not work" is much less useful than making it work, though. And nix shell/nix develop is the future, isn't it? Probably more bang for buck fixing it there.

PierreR commented 1 year ago

"It does not work" and that is not an issue, is that it ?

DUOLabs333 commented 7 months ago

I just ran into this problem --- is there a way to just add the proper setup hooks to your profile.nix/home.nix directly (I don't use nix-shell)?