cachix / devenv

Fast, Declarative, Reproducible, and Composable Developer Environments
https://devenv.sh
Apache License 2.0
3.56k stars 259 forks source link

pkg-config broken #862

Closed brianmay closed 3 weeks ago

brianmay commented 6 months ago

Describe the bug pkg-config complains that it can't find openssl, but openssl is installed.

To reproduce

devShells.default = devenv.lib.mkShell {
          inherit inputs pkgs;
          modules = [{
            packages = with pkgs; [
              ...
              pkgconfig
              openssl
            ];
            enterShell = ''
               [...]
            '';
          }];
        };

Gives the error (when building rust application):

  run pkg_config fail: `PKG_CONFIG_ALLOW_SYSTEM_CFLAGS="1" PKG_CONFIG_PATH="/nix/store/57mashplg49bqmhcwacbh6z0ishnc1ii-devenv-profile/lib/pkgconfig:" "pkg-config" "--libs" "--cflags" "openssl"` did not exit successfully: exit status: 1
  error: could not find system library 'openssl' required by the 'openssl-sys' crate

  --- stderr
  Package openssl was not found in the pkg-config search path.
  Perhaps you should add the directory containing `openssl.pc'
  to the PKG_CONFIG_PATH environment variable
  No package 'openssl' found

But the openssl wrapper is at the expected location:

$ cat /nix/store/57mashplg49bqmhcwacbh6z0ishnc1ii-devenv-profile/lib/pkgconfig/openssl.pc                                                                
prefix=/nix/store/i57qjfacl3hv7sc1s1lj4z6fssh69nd3-openssl-3.0.11
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=/nix/store/7nbh3b6hhjqjs3nfy529g38l85iv46i9-openssl-3.0.11-dev/include

Name: OpenSSL
Description: Secure Sockets Layer and cryptography libraries and tools
Version: 3.0.11
Requires: libssl libcrypto

The environment:

$ export | grep PKG_CONFIG_PATH                         
PKG_CONFIG_PATH=/nix/store/57mashplg49bqmhcwacbh6z0ishnc1ii-devenv-profile/lib/pkgconfig:

With debugging:

$ PKG_CONFIG_ALLOW_SYSTEM_CFLAGS="1" PKG_CONFIG_PATH="/nix/store/h595l9bizr7jkpjrw3d55x6ylj7nky2w-devenv-profile/lib/pkgconfig" sh -ex $(which "pkg-config") "--libs" "--cflags" "openssl"                                          
+ set -eu -o pipefail +o posix
+ shopt -s nullglob
+ ((  0 >= 7  ))
+ source /nix/store/7l5gbdz3rcab57r24arg61i4vavpf2cz-pkg-config-wrapper-0.29.2/nix-support/utils.bash
+ '[' -z '' ']'
+ source /nix/store/7l5gbdz3rcab57r24arg61i4vavpf2cz-pkg-config-wrapper-0.29.2/nix-support/add-flags.sh
++ var_templates_list=(PKG_CONFIG_PATH)
++ accumulateRoles
++ role_suffixes=()
++ declare -ga role_suffixes
++ '[' '' ']'
++ '[' '' ']'
++ '[' 1 ']'
++ role_suffixes+=('_FOR_TARGET')
++ for var in "${var_templates_list[@]}"
++ mangleVarListGeneric : PKG_CONFIG_PATH _FOR_TARGET
++ local sep=:
++ shift
++ local var=PKG_CONFIG_PATH
++ shift
++ role_suffixes=('_FOR_TARGET')
++ local -a role_suffixes
++ local outputVar=PKG_CONFIG_PATH_x86_64_unknown_linux_gnu
++ declare -gx PKG_CONFIG_PATH_x86_64_unknown_linux_gnu+=
++ for suffix in "${role_suffixes[@]}"
++ local inputVar=PKG_CONFIG_PATH_FOR_TARGET
++ '[' -v PKG_CONFIG_PATH_FOR_TARGET ']'
++ export NIX_PKG_CONFIG_WRAPPER_FLAGS_SET_x86_64_unknown_linux_gnu=1
++ NIX_PKG_CONFIG_WRAPPER_FLAGS_SET_x86_64_unknown_linux_gnu=1
+ set -- --libs --cflags openssl
+ ((  1 > 0  ))
+ PKG_CONFIG_PATH=
+ exec /nix/store/s0spf4mcz9yr89d50kblds4agvqajp8x-pkg-config-0.29.2/bin/pkg-config --libs --cflags openssl
Package openssl was not found in the pkg-config search path.
Perhaps you should add the directory containing `openssl.pc'
to the PKG_CONFIG_PATH environment variable
No package 'openssl' found

No wonder, it is setting PKG_CONFIG_PATH to nothing for some reason.

If I bypass the wrapper script, it works:

