Nix 包:在编译时将构建标志 --extra-cflags 传递给 ffmpeg

问题描述 投票:0回答:1

我对 Nix 和 NixOS 有点缺乏经验,并且在这个 ffmpeg 源代码构建方面遇到了一些困难。任何建议表示赞赏!

目标

使用

--extra-cflags="-pipe -O3 -march=znver3 -ffat-lto-objects"
从源代码构建ffmpeg,理想情况下使用薄片或覆盖层或类似的东西,以便我可以构建现有的ffmpeg nix包,甚至可以重现构建。

尝试

我一直在尝试遵循我在网上看到的不同建议,但是看看nixpkgs中的ffmpeg,我不确定我可以修补或覆盖什么。由于

configureFlags
发生在
stdenv.mkderivation
块内,当我尝试覆盖它时,它似乎没有此变量的范围(并且由于推导显式设置了
onfigurePlatforms = [];
,我不确定是否除非我尝试覆盖整个长推导,否则会破坏覆盖更改)。

查看 ffmpeg 配置脚本,似乎环境变量 cflags / cxxflags 不会受到尊重,但它会从

--extra-cflags
参数中获取它们,但我可能会遗漏一些东西。

剥落尝试

这是一个示例

flake.nix
我从我在 this github repo

看到的示例中分叉出来
{
  description = "A full build of ffmpeg, including the proprietary stuff";

  inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
  inputs.flake-utils.url = "github:numtide/flake-utils";

  outputs = { self, nixpkgs, flake-utils }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = import nixpkgs {
          inherit system;
          config.allowUnfree = true;
        };

        overrides = {
          ffmpeg = pkgs.ffmpeg-full;
          # If this did work, I'm not sure how it would combine with the derivation in the existing package, e.g. if it would get overridden
          configureFlags = [ "--extra-cflags -march=znver3 -O3 -pipe -ffat-lto-objects" ];
          withHeadlessDeps = true;
          nonfreeLicensing = true;
          # more options here once things are working above
        };
      in
      rec {
        packages.ffmpeg-custom = pkgs.ffmpeg-full.override overrides;
        defaultPackage = packages.ffmpeg-custom;
      }
    );
}

使用

nix profile install
构建时,遇到错误:

       error: function 'anonymous lambda' called with unexpected argument 'configureFlags'

       at /nix/store/d9wpzgyjlpw1424kw2lyilah6690fnk3-source/pkgs/development/libraries/ffmpeg-full/default.nix:1:1:

            1| { lib, stdenv, buildPackages, ffmpeg, addOpenGLRunpath, pkg-config, perl, texinfo, yasm
             | ^
            2| /*

大概是因为configureFlags是在原始包的派生中定义的。

configuration.nix 尝试中的覆盖

我尝试将其添加到我的 /etc/nixos/configuration.nix 中也没有成功:

nixpkgs.overlays = [
  (self: super: {
    ffmpeg-full = super.ffmpeg-full.override {
      configureFlags = [
        "--enable-hardcoded-tables"
        "--extra-cflags -march=znver3 -O3 -pipe -ffat-lto-objects"
      ] ++ super.ffmpeg-full.configureFlags;
    };
  })
];

使用

nixos-rebuild switch
构建时,我得到同样的错误:

       error: function 'anonymous lambda' called with unexpected argument 'configureFlags'

       at /nix/store/amxbqlhq11xfrbs4vdsyi04fap0abx0v-nixos-23.11/nixos/pkgs/development/libraries/ffmpeg/generic.nix:3:1:

            2|
            3| { lib, stdenv, buildPackages, removeReferencesTo, addOpenGLRunpath, pkg-config, perl, texinfo, yasm
             | ^
            4|

背景

我有一台 NixOS 机器,几乎一直在进行长时间运行的 ffmpeg 编码。我希望用更积极的 cflags 和一些额外的选项来重建无头 ffmpeg。我希望对不同版本之间的性能差异进行基准测试。

我可能会以此为借口来构建带有一些额外的非自由依赖项的 ffmpeg。

ffmpeg nix nixos
1个回答
0
投票

我在 NixOS 论坛的帮助下修复了它这里

使用

overrideAttrs
有助于解决范围问题。然后我遇到了一个问题,
--extra-cflags
值中的空格解析得很糟糕;通过将其设置为
preConfigure
解决了这个问题,如下所示。

# /etc/nixos/configuration.nix

nixpkgs.overlays = [
  (self: super: {
    ffmpeg-headless = super.ffmpeg-headless.overrideAttrs (old: {
      preConfigure = ''
        configureFlagsArray+=(
          "--extra-cflags=-O3 -pipe -march=znver3 -ffat-lto-objects -frecord-gcc-switches"
        )
      '';
      configureFlags = old.configureFlags;
    });
  })
];
© www.soinside.com 2019 - 2024. All rights reserved.