gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 03:11:30 25 4
gpt4 key购买 nike

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

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

关于nix - 如何获取更新的 Nixpkgs stdenv 版本来为 'libav' 设置 NIX_CFLAGS/NIX_LDFLAGS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44931579/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com