diff --git a/pkgs/applications/terminal-emulators/mlterm/default.nix b/pkgs/applications/terminal-emulators/mlterm/default.nix index 28f027401bd74..7961437dcdcad 100644 --- a/pkgs/applications/terminal-emulators/mlterm/default.nix +++ b/pkgs/applications/terminal-emulators/mlterm/default.nix @@ -20,71 +20,13 @@ , gtk ? gtk3 # List of gui libraries to use. According to `./configure --help` ran on # release 3.9.3, options are: (xlib|win32|fb|quartz|console|wayland|sdl2|beos) -, enableGuis ? { - xlib = enableX11; - # From some reason, upstream's ./configure script disables compilation of the - # external tool `mlconfig` if `enableGuis.fb == true`. This behavior is not - # documentd in `./configure --help`, and it is reported here: - # https://github.com/arakiken/mlterm/issues/73 - fb = false; - quartz = stdenv.isDarwin; - wayland = stdenv.isLinux; - sdl2 = true; -} , libxkbcommon , wayland # for the "wayland" --with-gui option , SDL2 # for the "sdl" --with-gui option -# List of typing engines, the default list enables compiling all of the -# available ones, as recorded on release 3.9.3 -, enableTypeEngines ? { - xcore = false; # Considered legacy - xft = enableX11; - cairo = true; -} , libX11 , libXft , cairo -# List of external tools to create, this default list includes all default -# tools, as recorded on release 3.9.3. -, enableTools ? { - mlclient = true; - mlconfig = true; - mlcc = true; - mlterm-menu = true; - # Note that according to upstream's ./configure script, to disable - # mlimgloader you have to disable _all_ tools. See: - # https://github.com/arakiken/mlterm/issues/69 - mlimgloader = true; - registobmp = true; - mlfc = true; -} -# Whether to enable the X window system -, enableX11 ? stdenv.isLinux -# Most of the input methods and other build features are enabled by default, -# the following attribute set can be used to disable some of them. It's parsed -# when we set `configureFlags`. If you find other configure Flags that require -# dependencies, it'd be nice to make that contribution here. -, enableFeatures ? { - uim = !stdenv.isDarwin; - ibus = !stdenv.isDarwin; - fcitx = !stdenv.isDarwin; - m17n = !stdenv.isDarwin; - ssh2 = true; - bidi = true; - # Open Type layout support, (substituting glyphs with opentype fonts) - otl = true; -} -# Configure the Exec directive in the generated .desktop file -, desktopBinary ? ( - if enableGuis.xlib then - "mlterm" - else if enableGuis.wayland then - "mlterm-wl" - else if enableGuis.sdl2 then - "mlterm-sdl2" - else - throw "mlterm: couldn't figure out what desktopBinary to use." - ) +, configuration ? { } }: let @@ -96,6 +38,23 @@ let in lib.withFeatureAs (commaSepList != "") featureName commaSepList ; + eval = lib.evalModules { + modules = [ + ./options.nix + configuration + { + _module.args = { + inherit stdenv; + }; + } + ]; + }; + inherit (eval) config; + # For compat in order to not need to touch the entire drv + enableGuis = config.gui; + enableTypeEngines = config.typeEngines; + enableTools = config.tools; + enableFeatures = config.features; in stdenv.mkDerivation (finalAttrs: { pname = "mlterm"; version = "3.9.3"; @@ -173,7 +132,7 @@ in stdenv.mkDerivation (finalAttrs: { (withFeaturesList "type-engines" enableTypeEngines) (withFeaturesList "tools" enableTools) (withFeaturesList "gui" enableGuis) - (lib.withFeature enableX11 "x") + (lib.withFeature config.x11 "x") ] ++ lib.optionals (gtk != null) [ "--with-gtk=${lib.versions.major gtk.version}.0" ] ++ (lib.mapAttrsToList (n: v: lib.enableFeature v n) enableFeatures) ++ [ @@ -193,7 +152,7 @@ in stdenv.mkDerivation (finalAttrs: { desktopItem = makeDesktopItem { name = "mlterm"; - exec = "${desktopBinary} %U"; + exec = "${config.desktopBinary} %U"; icon = "mlterm"; type = "Application"; comment = "Multi Lingual TERMinal emulator"; diff --git a/pkgs/applications/terminal-emulators/mlterm/options.nix b/pkgs/applications/terminal-emulators/mlterm/options.nix new file mode 100644 index 0000000000000..ff6e3af12ba07 --- /dev/null +++ b/pkgs/applications/terminal-emulators/mlterm/options.nix @@ -0,0 +1,81 @@ +{ + lib, + config, + stdenv, + ... +}: + +let + # For prototyping. In reality you may want to declare options manually + quickConvert = lib.mapAttrs (n: v: lib.mkOption { default = v; }); +in + +{ + options = { + gui = { + xlib = lib.mkOption { default = config.x11; }; + # From some reason, upstream's ./configure script disables compilation of the + # external tool `mlconfig` if `config.gui.fb == true`. This behavior is not + # documentd in `./configure --help`, and it is reported here: + # https://github.com/arakiken/mlterm/issues/73 + fb = lib.mkOption { default = false; }; + quartz = lib.mkOption { default = stdenv.isDarwin; }; + wayland = lib.mkOption { default = stdenv.isLinux; }; + sdl2 = lib.mkOption { default = true; }; + }; + + # Whether to enable the X window system + x11 = lib.mkOption { default = stdenv.isLinux; }; + + typeEngines = { + # List of typing engines, the default list enables compiling all of the + # available ones, as recorded on release 3.9.3 + xcore = lib.mkOption { default = false; }; # Considered legacy + xft = lib.mkOption { default = config.x11; }; + cairo = lib.mkOption { default = true; }; + }; + + # Most of the input methods and other build features are enabled by default, + # the following attribute set can be used to disable some of them. It's parsed + # when we set `configureFlags`. If you find other configure Flags that require + # dependencies, it'd be nice to make that contribution here. + features = quickConvert { + uim = !stdenv.isDarwin; + ibus = !stdenv.isDarwin; + fcitx = !stdenv.isDarwin; + m17n = !stdenv.isDarwin; + ssh2 = true; + bidi = true; + # Open Type layout support, (substituting glyphs with opentype fonts) + otl = true; + }; + + # List of external tools to create, this default list includes all default + # tools, as recorded on release 3.9.3. + tools = quickConvert { + mlclient = true; + mlconfig = true; + mlcc = true; + mlterm-menu = true; + # Note that according to upstream's ./configure script, to disable + # mlimgloader you have to disable _all_ tools. See: + # https://github.com/arakiken/mlterm/issues/69 + mlimgloader = true; + registobmp = true; + mlfc = true; + }; + + desktopBinary = lib.mkOption { + default = + # Configure the Exec directive in the generated .desktop file + if config.gui.xlib then + "mlterm" + else if config.gui.wayland then + "mlterm-wl" + else if config.gui.sdl2 then + "mlterm-sdl2" + else + throw "mlterm: couldn't figure out what desktopBinary to use."; + }; + }; +} diff --git a/pkgs/development/libraries/ffmpeg/generic.nix b/pkgs/development/libraries/ffmpeg/generic.nix index 92a28d8a7705b..75a8c243f52ac 100644 --- a/pkgs/development/libraries/ffmpeg/generic.nix +++ b/pkgs/development/libraries/ffmpeg/generic.nix @@ -12,207 +12,10 @@ , ffmpegVariant ? "small" # Decides which dependencies are enabled by default - # Build with headless deps; excludes dependencies that are only necessary for - # GUI applications. To be used for purposes that don't generally need such - # components and i.e. only depend on libav -, withHeadlessDeps ? ffmpegVariant == "headless" || withSmallDeps - - # Dependencies a user might customarily expect from a regular ffmpeg build. - # /All/ packages that depend on ffmpeg and some of its feaures should depend - # on the small variant. Small means the minimal set of features that satisfies - # all dependants in Nixpkgs -, withSmallDeps ? ffmpegVariant == "small" || withFullDeps - - # Everything enabled; only guarded behind platform exclusivity or brokeness. - # If you need to depend on ffmpeg-full because ffmpeg is missing some feature - # your package needs, you should enable that feature in regular ffmpeg - # instead. -, withFullDeps ? ffmpegVariant == "full" - , fetchgit , fetchpatch2 - # Feature flags -, withAlsa ? withHeadlessDeps && stdenv.isLinux # Alsa in/output supporT -, withAom ? withFullDeps # AV1 reference encoder -, withAppKit ? withHeadlessDeps && stdenv.isDarwin # Apple AppKit framework -, withAribcaption ? withFullDeps && lib.versionAtLeast version "6.1" # ARIB STD-B24 Caption Decoder/Renderer -, withAss ? withHeadlessDeps && stdenv.hostPlatform == stdenv.buildPlatform # (Advanced) SubStation Alpha subtitle rendering -, withAudioToolbox ? withHeadlessDeps && stdenv.isDarwin # Apple AudioToolbox -, withAvFoundation ? withHeadlessDeps && stdenv.isDarwin # Apple AVFoundation framework -, withAvisynth ? withFullDeps # AviSynth script files reading -, withBluray ? withFullDeps # BluRay reading -, withBs2b ? withFullDeps # bs2b DSP library -, withBzlib ? withHeadlessDeps -, withCaca ? withFullDeps # Textual display (ASCII art) -, withCelt ? withFullDeps # CELT decoder -, withChromaprint ? withFullDeps # Audio fingerprinting -, withCodec2 ? withFullDeps # codec2 en/decoding -, withCoreImage ? withHeadlessDeps && stdenv.isDarwin # Apple CoreImage framework -, withCuda ? withFullDeps && withNvcodec -, withCudaLLVM ? withFullDeps -, withCuvid ? withHeadlessDeps && withNvcodec -, withDav1d ? withHeadlessDeps # AV1 decoder (focused on speed and correctness) -, withDc1394 ? withFullDeps && !stdenv.isDarwin # IIDC-1394 grabbing (ieee 1394) -, withDrm ? withHeadlessDeps && (with stdenv; isLinux || isFreeBSD) # libdrm support -, withDvdnav ? withFullDeps && withGPL && lib.versionAtLeast version "7" # needed for DVD demuxing -, withDvdread ? withFullDeps && withGPL && lib.versionAtLeast version "7" # needed for DVD demuxing -, withFdkAac ? withFullDeps && (!withGPL || withUnfree) # Fraunhofer FDK AAC de/encoder -, withNvcodec ? withHeadlessDeps && (with stdenv; !isDarwin && !isAarch32 && !hostPlatform.isRiscV && hostPlatform == buildPlatform) # dynamically linked Nvidia code -, withFlite ? withFullDeps # Voice Synthesis -, withFontconfig ? withHeadlessDeps # Needed for drawtext filter -, withFreetype ? withHeadlessDeps # Needed for drawtext filter -, withFrei0r ? withFullDeps && withGPL # frei0r video filtering -, withFribidi ? withFullDeps # Needed for drawtext filter -, withGme ? withFullDeps # Game Music Emulator -, withGnutls ? withHeadlessDeps -, withGsm ? withFullDeps # GSM de/encoder -, withHarfbuzz ? withHeadlessDeps && lib.versionAtLeast version "6.1" # Needed for drawtext filter -, withIconv ? withHeadlessDeps -, withJack ? withFullDeps && !stdenv.isDarwin # Jack audio -, withJxl ? withFullDeps && lib.versionAtLeast version "5" # JPEG XL de/encoding -, withLadspa ? withFullDeps # LADSPA audio filtering -, withLzma ? withHeadlessDeps # xz-utils -, withMfx ? withFullDeps && (with stdenv.hostPlatform; isLinux && !isAarch) # Hardware acceleration via intel-media-sdk/libmfx -, withModplug ? withFullDeps && !stdenv.isDarwin # ModPlug support -, withMp3lame ? withHeadlessDeps # LAME MP3 encoder -, withMysofa ? withFullDeps # HRTF support via SOFAlizer -, withNvdec ? withHeadlessDeps && withNvcodec -, withNvenc ? withHeadlessDeps && withNvcodec -, withOgg ? withHeadlessDeps # Ogg container used by vorbis & theora -, withOpenal ? withFullDeps # OpenAL 1.1 capture support -, withOpencl ? withFullDeps -, withOpencoreAmrnb ? withFullDeps && withVersion3 # AMR-NB de/encoder -, withOpencoreAmrwb ? withFullDeps && withVersion3 # AMR-WB decoder -, withOpengl ? withFullDeps && !stdenv.isDarwin # OpenGL rendering -, withOpenh264 ? withFullDeps # H.264/AVC encoder -, withOpenjpeg ? withFullDeps # JPEG 2000 de/encoder -, withOpenmpt ? withFullDeps # Tracked music files decoder -, withOpus ? withHeadlessDeps # Opus de/encoder -, withPlacebo ? withFullDeps && !stdenv.isDarwin # libplacebo video processing library -, withPulse ? withSmallDeps && stdenv.isLinux # Pulseaudio input support -, withQrencode ? withFullDeps && lib.versionAtLeast version "7" # QR encode generation -, withQuirc ? withFullDeps && lib.versionAtLeast version "7" # QR decoding -, withRav1e ? withFullDeps # AV1 encoder (focused on speed and safety) -, withRtmp ? withFullDeps # RTMP[E] support -, withSamba ? withFullDeps && !stdenv.isDarwin && withGPLv3 # Samba protocol -, withSdl2 ? withSmallDeps -, withShaderc ? withFullDeps && !stdenv.isDarwin && lib.versionAtLeast version "5.0" -, withSoxr ? withHeadlessDeps # Resampling via soxr -, withSpeex ? withHeadlessDeps # Speex de/encoder -, withSrt ? withHeadlessDeps # Secure Reliable Transport (SRT) protocol -, withSsh ? withHeadlessDeps # SFTP protocol -, withSvg ? withFullDeps # SVG protocol -, withSvtav1 ? withHeadlessDeps && !stdenv.isAarch64 && !stdenv.hostPlatform.isMinGW # AV1 encoder/decoder (focused on speed and correctness) -, withTensorflow ? false # Tensorflow dnn backend support (Increases closure size by ~390 MiB) -, withTheora ? withHeadlessDeps # Theora encoder -, withV4l2 ? withHeadlessDeps && stdenv.isLinux # Video 4 Linux support -, withV4l2M2m ? withV4l2 -, withVaapi ? withHeadlessDeps && (with stdenv; isLinux || isFreeBSD) # Vaapi hardware acceleration -, withVdpau ? withSmallDeps && !stdenv.hostPlatform.isMinGW # Vdpau hardware acceleration -, withVideoToolbox ? withHeadlessDeps && stdenv.isDarwin # Apple VideoToolbox -, withVidStab ? withFullDeps && withGPL # Video stabilization -, withVmaf ? withFullDeps && !stdenv.isAarch64 && lib.versionAtLeast version "5" # Netflix's VMAF (Video Multi-Method Assessment Fusion) -, withVoAmrwbenc ? withFullDeps && withVersion3 # AMR-WB encoder -, withVorbis ? withHeadlessDeps # Vorbis de/encoding, native encoder exists -, withVpl ? false # Hardware acceleration via intel libvpl -, withVpx ? withHeadlessDeps && stdenv.buildPlatform == stdenv.hostPlatform # VP8 & VP9 de/encoding -, withVulkan ? withSmallDeps && !stdenv.isDarwin -, withWebp ? withFullDeps # WebP encoder -, withX264 ? withHeadlessDeps && withGPL # H.264/AVC encoder -, withX265 ? withHeadlessDeps && withGPL # H.265/HEVC encoder -, withXavs ? withFullDeps && withGPL # AVS encoder -, withXcb ? withXcbShm || withXcbxfixes || withXcbShape # X11 grabbing using XCB -, withXcbShape ? withFullDeps # X11 grabbing shape rendering -, withXcbShm ? withFullDeps # X11 grabbing shm communication -, withXcbxfixes ? withFullDeps # X11 grabbing mouse rendering -, withXevd ? withFullDeps && lib.versionAtLeast version "7" && stdenv.hostPlatform.isx86 # MPEG-5 EVC decoding -, withXeve ? withFullDeps && lib.versionAtLeast version "7" && stdenv.hostPlatform.isx86 # MPEG-5 EVC encoding -, withXlib ? withFullDeps # Xlib support -, withXml2 ? withFullDeps # libxml2 support, for IMF and DASH demuxers -, withXvid ? withHeadlessDeps && withGPL # Xvid encoder, native encoder exists -, withZimg ? withHeadlessDeps -, withZlib ? withHeadlessDeps -, withZmq ? withFullDeps # Message passing - -/* - * Licensing options (yes some are listed twice, filters and such are not listed) - */ -, withGPL ? true -, withVersion3 ? true # When withGPL is set this implies GPLv3 otherwise it is LGPLv3 -, withGPLv3 ? withGPL && withVersion3 -, withUnfree ? false - -/* - * Build options - */ -, withSmallBuild ? false # Optimize for size instead of speed -, withRuntimeCPUDetection ? true # Detect CPU capabilities at runtime (disable to compile natively) -, withGrayscale ? withFullDeps # Full grayscale support -, withSwscaleAlpha ? buildSwscale # Alpha channel support in swscale. You probably want this when buildSwscale. -, withHardcodedTables ? withHeadlessDeps # Hardcode decode tables instead of runtime generation -, withSafeBitstreamReader ? withHeadlessDeps # Buffer boundary checking in bitreaders -, withMultithread ? true # Multithreading via pthreads/win32 threads -, withNetwork ? withHeadlessDeps # Network support -, withPixelutils ? withHeadlessDeps # Pixel utils in libavutil -, withStatic ? stdenv.hostPlatform.isStatic -, withShared ? !stdenv.hostPlatform.isStatic -, withPic ? true -, withThumb ? false # On some ARM platforms - -/* - * Program options - */ -, buildFfmpeg ? withHeadlessDeps # Build ffmpeg executable -, buildFfplay ? withSmallDeps # Build ffplay executable -, buildFfprobe ? withHeadlessDeps # Build ffprobe executable -, buildQtFaststart ? withFullDeps # Build qt-faststart executable -, withBin ? buildFfmpeg || buildFfplay || buildFfprobe || buildQtFaststart -/* - * Library options - */ -, buildAvcodec ? withHeadlessDeps # Build avcodec library -, buildAvdevice ? withHeadlessDeps # Build avdevice library -, buildAvfilter ? withHeadlessDeps # Build avfilter library -, buildAvformat ? withHeadlessDeps # Build avformat library -# Deprecated but depended upon by some packages. -# https://github.com/NixOS/nixpkgs/pull/211834#issuecomment-1417435991) -, buildAvresample ? withHeadlessDeps && lib.versionOlder version "5" # Build avresample library -, buildAvutil ? withHeadlessDeps # Build avutil library -, buildPostproc ? withHeadlessDeps # Build postproc library -, buildSwresample ? withHeadlessDeps # Build swresample library -, buildSwscale ? withHeadlessDeps # Build swscale library -, withLib ? buildAvcodec - || buildAvdevice - || buildAvfilter - || buildAvformat - || buildAvutil - || buildPostproc - || buildSwresample - || buildSwscale -/* - * Documentation options - */ -, withDocumentation ? withHtmlDoc || withManPages || withPodDoc || withTxtDoc -, withHtmlDoc ? withHeadlessDeps # HTML documentation pages -, withManPages ? withHeadlessDeps # Man documentation pages -, withPodDoc ? withHeadlessDeps # POD documentation pages -, withTxtDoc ? withHeadlessDeps # Text documentation pages -# Whether a "doc" output will be produced. Note that withManPages does not produce -# a "doc" output because its files go to "man". -, withDoc ? withDocumentation && (withHtmlDoc || withPodDoc || withTxtDoc) - -/* - * Developer options - */ -, withDebug ? false -, withOptimisations ? true -, withExtraWarnings ? false -, withStripping ? false - -/* - * External libraries options - */ + # Feature inputs , alsa-lib , avisynthplus , bzip2 @@ -321,6 +124,8 @@ * Testing */ , testers + +, configuration ? { } }: /* Maintainer notes: @@ -337,49 +142,845 @@ */ let - inherit (lib) optional optionals optionalString enableFeature versionOlder versionAtLeast; + inherit (lib) optional optionals optionalString versionOlder versionAtLeast; + variants = lib.genAttrs [ "headless" "small" "full" ] lib.id; + inherit (variants) headless small full; + + module = + { + config, + ... + }: + + let + # Checks whether the given variant of the flag is contained in the currently + # active variant. full ⊃ small ⊃ headless + isInVariant = flagVariant: + let + checks = { + full = ffmpegVariant == variants.full; + small = ffmpegVariant == variants.small || checks.full; + headless = ffmpegVariant == variants.headless || checks.small; + }; + in checks.${flagVariant} or false; + + # Represents a feature flag for ffmpeg. Each feature flag controls which + # packages should be added to buildInputs and which configureFlags should + # be set to enable the feature. It also offers easy controls to + # enable/disable features by default depending on the variant, version and + # custom logic. + ffmpegFlag = default: lib.types.submodule ({ config, name, ... }: { + options = { + enable = lib.mkEnableOption "Whether to enable ${name} support in ffmpeg" // lib.mkOption { + default = isInVariant config.variant && config.gate; + }; + packages = lib.mkOption { + type = with lib.types; attrsOf package; + default = { }; + description = "The dependencies required to enable ${name} support."; + }; + version = lib.mkOption { + type = lib.types.str; + default = "0"; # Unknown/Enable in any version + description = "Minimum version that understands this flag. Flag will not be passed when lower."; + }; + versionMax = lib.mkOption { + type = lib.types.str; + default = "99999999"; # Unknown/Enable in any version + description = "Maximum version that understands this flag. Flag will not be passed when higher."; + }; + variant = lib.mkOption { + type = lib.types.enum [ "headless" "small" "full" ]; + default = "headless"; + description = '' + Which variant this feature should be enabled in. + + Headless: Build with dependency set that is necessary for headless + operation; excludes dependencies that are only necessary for GUI + applications. Intended for purposes that don't generally need such + components and i.e. only depend on libav and for bootstrapping. + + Small: Dependencies a user might customarily expect from a regular + ffmpeg build. /All/ packages that depend on ffmpeg and some of its + feaures should depend on the small variant. Small means the minimal + set of features that satisfies all dependants in Nixpkgs + + Full: All dependencies enabled; only guarded behind platform + exclusivity, brokeness or extreme closure sizes that make more sense + in a specific ffmpeg variant. If you need to depend on ffmpeg-full + because ffmpeg is missing some feature your package needs, you should + enable that feature in regular ffmpeg instead. + ''; + }; + + gate = lib.mkOption { + default = true; + description = '' + Gates the default value for {option}`enable` behind a boolean. Use + this to disable certain features on certain platforms by default. + ''; + }; + + flags = lib.mkOption { + type = with lib.types; listOf str; + default = lib.optionals (!config.internal) [ (config.flagPrefix + name) ]; + description = '' + Flags to be passed to the configure script for this feature. + ''; + }; + + flagPrefix = lib.mkOption { + default = ""; + example = "lib"; + description = '' + Which prefix the configure enable flag has. Frequently `lib`. + ''; + }; + + description = lib.mkOption { + type = with lib.types; nullOr str; + default = null; + readOnly = true; + internal = true; + }; + + internal = lib.mkEnableOption "" // lib.mkOption { + description = '' + Whether this flag is an internal ffmpeg derivation implementation + detail and does not have a corresponding upstream configureFlag. + ''; + }; + }; + + # Default is passed as the submodule's config in order to merge with + # user-supplied values rather than being overridden entirely. + # https://github.com/NixOS/nixpkgs/pull/312432#discussion_r1759740858 + config = default; + }); + + mkFfmpegOption = name: default: lib.mkOption { + type = ffmpegFlag default; + default = { }; + description = + let + hasDescription = default.description or null != null; + additionalDescription = lib.optionalString hasDescription ": ${default.description}"; + in + "Control `${name}` support in ffmpeg${additionalDescription}."; + }; + + # This is the source of truth for the default set of features activated in ffmpeg + featureOptions = config: + let + enable = lib.mapAttrs (n: v: v.enable) config; + in + { + # Licensing flags + gpl = { }; + version3 = { + description = "When {option}`gpl` is set this implies {option}`gplv3`. Otherwise the license is LGPLv3"; + }; + gplv3 = { + gate = enable.gpl && enable.version3; + internal = true; + }; + unfree = { + gate = false; + flags = [ "nonfree" ]; + }; + # Build flags + static = { gate = stdenv.hostPlatform.isStatic; }; + shared = { gate = !stdenv.hostPlatform.isStatic; }; + pic = { }; + thumb = { gate = false; }; + small = { gate = false; }; + runtime-cpudetect = { }; + gray = { variant = full; }; + swscale-alpha = { }; # TODO same as swscale? + hardcoded-tables = { }; + safe-bitstream-reader = { }; + + small = { }; + runtime-cpudetect = { }; + gray = { }; + swscale-alpha = { }; + hardcoded-tables = { }; + safe-bitstream-reader = { }; + + multithread = { internal = true; }; + pthreads = { + gate = enable.multithread && stdenv.hostPlatform.isUnix; + }; + w32threads = { + gate = enable.multithread && stdenv.hostPlatform.isWindows; + }; + os2threads = { + # We don't support OS/2 + gate = false; + }; + + network = { }; + pixelutils = { + description = "Pixel utils in libavutil"; + }; + + # Program flags + ffmpeg = { + description = "Build ffmpeg executable"; + }; + ffplay = { + variant = small; + description = "Build ffplay executable"; + }; + ffprobe = { + description = "Build ffprobe executable"; + }; + qt-faststart = { + variant = full; + description = "Build qt-faststart executable"; + internal = true; # Does not have a flag, needs its dir to be passed to make manually + }; + bin-output = { + gate = with enable; ffmpeg || ffplay || ffprobe || qt-faststart; + internal = true; + }; + + # Library flags + avcodec = { }; + avdevice = { }; + avfilter = { }; + avformat = { }; + # Deprecated but depended upon by some packages. + # https://github.com/NixOS/nixpkgs/pull/211834#issuecomment-1417435991 + avresample = { + # Ffmpeg > 4 doesn't know about the flag anymore + versionMax = "5"; + }; + lib-output = { + gate = + with enable; + avcodec || avdevice || avfilter || avformat || avutil || postproc || swresample || swscale; + internal = true; + }; + + avutil = { }; + postproc = { gate = enable.gpl; }; + swresample = { }; + swscale = { }; + + # Documentation flags + doc = { + gate = with enable; htmlpages || manpages || podpages || txtpages; + }; + htmlpages = { }; + manpages = { }; + podpages = { }; + txtpages = { }; + doc-output = { + gate = with enable; doc && (htmlpages || podpages || txtpages); + description = '' + Whether a "doc" output will be produced. Note that + {option}`manpages` does not produce a "doc" output because its + files go to "man". + ''; + internal = true; + }; + + # Developer flags + debug = { gate = false; }; + optimizations = { }; + extra-warnings = { gate = false; }; + stripping = { gate = false; }; + + # Feature flags + alsa = { + gate = stdenv.isLinux; + packages = { inherit alsa-lib; }; + }; + aom = { + variant = full; + packages = { inherit libaom; }; + flagPrefix = "lib"; + description = "AV1 reference encoder"; + }; + appkit = { + gate = stdenv.isDarwin; + packages = { inherit AppKit; }; + }; + aribcaption = { + variant = full; + packages = { inherit libaribcaption; }; + flagPrefix = "lib"; + description = "ARIB STD-B24 Caption Decoder/Renderer"; + }; + ass = { + gate = stdenv.hostPlatform == stdenv.buildPlatform; + packages = { inherit libass; }; + flagPrefix = "lib"; + description = "(Advanced) SubStation Alpha subtitle rendering"; + }; + audiotoolbox = { + gate = stdenv.isDarwin; + packages = { inherit AudioToolbox; }; + }; + avfoundation = { + gate = stdenv.isDarwin; + packages = { inherit AVFoundation; }; + }; + avisynth = { + variant = full; + packages = { inherit avisynthplus; }; + description = "AviSynth script processing"; + }; + bluray = { + variant = full; + packages = { inherit libbluray; }; + flagPrefix = "lib"; + }; + bs2b = { + variant = full; + packages = { inherit libbs2b; }; + flagPrefix = "lib"; + }; + bzlib = { packages = { inherit bzip2; }; }; + caca = { + variant = full; + packages = { inherit libcaca; }; + flagPrefix = "lib"; + description = "Textual display (ASCII art)"; + }; + celt = { + variant = full; + packages = { inherit celt; }; + flagPrefix = "lib"; + }; + chromaprint = { + variant = full; + packages = { inherit chromaprint; }; + description = "Audio fingerprinting"; + }; + codec2 = { + variant = full; + packages = { inherit codec2; }; + flagPrefix = "lib"; + }; + coreimage = { + gate = stdenv.isDarwin; + packages = { inherit CoreImage; }; + }; + cuda = { + inherit (config.nvcodec) gate; + variant = full; + }; + cuda-llvm = { + variant = full; + }; + cuvid = { + inherit (config.nvcodec) gate; + }; + dav1d = { + packages = { inherit dav1d; }; + flagPrefix = "lib"; + description = "AV1 decoder (focused on speed and correctness)"; + }; + dc1394 = { + gate = !stdenv.isDarwin; + variant = full; + packages = { inherit libdc1394 libraw1394; }; + flagPrefix = "lib"; + description = "IIDC-1394 grabbing (ieee 1394/Firewire)"; + }; + drm = { + gate = with stdenv; isLinux || isFreeBSD; + packages = { inherit libdrm; }; + flagPrefix = "lib"; + }; + dvdnav = { + gate = enable.gpl; + variant = full; + version = "7"; + packages = { inherit libdvdnav; }; + flagPrefix = "lib"; + description = "DVD demuxing"; + }; + dvdread = { + gate = enable.gpl; + variant = full; + version = "7"; + packages = { inherit libdvdread; }; + flagPrefix = "lib"; + description = "DVD demuxing"; + }; + fdk-aac = { + gate = with enable; !gpl || unfree; + variant = full; + packages = { inherit fdk_aac; }; + flagPrefix = "lib"; + description = "Fraunhofer FDK AAC de/encoder"; + }; + nvcodec = { + gate = with stdenv; !isDarwin && !isAarch32 && !hostPlatform.isRiscV && hostPlatform == buildPlatform; + packages = { + nv-codec-headers = + if lib.versionAtLeast version "6" + then nv-codec-headers-12 + else nv-codec-headers; + }; + flagPrefix = "ff"; + description = "Dynamically linked Nvidia code"; + }; + flite = { + variant = full; + packages = { inherit flite; }; + flagPrefix = "lib"; + description = "Voice synthesis"; + }; + fontconfig = { + packages = { inherit fontconfig; }; + flags = [ "fontconfig" "libfontconfig" ]; + description = "Font support for i.e. the drawtext filter"; + }; + freetype = { + packages = { inherit freetype; }; + flagPrefix = "lib"; + description = "Font support for i.e. the drawtext filter"; + }; + frei0r = { + gate = enable.gpl; + variant = full; + packages = { inherit frei0r; }; + description = "Frei0r video filtering"; + }; + fribidi = { + variant = full; + packages = { inherit fribidi; }; + flagPrefix = "lib"; + description = "Font support for i.e. the drawtext filter"; + }; + gme = { + variant = full; + packages = { inherit game-music-emu; }; + flagPrefix = "lib"; + description = "Game Music Emulator"; + }; + gnutls = { packages = { inherit gnutls; }; }; + gsm = { + variant = full; + packages = { inherit gsm; }; + flagPrefix = "lib"; + }; + harfbuzz = { + version = "6.1"; + packages = { inherit harfbuzz; }; + flagPrefix = "lib"; + description = "Font support for i.e. the drawtext filter"; + }; + iconv = { packages = { inherit libiconv; }; }; # On Linux this should be in libc, do we really need it? + jack = { + gate = !stdenv.isDarwin; + variant = full; + packages = { inherit libjack2; }; + flagPrefix = "lib"; + }; + jxl = { + variant = full; + version = "5"; + packages = { inherit libjxl; }; + flagPrefix = "lib"; + }; + ladspa = { + variant = full; + packages = { inherit ladspaH; }; + description = "LADSPA audio filtering"; + }; + lzma = { packages = { inherit xz; }; }; + mfx = { + gate = with stdenv.hostPlatform; isLinux && !isAarch; + variant = full; + packages = { inherit intel-media-sdk; }; + flagPrefix = "lib"; + description = "Hardware acceleration via intel-media-sdk/libmfx (incompatible with {option}`vpl`)"; + }; + modplug = { + gate = !stdenv.isDarwin; + variant = full; + packages = { inherit libmodplug; }; + flagPrefix = "lib"; + }; + mp3lame = { + packages = { inherit lame; }; + flagPrefix = "lib"; + }; + mysofa = { + variant = full; + packages = { inherit libmysofa; }; + flagPrefix = "lib"; + description = "HRTF support via SOFAlizer"; + }; + nvdec = { + inherit (config.nvcodec) gate; + }; + nvenc = { + inherit (config.nvcodec) gate; + }; + ogg = { + packages = { inherit libogg; }; + flags = [ ]; # There is no flag for OGG?! + description = "Ogg container used by vorbis & theora"; + }; + openal = { + variant = full; + packages = { inherit openal; }; + description = "OpenAL 1.1 capture support"; + }; + opencl = { + variant = full; + packages = { inherit ocl-icd opencl-headers; }; + }; + opencore-amr = { + gate = enable.gplv3; + variant = full; + packages = { inherit opencore-amr; }; + flags = [ "libopencore-amrnb" "libopencore-amrwb" ]; + }; + opengl = { + gate = !stdenv.isDarwin; + variant = full; + packages = { inherit libGL libGLU; }; + description = "OpenGL rendering"; + }; + openh264 = { + variant = full; + packages = { inherit openh264; }; + flagPrefix = "lib"; + }; + openjpeg = { + variant = full; + packages = { inherit openjpeg; }; + flagPrefix = "lib"; + }; + openmpt = { + variant = full; + packages = { inherit libopenmpt; }; + flagPrefix = "lib"; + description = "Tracked music files decoder"; + }; + opus = { + packages = { inherit libopus; }; + flagPrefix = "lib"; + }; + placebo = { + gate = !stdenv.isDarwin; + variant = full; + packages = { + inherit vulkan-headers; + libplacebo = + if lib.versionAtLeast version "6.1" + then libplacebo + else libplacebo_5; + }; + flagPrefix = "lib"; + description = "libplacebo video processing library"; + }; + pulse = { + gate = stdenv.isLinux; + variant = small; + packages = { inherit libpulseaudio; }; + flagPrefix = "lib"; + description = "Pulseaudio input support"; + }; + qrencode = { + variant = full; + version = "7"; + packages = { inherit qrencode; }; + flagPrefix = "lib"; + description = "QR encode generation"; + }; + quirc = { + variant = full; + version = "7"; + packages = { inherit quirc; }; + flagPrefix = "lib"; + description = "QR decoding"; + }; + rav1e = { + variant = full; + packages = { inherit rav1e; }; + flagPrefix = "lib"; + description = "AV1 encoder (focused on speed and safety)"; + }; + rtmp = { + variant = full; + packages = { inherit rtmpdump; }; + flagPrefix = "lib"; + }; + samba = { + variant = full; + packages = { inherit samba; }; + flags = [ "libsmbclient" ]; + }; + sdl2 = { + variant = small; + packages = { inherit SDL2; }; + }; + shaderc = { + gate = !stdenv.isDarwin; + variant = full; + version = "5"; + packages = { inherit shaderc; }; + flagPrefix = "lib"; + }; + soxr = { + packages = { inherit soxr; }; + flagPrefix = "lib"; + description = "Resampling via soxr"; + }; + speex = { + packages = { inherit speex; }; + flagPrefix = "lib"; + }; + srt = { + packages = { inherit srt; }; + flagPrefix = "lib"; + description = "Secure Reliable Transport (SRT) protocol"; + }; + ssh = { + packages = { inherit libssh; }; + flagPrefix = "lib"; + description = "SFTP protocol"; + }; + svg = { + variant = full; + packages = { inherit librsvg; }; + flags = [ "librsvg" ]; + }; + svtav1 = { + gate = !stdenv.isAarch64 && !stdenv.hostPlatform.isMinGW; + packages = { inherit svt-av1; }; + flagPrefix = "lib"; + description = "AV1 encoder/decoder (focused on speed and correctness)"; + }; + tensorflow = { + gate = false; # Increases closure size by ~390 MiB and is rather specialised purpose + packages = { inherit libtensorflow; }; + flagPrefix = "lib"; + description = "Tensorflow dnn backend support"; + }; + theora = { + packages = { inherit libtheora; }; + flagPrefix = "lib"; + }; + v4l2 = { + gate = stdenv.isLinux; + packages = { inherit libv4l; }; + flags = [ "libv4l2" "v4l2-m2m" ]; + description = "Video 4 Linux"; + }; + vaapi = { + gate = with stdenv; isLinux || isFreeBSD; + packages = { + libva = if ffmpegVariant == headless then libva-minimal else libva; + }; + description = "Vaapi hardware acceleration"; + }; + vdpau = { + gate = !stdenv.hostPlatform.isMinGW; + variant = small; + packages = { inherit libvdpau; }; + description = "Vdpau hardware acceleration"; + }; + videotoolbox = { + gate = stdenv.isDarwin; + packages = { inherit VideoToolbox; }; + }; + vidstab = { + gate = enable.gpl; + variant = full; + packages = { inherit vid-stab; }; + flagPrefix = "lib"; + description = "Video stabilization"; + }; + vmaf = { + gate = !stdenv.isAarch64; + variant = full; + version = "5"; + packages = { inherit libvmaf; }; + flagPrefix = "lib"; + description = "Netflix's VMAF (Video Multi-Method Assessment Fusion)"; + }; + vo-amrwbenc = { + gate = enable.gplv3; + variant = full; + packages = { inherit vo-amrwbenc; }; + flagPrefix = "lib"; + }; + vorbis = { + packages = { inherit libvorbis; }; + flagPrefix = "lib"; + description = "Vorbis de/encoding, native encoder exists"; # TODO shouldn't we be using it then? + }; + vpl = { + # It is currently unclear whether this breaks support for old GPUs. See + # https://github.com/NixOS/nixpkgs/issues/303074 + gate = false; + packages = { inherit libvpl; }; + flagPrefix = "lib"; + description = "Hardware acceleration via intel libvpl (incompatible with {option}`mfx`)"; + }; + vpx = { + gate = stdenv.buildPlatform == stdenv.hostPlatform; + packages = { inherit libvpx; }; + flagPrefix = "lib"; + description = "VP8 & VP9 de/encoding"; + }; + vulkan = { + gate = !stdenv.isDarwin; + variant = small; + packages = { inherit vulkan-headers vulkan-loader; }; }; + webp = { + variant = full; + packages = { inherit libwebp; }; + flagPrefix = "lib"; + }; + x264 = { + gate = enable.gpl; + packages = { inherit x264; }; + flagPrefix = "lib"; + }; + x265 = { + gate = enable.gpl; + packages = { inherit x265; }; + flagPrefix = "lib"; + }; + xavs = { + gate = enable.gpl; + variant = full; + packages = { inherit xavs; }; + flagPrefix = "lib"; + }; + xcb = { + gate = with enable; xcb-shape || xcb-shm || xcb-xfixes; + packages = { inherit libxcb; }; + flagPrefix = "lib"; + description = "X11 grabbing using XCB"; + }; + xcb-shape = { + variant = full; + flagPrefix = "lib"; + description = "X11 grabbing shape rendering"; + }; + xcb-shm = { + variant = full; + flagPrefix = "lib"; + description = "X11 grabbing shm communication"; + }; + xcb-xfixes = { + variant = full; + flagPrefix = "lib"; + description = "X11 grabbing mouse rendering"; + }; + xevd = { + gate = stdenv.hostPlatform.isx86; + variant = full; + version = "7"; + packages = { inherit xevd; }; + flagPrefix = "lib"; + description = "MPEG-5 EVC decoding"; + }; + xeve = { + gate = stdenv.hostPlatform.isx86; + variant = full; + version = "7"; + packages = { inherit xeve; }; + flagPrefix = "lib"; + description = "MPEG-5 EVC encoding"; + }; + xlib = { + variant = full; + packages = { inherit libX11 libXv libXext; }; + }; + xml2 = { + variant = full; + packages = { inherit libxml2; }; + flagPrefix = "lib"; + description = "libxml2 support, for IMF and DASH demuxers"; + }; + xvid = { + gate = enable.gpl; + packages = { inherit xvidcore; }; + flagPrefix = "lib"; + description = "Xvid encoder, native encoder exists"; # TODO shouldn't we be using it then? + }; + zimg = { + packages = { inherit zimg; }; + flagPrefix = "lib"; + }; + zlib = { packages = { inherit zlib; }; }; + zmq = { + variant = full; + packages = { inherit zeromq4; }; + flagPrefix = "lib"; + description = "Message passing"; + }; + }; + in + { + options = { + features = lib.mapAttrs mkFfmpegOption (featureOptions (config.features)); + }; + }; + + eval = lib.evalModules { + modules = [ + module + configuration + { + _module.args = { variant = ffmpegVariant; }; + } + ]; + }; + inherit (eval) config; + inherit (config) features; + enable = lib.mapAttrs (n: v: v.enable) features; + + # All library .so files that this ffmpeg exposes + exposedLibNames = lib.concatMap (name: lib.optional (builtins.getAttr name enable) "lib${name}") [ + "avcodec" + "avdevice" + "avfilter" + "avformat" + "avresample" + "avutil" + "postproc" + "swresample" + "swscale" + ]; in +# Assertions to help the user reach a sane config -assert lib.elem ffmpegVariant [ "headless" "small" "full" ]; +# General +assert builtins.hasAttr ffmpegVariant variants; # We must know the ffmpeg variant -/* - * Licensing dependencies - */ -assert withGPLv3 -> withGPL && withVersion3; +# Licensing dependencies +assert with enable; gplv3 -> gpl && version3; -/* - * Build dependencies - */ -assert withPixelutils -> buildAvutil; -assert !(withMfx && withVpl); # incompatible features -/* - * Program dependencies - */ -assert buildFfmpeg -> buildAvcodec - && buildAvfilter - && buildAvformat - && (buildSwresample || buildAvresample); -assert buildFfplay -> buildAvcodec - && buildAvformat - && buildSwscale - && (buildSwresample || buildAvresample); -assert buildFfprobe -> buildAvcodec && buildAvformat; -/* - * Library dependencies - */ -assert buildAvcodec -> buildAvutil; # configure flag since 0.6 -assert buildAvdevice -> buildAvformat - && buildAvcodec - && buildAvutil; # configure flag since 0.6 -assert buildAvformat -> buildAvcodec && buildAvutil; # configure flag since 0.6 -assert buildPostproc -> buildAvutil; -assert buildSwscale -> buildAvutil; +# Build dependencies +assert with enable; pixelutils -> avutil; +assert with enable; !(mfx && vpl); # incompatible features +# Program dependencies +assert with enable; ffmpeg -> avcodec && avfilter && avformat && (swresample || avresample); +assert with enable; ffplay -> avcodec && avformat && swscale && (swresample || avresample); +assert with enable; ffprobe -> avcodec && avformat; +# Library dependencies +assert with enable; avcodec -> avutil; # configure flag since 0.6 +assert with enable; avdevice -> avformat && avcodec && avutil; # configure flag since 0.6 +assert with enable; avformat -> avcodec && avutil; # configure flag since 0.6 +assert with enable; postproc -> avutil; +assert with enable; swscale -> avutil; -/* - * External Library dependencies - */ -assert (withCuda || withCuvid || withNvdec || withNvenc) -> withNvcodec; +# External Library dependencies +assert with enable; (cuda || cuvid || nvdec || nvenc) -> nvcodec; stdenv.mkDerivation (finalAttrs: { pname = "ffmpeg" + (optionalString (ffmpegVariant != "small") "-${ffmpegVariant}"); @@ -388,7 +989,7 @@ stdenv.mkDerivation (finalAttrs: { postPatch = '' patchShebangs . - '' + lib.optionalString withFrei0r '' + '' + lib.optionalString enable.frei0r '' substituteInPlace libavfilter/vf_frei0r.c \ --replace /usr/local/lib/frei0r-1 ${frei0r}/lib/frei0r-1 substituteInPlace doc/filters.texi \ @@ -456,214 +1057,28 @@ stdenv.mkDerivation (finalAttrs: { "--target_os=${if stdenv.hostPlatform.isMinGW then "mingw64" else stdenv.hostPlatform.parsed.kernel.name}" "--arch=${stdenv.hostPlatform.parsed.cpu.name}" "--pkg-config=${buildPackages.pkg-config.targetPrefix}pkg-config" - /* - * Licensing flags - */ - (enableFeature withGPL "gpl") - (enableFeature withVersion3 "version3") - (enableFeature withUnfree "nonfree") - /* - * Build flags - */ - (enableFeature withStatic "static") - (enableFeature withShared "shared") - (enableFeature withPic "pic") - (enableFeature withThumb "thumb") - - (enableFeature withSmallBuild "small") - (enableFeature withRuntimeCPUDetection "runtime-cpudetect") - (enableFeature withGrayscale "gray") - (enableFeature withSwscaleAlpha "swscale-alpha") - (enableFeature withHardcodedTables "hardcoded-tables") - (enableFeature withSafeBitstreamReader "safe-bitstream-reader") - - (enableFeature (withMultithread && stdenv.hostPlatform.isUnix) "pthreads") - (enableFeature (withMultithread && stdenv.hostPlatform.isWindows) "w32threads") - "--disable-os2threads" # We don't support OS/2 - - (enableFeature withNetwork "network") - (enableFeature withPixelutils "pixelutils") "--datadir=${placeholder "data"}/share/ffmpeg" - - /* - * Program flags - */ - (enableFeature buildFfmpeg "ffmpeg") - (enableFeature buildFfplay "ffplay") - (enableFeature buildFfprobe "ffprobe") - ] ++ optionals withBin [ + ] ++ optionals enable.bin-output [ "--bindir=${placeholder "bin"}/bin" - ] ++ [ - /* - * Library flags - */ - (enableFeature buildAvcodec "avcodec") - (enableFeature buildAvdevice "avdevice") - (enableFeature buildAvfilter "avfilter") - (enableFeature buildAvformat "avformat") - ] ++ optionals (lib.versionOlder version "5") [ - # Ffmpeg > 4 doesn't know about the flag anymore - (enableFeature buildAvresample "avresample") - ] ++ [ - (enableFeature buildAvutil "avutil") - (enableFeature (buildPostproc && withGPL) "postproc") - (enableFeature buildSwresample "swresample") - (enableFeature buildSwscale "swscale") - ] ++ optionals withLib [ + ] ++ optionals enable.lib-output [ "--libdir=${placeholder "lib"}/lib" "--incdir=${placeholder "dev"}/include" - ] ++ [ - /* - * Documentation flags - */ - (enableFeature withDocumentation "doc") - (enableFeature withHtmlDoc "htmlpages") - (enableFeature withManPages "manpages") - ] ++ optionals withManPages [ + ] ++ optionals enable.manpages [ "--mandir=${placeholder "man"}/share/man" - ] ++ [ - (enableFeature withPodDoc "podpages") - (enableFeature withTxtDoc "txtpages") - ] ++ optionals withDoc [ + ] ++ optionals enable.doc-output [ "--docdir=${placeholder "doc"}/share/doc/ffmpeg" - ] ++ [ - /* - * External libraries - */ - (enableFeature withAlsa "alsa") - (enableFeature withAom "libaom") - (enableFeature withAppKit "appkit") - ] ++ optionals (versionAtLeast version "6.1") [ - (enableFeature withAribcaption "libaribcaption") - ] ++ [ - (enableFeature withAss "libass") - (enableFeature withAudioToolbox "audiotoolbox") - (enableFeature withAvFoundation "avfoundation") - (enableFeature withAvisynth "avisynth") - (enableFeature withBluray "libbluray") - (enableFeature withBs2b "libbs2b") - (enableFeature withBzlib "bzlib") - (enableFeature withCaca "libcaca") - (enableFeature withCelt "libcelt") - (enableFeature withChromaprint "chromaprint") - (enableFeature withCodec2 "libcodec2") - (enableFeature withCoreImage "coreimage") - (enableFeature withCuda "cuda") - (enableFeature withCudaLLVM "cuda-llvm") - (enableFeature withCuvid "cuvid") - (enableFeature withDav1d "libdav1d") - (enableFeature withDc1394 "libdc1394") - (enableFeature withDrm "libdrm") - ] ++ optionals (versionAtLeast version "7") [ - (enableFeature withDvdnav "libdvdnav") - (enableFeature withDvdread "libdvdread") - ] ++ [ - (enableFeature withFdkAac "libfdk-aac") - (enableFeature withNvcodec "ffnvcodec") - (enableFeature withFlite "libflite") - (enableFeature withFontconfig "fontconfig") - (enableFeature withFontconfig "libfontconfig") - (enableFeature withFreetype "libfreetype") - (enableFeature withFrei0r "frei0r") - (enableFeature withFribidi "libfribidi") - (enableFeature withGme "libgme") - (enableFeature withGnutls "gnutls") - (enableFeature withGsm "libgsm") - ] ++ optionals (versionAtLeast version "6.1") [ - (enableFeature withHarfbuzz "libharfbuzz") - ] ++ [ - (enableFeature withIconv "iconv") - (enableFeature withJack "libjack") - ] ++ optionals (versionAtLeast finalAttrs.version "5.0") [ - (enableFeature withJxl "libjxl") - ] ++ [ - (enableFeature withLadspa "ladspa") - (enableFeature withLzma "lzma") - (enableFeature withMfx "libmfx") - (enableFeature withModplug "libmodplug") - (enableFeature withMp3lame "libmp3lame") - (enableFeature withMysofa "libmysofa") - (enableFeature withNvdec "nvdec") - (enableFeature withNvenc "nvenc") - (enableFeature withOpenal "openal") - (enableFeature withOpencl "opencl") - (enableFeature withOpencoreAmrnb "libopencore-amrnb") - (enableFeature withOpencoreAmrwb "libopencore-amrwb") - (enableFeature withOpengl "opengl") - (enableFeature withOpenh264 "libopenh264") - (enableFeature withOpenjpeg "libopenjpeg") - (enableFeature withOpenmpt "libopenmpt") - (enableFeature withOpus "libopus") - ] ++ optionals (versionAtLeast version "5.0") [ - (enableFeature withPlacebo "libplacebo") - ] ++ [ - (enableFeature withPulse "libpulse") - ] ++ optionals (versionAtLeast version "7") [ - (enableFeature withQrencode "libqrencode") - (enableFeature withQuirc "libquirc") - ] ++ [ - (enableFeature withRav1e "librav1e") - (enableFeature withRtmp "librtmp") - (enableFeature withSamba "libsmbclient") - (enableFeature withSdl2 "sdl2") - ] ++ optionals (versionAtLeast version "5.0") [ - (enableFeature withShaderc "libshaderc") - ] ++ [ - (enableFeature withSoxr "libsoxr") - (enableFeature withSpeex "libspeex") - (enableFeature withSrt "libsrt") - (enableFeature withSsh "libssh") - (enableFeature withSvg "librsvg") - (enableFeature withSvtav1 "libsvtav1") - (enableFeature withTensorflow "libtensorflow") - (enableFeature withTheora "libtheora") - (enableFeature withV4l2 "libv4l2") - (enableFeature withV4l2M2m "v4l2-m2m") - (enableFeature withVaapi "vaapi") - (enableFeature withVdpau "vdpau") - ] ++ optionals (versionAtLeast version "6.0") [ - (enableFeature withVpl "libvpl") - ] ++ [ - (enableFeature withVideoToolbox "videotoolbox") - (enableFeature withVidStab "libvidstab") # Actual min. version 2.0 - (enableFeature withVmaf "libvmaf") - (enableFeature withVoAmrwbenc "libvo-amrwbenc") - (enableFeature withVorbis "libvorbis") - (enableFeature withVpx "libvpx") - (enableFeature withVulkan "vulkan") - (enableFeature withWebp "libwebp") - (enableFeature withX264 "libx264") - (enableFeature withX265 "libx265") - (enableFeature withXavs "libxavs") - (enableFeature withXcb "libxcb") - (enableFeature withXcbShape "libxcb-shape") - (enableFeature withXcbShm "libxcb-shm") - (enableFeature withXcbxfixes "libxcb-xfixes") - ] ++ optionals (versionAtLeast version "7") [ - (enableFeature withXevd "libxevd") - (enableFeature withXeve "libxeve") - ] ++ [ - (enableFeature withXlib "xlib") - (enableFeature withXml2 "libxml2") - (enableFeature withXvid "libxvid") - (enableFeature withZimg "libzimg") - (enableFeature withZlib "zlib") - (enableFeature withZmq "libzmq") - /* - * Developer flags - */ - (enableFeature withDebug "debug") - (enableFeature withOptimisations "optimizations") - (enableFeature withExtraWarnings "extra-warnings") - (enableFeature withStripping "stripping") ] ++ optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ "--cross-prefix=${stdenv.cc.targetPrefix}" - "--enable-cross-compile" + "--enable-cross-compile" # TODO "--host-cc=${buildPackages.stdenv.cc}/bin/cc" ] ++ optionals stdenv.cc.isClang [ "--cc=clang" "--cxx=clang++" + ] ++ lib.pipe eval.config.features [ + (lib.filterAttrs (n: v: lib.versionAtLeast version v.version && lib.versionOlder version v.versionMax)) + (lib.mapAttrsToList (n: feature: (map (lib.enableFeature feature.enable) feature.flags))) + lib.flatten ]; # ffmpeg embeds the configureFlags verbatim in its binaries and because we @@ -679,152 +1094,54 @@ stdenv.mkDerivation (finalAttrs: { strictDeps = true; nativeBuildInputs = [ removeReferencesTo addOpenGLRunpath perl pkg-config texinfo yasm ] - ++ optionals withCudaLLVM [ clang ]; - - buildInputs = [] - ++ optionals withAlsa [ alsa-lib ] - ++ optionals withAom [ libaom ] - ++ optionals withAppKit [ AppKit ] - ++ optionals withAribcaption [ libaribcaption ] - ++ optionals withAss [ libass ] - ++ optionals withAudioToolbox [ AudioToolbox ] - ++ optionals withAvFoundation [ AVFoundation ] - ++ optionals withAvisynth [ avisynthplus ] - ++ optionals withBluray [ libbluray ] - ++ optionals withBs2b [ libbs2b ] - ++ optionals withBzlib [ bzip2 ] - ++ optionals withCaca [ libcaca ] - ++ optionals withCelt [ celt ] - ++ optionals withChromaprint [ chromaprint ] - ++ optionals withCodec2 [ codec2 ] - ++ optionals withCoreImage [ CoreImage ] - ++ optionals withDav1d [ dav1d ] - ++ optionals withDc1394 [ libdc1394 libraw1394 ] - ++ optionals withDrm [ libdrm ] - ++ optionals withDvdnav [ libdvdnav ] - ++ optionals withDvdread [ libdvdread ] - ++ optionals withFdkAac [ fdk_aac ] - ++ optionals withNvcodec [ (if (lib.versionAtLeast version "6") then nv-codec-headers-12 else nv-codec-headers) ] - ++ optionals withFlite [ flite ] - ++ optionals withFontconfig [ fontconfig ] - ++ optionals withFreetype [ freetype ] - ++ optionals withFrei0r [ frei0r ] - ++ optionals withFribidi [ fribidi ] - ++ optionals withGme [ game-music-emu ] - ++ optionals withGnutls [ gnutls ] - ++ optionals withGsm [ gsm ] - ++ optionals withHarfbuzz [ harfbuzz ] - ++ optionals withIconv [ libiconv ] # On Linux this should be in libc, do we really need it? - ++ optionals withJack [ libjack2 ] - ++ optionals withJxl [ libjxl ] - ++ optionals withLadspa [ ladspaH ] - ++ optionals withLzma [ xz ] - ++ optionals withMfx [ intel-media-sdk ] - ++ optionals withModplug [ libmodplug ] - ++ optionals withMp3lame [ lame ] - ++ optionals withMysofa [ libmysofa ] - ++ optionals withOgg [ libogg ] - ++ optionals withOpenal [ openal ] - ++ optionals withOpencl [ ocl-icd opencl-headers ] - ++ optionals (withOpencoreAmrnb || withOpencoreAmrwb) [ opencore-amr ] - ++ optionals withOpengl [ libGL libGLU ] - ++ optionals withOpenh264 [ openh264 ] - ++ optionals withOpenjpeg [ openjpeg ] - ++ optionals withOpenmpt [ libopenmpt ] - ++ optionals withOpus [ libopus ] - ++ optionals withPlacebo [ (if (lib.versionAtLeast version "6.1") then libplacebo else libplacebo_5) vulkan-headers ] - ++ optionals withPulse [ libpulseaudio ] - ++ optionals withQrencode [ qrencode ] - ++ optionals withQuirc [ quirc ] - ++ optionals withRav1e [ rav1e ] - ++ optionals withRtmp [ rtmpdump ] - ++ optionals withSamba [ samba ] - ++ optionals withSdl2 [ SDL2 ] - ++ optionals withShaderc [ shaderc ] - ++ optionals withSoxr [ soxr ] - ++ optionals withSpeex [ speex ] - ++ optionals withSrt [ srt ] - ++ optionals withSsh [ libssh ] - ++ optionals withSvg [ librsvg ] - ++ optionals withSvtav1 [ svt-av1 ] - ++ optionals withTensorflow [ libtensorflow ] - ++ optionals withTheora [ libtheora ] - ++ optionals withV4l2 [ libv4l ] - ++ optionals withVaapi [ (if withSmallDeps then libva else libva-minimal) ] - ++ optionals withVdpau [ libvdpau ] - ++ optionals withVideoToolbox [ VideoToolbox ] - ++ optionals withVidStab [ vid-stab ] - ++ optionals withVmaf [ libvmaf ] - ++ optionals withVoAmrwbenc [ vo-amrwbenc ] - ++ optionals withVorbis [ libvorbis ] - ++ optionals withVpl [ libvpl ] - ++ optionals withVpx [ libvpx ] - ++ optionals withVulkan [ vulkan-headers vulkan-loader ] - ++ optionals withWebp [ libwebp ] - ++ optionals withX264 [ x264 ] - ++ optionals withX265 [ x265 ] - ++ optionals withXavs [ xavs ] - ++ optionals withXcb [ libxcb ] - ++ optionals withXevd [ xevd ] - ++ optionals withXeve [ xeve ] - ++ optionals withXlib [ libX11 libXv libXext ] - ++ optionals withXml2 [ libxml2 ] - ++ optionals withXvid [ xvidcore ] - ++ optionals withZimg [ zimg ] - ++ optionals withZlib [ zlib ] - ++ optionals withZmq [ zeromq4 ] - ; + ++ optionals enable.cuda-llvm [ clang ]; + + buildInputs = lib.pipe eval.config.features [ + (lib.filterAttrs (n: v: v.enable && lib.versionAtLeast version v.version && lib.versionOlder version v.versionMax)) + (lib.mapAttrsToList (n: v: lib.attrValues v.packages)) + lib.flatten + ]; buildFlags = [ "all" ] - ++ optional buildQtFaststart "tools/qt-faststart"; # Build qt-faststart executable + ++ optional enable.qt-faststart "tools/qt-faststart"; # Build qt-faststart executable doCheck = stdenv.hostPlatform == stdenv.buildPlatform; # Fails with SIGABRT otherwise FIXME: Why? - checkPhase = let - ldLibraryPathEnv = if stdenv.isDarwin then "DYLD_LIBRARY_PATH" else "LD_LIBRARY_PATH"; - libsToLink = [ ] - ++ optional buildAvcodec "libavcodec" - ++ optional buildAvdevice "libavdevice" - ++ optional buildAvfilter "libavfilter" - ++ optional buildAvformat "libavformat" - ++ optional buildAvresample "libavresample" - ++ optional buildAvutil "libavutil" - ++ optional buildPostproc "libpostproc" - ++ optional buildSwresample "libswresample" - ++ optional buildSwscale "libswscale" - ; - in '' - ${ldLibraryPathEnv}="${lib.concatStringsSep ":" libsToLink}" make check -j$NIX_BUILD_CORES - ''; + checkFlags = + let + ldEnvVar = if stdenv.isDarwin then "DYLD_LIBRARY_PATH" else "LD_LIBRARY_PATH"; + in + "${ldEnvVar}=${lib.concatStringsSep ":" exposedLibNames}"; - outputs = optionals withBin [ "bin" ] # The first output is the one that gets symlinked by default! - ++ optionals withLib [ "lib" "dev" ] - ++ optionals withDoc [ "doc" ] - ++ optionals withManPages [ "man" ] + outputs = optionals enable.bin-output [ "bin" ] # The first output is the one that gets symlinked by default! + ++ optionals enable.lib-output [ "lib" "dev" ] + ++ optionals enable.doc-output [ "doc" ] + ++ optionals enable.manpages [ "man" ] ++ [ "data" "out" ] # We need an "out" output because we get an error otherwise. It's just an empty dir. ; - postInstall = optionalString buildQtFaststart '' + postInstall = optionalString enable.qt-faststart '' install -D tools/qt-faststart -t $bin/bin ''; # Set RUNPATH so that libnvcuvid and libcuda in /run/opengl-driver(-32)/lib can be found. # See the explanation in addOpenGLRunpath. - postFixup = optionalString (stdenv.isLinux && withLib) '' + postFixup = optionalString (stdenv.isLinux && enable.lib-output) '' addOpenGLRunpath ${placeholder "lib"}/lib/libavcodec.so addOpenGLRunpath ${placeholder "lib"}/lib/libavutil.so '' # https://trac.ffmpeg.org/ticket/10809 - + optionalString (versionAtLeast version "5.0" && withVulkan && !stdenv.hostPlatform.isMinGW) '' + + optionalString (versionAtLeast version "5.0" && enable.vulkan && !stdenv.hostPlatform.isMinGW) '' patchelf $lib/lib/libavcodec.so --add-needed libvulkan.so --add-rpath ${lib.makeLibraryPath [ vulkan-loader ]} ''; enableParallelBuilding = true; passthru.tests.pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage; + passthru.eval = eval; - meta = with lib; { + meta = { description = "A complete, cross-platform solution to record, convert and stream audio and video"; homepage = "https://www.ffmpeg.org/"; changelog = "https://github.com/FFmpeg/FFmpeg/blob/n${version}/Changelog"; @@ -835,26 +1152,21 @@ stdenv.mkDerivation (finalAttrs: { No matter if they were designed by some standards committee, the community or a corporation. ''; - license = with licenses; [ lgpl21Plus ] - ++ optional withGPL gpl2Plus - ++ optional withVersion3 lgpl3Plus - ++ optional withGPLv3 gpl3Plus - ++ optional withUnfree unfreeRedistributable - ++ optional (withGPL && withUnfree) unfree; - pkgConfigModules = [ ] - ++ optional buildAvcodec "libavcodec" - ++ optional buildAvdevice "libavdevice" - ++ optional buildAvfilter "libavfilter" - ++ optional buildAvformat "libavformat" - ++ optional buildAvresample "libavresample" - ++ optional buildAvutil "libavutil" - ++ optional buildPostproc "libpostproc" - ++ optional buildSwresample "libswresample" - ++ optional buildSwscale "libswscale"; - platforms = platforms.all; + license = + let + l = lib.licenses; + in + [ l.lgpl21Plus ] + ++ optional enable.gpl l.gpl2Plus + ++ optional enable.version3 l.lgpl3Plus + ++ optional enable.gplv3 l.gpl3Plus + ++ optional enable.unfree l.unfreeRedistributable + ++ optional (enable.gpl && enable.unfree) l.unfree; + pkgConfigModules = exposedLibNames; + platforms = lib.platforms.all; # See https://github.com/NixOS/nixpkgs/pull/295344#issuecomment-1992263658 broken = stdenv.hostPlatform.isMinGW && stdenv.hostPlatform.is64bit; - maintainers = with maintainers; [ atemu arthsmn jopejoe1 ]; + maintainers = with lib.maintainers; [ atemu arthsmn jopejoe1 ]; mainProgram = "ffmpeg"; }; }) diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 05aca9f4018f1..627e313bee623 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -3009,7 +3009,9 @@ with pkgs; mlterm = darwin.apple_sdk_11_0.callPackage ../applications/terminal-emulators/mlterm { }; mlterm-wayland = mlterm.override { - enableX11 = false; + configuration = { + x11 = false; + }; }; mrxvt = callPackage ../applications/terminal-emulators/mrxvt { };