The stdenv of newer Nixpkgs versions fails to set the NIX_CFLAGS/NIX_LDFLAGS for the package libav
, which has worked in older versions.
What am I doing wong?
The following script illustrates the problem.
It runs several builds with buildInputs = [ libav ];
using different versions of the stdenv and prints the respective values of NIX_LDFLAGS
and NIX_CFLAGS_COMPILE
:
# Eval in shell
nix-build --no-out-link - <<'EOF'
let
pkgs = (import <nixpkgs> {});
fetchNixPkgs = { rev, sha256 }:
pkgs.fetchFromGitHub rec {
inherit sha256 rev;
owner = "NixOS";
repo = "nixpkgs-channels";
name = "adhoc-nixpkgs";
};
loadNixPkgs = args: import (fetchNixPkgs args) {};
pkgsVersions = {
# Aug 21, 2016
# This one works correctly: CFLAGS/LDFLAGS includes references to libav
working = loadNixPkgs {
rev = "5120af001f2bb163b58c41c84b11a0c136a207fe";
sha256 = "18h0aww5m17fip90zld8yqbz9f76ax5ws13krqgrccghn9i9hjlj";
};
# Jul 5, 2017
# The latest version: libav isn't included in CFLAGS/LDFLAGS
# This issue is also present in older versions
current = loadNixPkgs {
rev = "c2e3f7b687660fed7e0056ef1300a2efdfca6e4e";
sha256 = "0yp34xr8nkagn75d5sc0igynipvvr3mjcmz52scqd9isd7nmmfjs";
};
# Nov 11, 2016. An older version with the same issue
older = loadNixPkgs {
rev = "cf57b79fb1b4d1c261a1b27eaed75aefe99bd498";
sha256 = "1m5yjfnjckl8qjz2kxjj7zy074jdmn4r1csqgmf65024hlhqdz8r";
};
};
libav = pkgsVersions.current.libav.dev;
# libav = pkgsVersions.working.libav; # This one works, too
showEnv = pkgsVersion:
let
pkgs = pkgsVersions.${pkgsVersion};
in
pkgs.runCommand "test-env" { inherit pkgsVersion; buildInputs = [ libav ]; } ''
mkdir -p $out
echo
echo "============ Build environment for pkgs version '$pkgsVersion' ============"
echo NIX_LDFLAGS=$NIX_LDFLAGS
echo NIX_CFLAGS_COMPILE=$NIX_CFLAGS_COMPILE
echo
'';
in
map showEnv (builtins.attrNames pkgsVersions)
EOF
Output:
building path(s) ‘/nix/store/32jvx9cqafs54jcd0fbcdq6y93wyg8nm-test-env’
(Commentary: That's how it should look like)
↓
============ Build environment for pkgs version 'working' ============
NIX_LDFLAGS=-rpath /nix/store/32jvx9cqafs54jcd0fbcdq6y93wyg8nm-test-env/lib64 -rpath /nix/store/32jvx9cqafs54jcd0fbcdq6y93wyg8nm-test-env/lib -L/nix/store/b4viv3w9hzshp1i6zld219s3aszqdb4n-libav-11.9-dev/lib -L/nix/store/9li7l66zhd6lwhh34vbkx7zydk9cw3sz-libav-11.9/lib
NIX_CFLAGS_COMPILE= -isystem /nix/store/b4viv3w9hzshp1i6zld219s3aszqdb4n-libav-11.9-dev/include
building path(s) ‘/nix/store/j75z46xvfcl9512pi1rmahmslmlzk4ks-test-env’
============ Build environment for pkgs version 'current' ============
NIX_LDFLAGS=-rpath /nix/store/j75z46xvfcl9512pi1rmahmslmlzk4ks-test-env/lib64 -rpath /nix/store/j75z46xvfcl9512pi1rmahmslmlzk4ks-test-env/lib
NIX_CFLAGS_COMPILE=
building path(s) ‘/nix/store/1gic4s1jdv36pjkn5akrn98y215ll2al-test-env’
============ Build environment for pkgs version 'older' ============
NIX_LDFLAGS=-rpath /nix/store/1gic4s1jdv36pjkn5akrn98y215ll2al-test-env/lib64 -rpath /nix/store/1gic4s1jdv36pjkn5akrn98y215ll2al-test-env/lib
NIX_CFLAGS_COMPILE=
The solution is to add gcc
to buildInputs
or to use runCommandCC
instead of runCommand
:
nix-build --no-out-link - <<'EOF'
with (import <nixpkgs> {});
runCommand "test-env" { buildInputs = [ gcc libav ]; } ''
mkdir -p $out
echo NIX_LDFLAGS=$NIX_LDFLAGS
echo NIX_CFLAGS_COMPILE=$NIX_CFLAGS_COMPILE
''
EOF