ffmpeg: make version a regular parameter and use callPackage pattern

This is (to my knowledge) a novel pattern that is similar to how
callPackages (note the s) is used. Whereas callPackages would try to make the
arguments of default.nix overrideable, this instead exposes the individual
packages' arguments.

This pattern is a lot more robust than the custom import pattern I had
implemented here before.

It also moves the implementation detail out of all-packages which is great.

Making the version part of the interface allows overriders to declare a
different ABI. Doing so via overrideAttrs would not affect the flags in the
arguments; effectively retaining the overridden package's ABI.

See https://github.com/NixOS/nixpkgs/issues/280645 for an instance of that.

By overriding the arguments using

    ffmpeg.override { version = "..."; ... }

the ABI will now be overridden as expected.

This means you could theoretically turn ffmpeg_5-full into ffmpeg_4-headless by overriding it with

    {
      version = "4.4.4";
      hash = ...;
      ffmpegVariant = "headless";
    }

Having these implicit parameters be explicit parameters feels a lot cleaner and
neater to work with.
This commit is contained in:
Atemu 2024-03-13 19:15:21 +01:00
parent 883295650a
commit ec34e3d740
6 changed files with 83 additions and 70 deletions

View File

@ -1,5 +0,0 @@
import ./generic.nix {
version = "4.4.4";
hash = "sha256-Q8bkuF/1uJfqttJJoObnnLX3BEduv+qxsvOrVhMvRjA=";
extraPatches = [ ];
}

View File

@ -1,6 +0,0 @@
import ./generic.nix {
version = "5.1.4";
hash = "sha256-2jUL1/xGUf7aMooST2DW41KE7bC+BtgChXmj0sAJZ90=";
extraPatches = [
];
}

View File

@ -1,6 +0,0 @@
import ./generic.nix {
version = "6.1.1";
hash = "sha256-Q0c95hbCVUHQWPoh5uC8uzMylmB4BnWg+VhXEgSouzo=";
extraPatches = [
];
}

View File

@ -0,0 +1,58 @@
{ callPackage, darwin }:
let
mkFFmpeg =
initArgs: ffmpegVariant:
callPackage ./generic.nix (
{
inherit (darwin.apple_sdk.frameworks)
Cocoa
CoreServices
CoreAudio
CoreMedia
AVFoundation
MediaToolbox
VideoDecodeAcceleration
VideoToolbox
;
}
// (initArgs // { inherit ffmpegVariant; })
);
v4 = {
version = "4.4.4";
hash = "sha256-Q8bkuF/1uJfqttJJoObnnLX3BEduv+qxsvOrVhMvRjA=";
};
v5 = {
version = "5.1.4";
hash = "sha256-2jUL1/xGUf7aMooST2DW41KE7bC+BtgChXmj0sAJZ90=";
};
v6 = {
version = "6.1.1";
hash = "sha256-Q0c95hbCVUHQWPoh5uC8uzMylmB4BnWg+VhXEgSouzo=";
};
in
rec {
ffmpeg_4 = mkFFmpeg v4 "small";
ffmpeg_4-headless = mkFFmpeg v4 "headless";
ffmpeg_4-full = mkFFmpeg v4 "full";
ffmpeg_5 = mkFFmpeg v5 "small";
ffmpeg_5-headless = mkFFmpeg v5 "headless";
ffmpeg_5-full = mkFFmpeg v5 "full";
ffmpeg_6 = mkFFmpeg v6 "small";
ffmpeg_6-headless = mkFFmpeg v6 "headless";
ffmpeg_6-full = mkFFmpeg v6 "full";
# Please make sure this is updated to the latest version on the next major
# update to ffmpeg
# Packages which use ffmpeg as a library, should pin to the relevant major
# version number which the upstream support.
ffmpeg = ffmpeg_6;
ffmpeg-headless = ffmpeg_6-headless;
ffmpeg-full = ffmpeg_6-full;
}

View File