$ PKG_CONFIG_ALLOW_SYSTEM_CFLAGS="1" PKG_CONFIG_PATH="/nix/store/h595l9bizr7jkpjrw3d55x6ylj7nky2w-devenv-profile/lib/pkgconfig" /nix/store/s0spf4mcz9yr89d50kblds4agvqajp8x-pkg-config-0.29.2/bin/pkg-config --libs --cflags openssl
-I/nix/store/7nbh3b6hhjqjs3nfy529g38l85iv46i9-openssl-3.0.11-dev/include -L/nix/store/i57qjfacl3hv7sc1s1lj4z6fssh69nd3-openssl-3.0.11/lib -lssl -lcrypto

I am not sure where this wrapper script comes from:

lrwxrwxrwx 879 root  1 Jan  1970 /nix/store/57mashplg49bqmhcwacbh6z0ishnc1ii-devenv-profile/bin/pkg-config -> /nix/store/7l5gbdz3rcab57r24arg61i4vavpf2cz-pkg-config-wrapper-0.29.2/bin/pkg-config

This problem did not occur until I changed to devenv however. This is the same command with pkgs.mkShell:

PKG_CONFIG_ALLOW_SYSTEM_CFLAGS="1" PKG_CONFIG_PATH="/nix/store/h595l9bizr7jkpjrw3d55x6ylj7nky2w-devenv-profile/lib/pkgconfig" sh -ex $(which "pkg-config") "--libs" "--cflags" "openssl" 
+ set -eu -o pipefail +o posix
+ shopt -s nullglob
+ ((  0 >= 7  ))
+ source /nix/store/7l5gbdz3rcab57r24arg61i4vavpf2cz-pkg-config-wrapper-0.29.2/nix-support/utils.bash
+ '[' -z '' ']'
+ source /nix/store/7l5gbdz3rcab57r24arg61i4vavpf2cz-pkg-config-wrapper-0.29.2/nix-support/add-flags.sh
++ var_templates_list=(PKG_CONFIG_PATH)
++ accumulateRoles
++ role_suffixes=()
++ declare -ga role_suffixes
++ '[' '' ']'
++ '[' '' ']'
++ '[' 1 ']'
++ role_suffixes+=('_FOR_TARGET')
++ for var in "${var_templates_list[@]}"
++ mangleVarListGeneric : PKG_CONFIG_PATH _FOR_TARGET
++ local sep=:
++ shift
++ local var=PKG_CONFIG_PATH
++ shift
++ role_suffixes=('_FOR_TARGET')
++ local -a role_suffixes
++ local outputVar=PKG_CONFIG_PATH_x86_64_unknown_linux_gnu
++ declare -gx PKG_CONFIG_PATH_x86_64_unknown_linux_gnu+=
++ for suffix in "${role_suffixes[@]}"
++ local inputVar=PKG_CONFIG_PATH_FOR_TARGET
++ '[' -v PKG_CONFIG_PATH_FOR_TARGET ']'
++ export PKG_CONFIG_PATH_x86_64_unknown_linux_gnu+=/nix/store/gwxchbsz56q1qjqn9scqm881a2j83m1p-python3-3.10.13-env/lib/pkgconfig:/nix/store/7nbh3b6hhjqjs3nfy529g38l85iv46i9-openssl-3.0.11-dev/lib/pkgconfig:/nix/store/hq9gk0b60w877fbmqhq95xv5kxz3p3mp-protobuf-3.21.12/lib/pkgconfig:/nix/store/my1yzawmz5d1rvr76f3ryrqhlwjrh0d2-fontconfig-2.14.0-dev/lib/pkgconfig:/nix/store/xxfh7wqjkwr3mgl2a8ym9y7hvxywa32m-freetype-2.13.0-dev/lib/pkgconfig:/nix/store/j0zwp9zygvadcly9dxpm0f4ga7h0n8c9-zlib-1.2.13-dev/lib/pkgconfig:/nix/store/32lspl6qhmsm53l5n4wpgcdfzcjn6br4-bzip2-1.0.8-dev/lib/pkgconfig:/nix/store/pndmab9dmyjy2l39hyvhk90zrbhnm100-brotli-1.0.9-dev/lib/pkgconfig:/nix/store/86cvg8vkqkjls6cic26nb5rjjdjcjga3-libpng-apng-1.6.39-dev/lib/pkgconfig
++ PKG_CONFIG_PATH_x86_64_unknown_linux_gnu+=/nix/store/gwxchbsz56q1qjqn9scqm881a2j83m1p-python3-3.10.13-env/lib/pkgconfig:/nix/store/7nbh3b6hhjqjs3nfy529g38l85iv46i9-openssl-3.0.11-dev/lib/pkgconfig:/nix/store/hq9gk0b60w877fbmqhq95xv5kxz3p3mp-protobuf-3.21.12/lib/pkgconfig:/nix/store/my1yzawmz5d1rvr76f3ryrqhlwjrh0d2-fontconfig-2.14.0-dev/lib/pkgconfig:/nix/store/xxfh7wqjkwr3mgl2a8ym9y7hvxywa32m-freetype-2.13.0-dev/lib/pkgconfig:/nix/store/j0zwp9zygvadcly9dxpm0f4ga7h0n8c9-zlib-1.2.13-dev/lib/pkgconfig:/nix/store/32lspl6qhmsm53l5n4wpgcdfzcjn6br4-bzip2-1.0.8-dev/lib/pkgconfig:/nix/store/pndmab9dmyjy2l39hyvhk90zrbhnm100-brotli-1.0.9-dev/lib/pkgconfig:/nix/store/86cvg8vkqkjls6cic26nb5rjjdjcjga3-libpng-apng-1.6.39-dev/lib/pkgconfig
++ export NIX_PKG_CONFIG_WRAPPER_FLAGS_SET_x86_64_unknown_linux_gnu=1
++ NIX_PKG_CONFIG_WRAPPER_FLAGS_SET_x86_64_unknown_linux_gnu=1
+ set -- --libs --cflags openssl
+ ((  1 > 0  ))
+ PKG_CONFIG_PATH=/nix/store/gwxchbsz56q1qjqn9scqm881a2j83m1p-python3-3.10.13-env/lib/pkgconfig:/nix/store/7nbh3b6hhjqjs3nfy529g38l85iv46i9-openssl-3.0.11-dev/lib/pkgconfig:/nix/store/hq9gk0b60w877fbmqhq95xv5kxz3p3mp-protobuf-3.21.12/lib/pkgconfig:/nix/store/my1yzawmz5d1rvr76f3ryrqhlwjrh0d2-fontconfig-2.14.0-dev/lib/pkgconfig:/nix/store/xxfh7wqjkwr3mgl2a8ym9y7hvxywa32m-freetype-2.13.0-dev/lib/pkgconfig:/nix/store/j0zwp9zygvadcly9dxpm0f4ga7h0n8c9-zlib-1.2.13-dev/lib/pkgconfig:/nix/store/32lspl6qhmsm53l5n4wpgcdfzcjn6br4-bzip2-1.0.8-dev/lib/pkgconfig:/nix/store/pndmab9dmyjy2l39hyvhk90zrbhnm100-brotli-1.0.9-dev/lib/pkgconfig:/nix/store/86cvg8vkqkjls6cic26nb5rjjdjcjga3-libpng-apng-1.6.39-dev/lib/pkgconfig
+ exec /nix/store/s0spf4mcz9yr89d50kblds4agvqajp8x-pkg-config-0.29.2/bin/pkg-config --libs --cflags openssl
-I/nix/store/7nbh3b6hhjqjs3nfy529g38l85iv46i9-openssl-3.0.11-dev/include -L/nix/store/i57qjfacl3hv7sc1s1lj4z6fssh69nd3-openssl-3.0.11/lib -lssl -lcrypto

