如何获取更新的 Nixpkgs stdenv 版本来为 'libav' 设置 NIX_CFLAGS/NIX_LDFLAGS?

How to get newer Nixpkgs stdenv versions to set the NIX_CFLAGS/NIX_LDFLAGS for 'libav'?

较新的 Nixpkgs 版本的 stdenv 无法为包 libav 设置 NIX_CFLAGS/NIX_LDFLAGS,这在旧版本中有效。 我在做什么wong?

以下脚本说明了这个问题。 它使用不同版本的 stdenv 使用 buildInputs = [ libav ]; 运行多个构建,并打印 NIX_LDFLAGSNIX_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

输出:

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=

解决方案是将gcc添加到buildInputs或使用runCommandCC代替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