@ -1,7 +1,15 @@
{ version, hash, extraPatches ? [] }:
{ lib, stdenv, buildPackages, removeReferencesTo, addOpenGLRunpath, pkg-config, perl, texinfo, yasm
# You can fetch any upstream version using this derivation by specifying version and hash
# NOTICE: Always use this argument to override the version. Do not use overrideAttrs.
, version # ffmpeg ABI version. Also declare this if you're overriding the source.
, hash ? "" # hash of the upstream source for the given ABI version
, source ? fetchgit {
url = "https://git.ffmpeg.org/ffmpeg.git";
rev = "n${version}";
inherit hash;
}
, ffmpegVariant ? "small" # Decides which dependencies are enabled by default
# Build with headless deps; excludes dependencies that are only necessary for
@ -346,12 +354,7 @@ assert buildSwscale -> buildAvutil;
stdenv.mkDerivation (finalAttrs: {
pname = "ffmpeg" + (optionalString (ffmpegVariant != "small") "-${ffmpegVariant}");
inherit version;
src = fetchgit {
url = "https://git.ffmpeg.org/ffmpeg.git";
rev = "n${finalAttrs.version}";
inherit hash;
};
src = source;
postPatch = ''
patchShebangs .
@ -362,7 +365,7 @@ stdenv.mkDerivation (finalAttrs: {
--replace /usr/local/lib/frei0r-1 ${frei0r}/lib/frei0r-1
'';
patches = map (patch: fetchpatch patch) (extraPatches
patches = map (patch: fetchpatch patch) ([ ]
++ optionals (versionOlder version "5") [
{
name = "libsvtav1-1.5.0-compat-compressed_ten_bit_format.patch";

View File

@ -20960,50 +20960,19 @@ with pkgs;
linbox = callPackage ../development/libraries/linbox { };
ffmpeg_4 = callPackage ../development/libraries/ffmpeg/4.nix {
inherit (darwin.apple_sdk.frameworks)
Cocoa CoreServices CoreAudio CoreMedia AVFoundation MediaToolbox
VideoDecodeAcceleration VideoToolbox;
};
ffmpeg_4-headless = ffmpeg_4.override {
ffmpegVariant = "headless";
};
ffmpeg_4-full = ffmpeg_4.override {
ffmpegVariant = "full";
};
ffmpeg_5 = callPackage ../development/libraries/ffmpeg/5.nix {
inherit (darwin.apple_sdk.frameworks)
Cocoa CoreServices CoreAudio CoreMedia AVFoundation MediaToolbox
VideoDecodeAcceleration VideoToolbox;
};
ffmpeg_5-headless = ffmpeg_5.override {
ffmpegVariant = "headless";
};
ffmpeg_5-full = ffmpeg_5.override {
ffmpegVariant = "full";
};
ffmpeg_6 = callPackage ../development/libraries/ffmpeg/6.nix {
inherit (darwin.apple_sdk.frameworks)
Cocoa CoreServices CoreAudio CoreMedia AVFoundation MediaToolbox
VideoDecodeAcceleration VideoToolbox;
};
ffmpeg_6-headless = ffmpeg_6.override {
ffmpegVariant = "headless";
};
ffmpeg_6-full = ffmpeg_6.override {
ffmpegVariant = "full";
};
# Aliases
# Please make sure this is updated to the latest version on the next major
# update to ffmpeg
# Packages which use ffmpeg as a library, should pin to the relevant major
# version number which the upstream support.
ffmpeg = ffmpeg_6;
ffmpeg-headless = ffmpeg_6-headless;
ffmpeg-full = ffmpeg_6-full;
inherit (callPackage ../development/libraries/ffmpeg { })
ffmpeg_4
ffmpeg_4-headless
ffmpeg_4-full
ffmpeg_5
ffmpeg_5-headless
ffmpeg_5-full
ffmpeg_6
ffmpeg_6-headless
ffmpeg_6-full
ffmpeg
ffmpeg-headless
ffmpeg-full;
ffmpegthumbnailer = callPackage ../development/libraries/ffmpegthumbnailer { };