Oh, that is probably because the environment is very different:

NIX_PKG_CONFIG_WRAPPER_TARGET_TARGET_x86_64_unknown_linux_gnu=1
PKG_CONFIG_FOR_TARGET=pkg-config
PKG_CONFIG_PATH_FOR_TARGET=/nix/store/gwxchbsz56q1qjqn9scqm881a2j83m1p-python3-3.10.13-env/lib/pkgconfig:/nix/store/7nbh3b6hhjqjs3nfy529g38l85iv46i9-openssl-3.0.11-dev/lib/pkgconfig:/nix/store/hq9gk0b60w877fbmqhq95xv5kxz3p3mp-protobuf-3.21.12/lib/pkgconfig:/nix/store/my1yzawmz5d1rvr76f3ryrqhlwjrh0d2-fontconfig-2.14.0-dev/lib/pkgconfig:/nix/store/xxfh7wqjkwr3mgl2a8ym9y7hvxywa32m-freetype-2.13.0-dev/lib/pkgconfig:/nix/store/j0zwp9zygvadcly9dxpm0f4ga7h0n8c9-zlib-1.2.13-dev/lib/pkgconfig:/nix/store/32lspl6qhmsm53l5n4wpgcdfzcjn6br4-bzip2-1.0.8-dev/lib/pkgconfig:/nix/store/pndmab9dmyjy2l39hyvhk90zrbhnm100-brotli-1.0.9-dev/lib/pkgconfig:/nix/store/86cvg8vkqkjls6cic26nb5rjjdjcjga3-libpng-apng-1.6.39-dev/lib/pkgconfig

If I set PKG_CONFIG_PATH_FOR_TARGET to "$PKG_CONFIG_PATH" then I think this works.

enterShell = ''
  export PKG_CONFIG_PATH_FOR_TARGET="$PKG_CONFIG_PATH"
   "

Curiously, now I have to add gcc to the packages, but now it works.

Version

devenv version
devenv: 0.6.3

I also reproduced this with the latest main branch.

domenkozar commented 6 months ago

I believe this is fixed in #745

zoechi commented 4 months ago

I could make openssl work with

...
modules = [
  {
    env = {
              OPENSSL_LIB_DIR = "${nixpkgs.lib.getLib pkgs.openssl}/lib";
              OPENSSL_DIR = "${nixpkgs.lib.getDev pkgs.openssl}";
    };
    ...
]
...
domenkozar commented 3 weeks ago

This is fixed, please reopen if not.