summary refs log tree commit diff
path: root/pkgs/applications/video/handbrake/default.nix
blob: 3e796275907ca4f34275da4eca00767eb53d53c4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# Handbrake normally uses its own copies of the libraries it uses, for better
# control over library patches.
#
# This derivation patches HB so it doesn't do that. The relevant patches
# are added to the Nix packages and proposed upstream instead. In several cases
# upstream already incorporated these patches.
# This has the benefits of providing improvements to other packages,
# making licenses more clear and reducing compile time/install size.
#
# Only tested on Linux

{ stdenv, lib, fetchFromGitHub,
  python2, pkgconfig, yasm, harfbuzz, zlib,
  autoconf, automake, cmake, libtool, m4, jansson,
  libass, libiconv, libsamplerate, fribidi, libxml2, bzip2,
  libogg, libopus, libtheora, libvorbis, libdvdcss, a52dec, fdk_aac,
  lame, ffmpeg, libdvdread, libdvdnav, libbluray,
  mp4v2, mpeg2dec, x264, x265, libmkv,
  fontconfig, freetype, hicolor-icon-theme,
  glib, gtk3, intltool, libnotify,
  gst_all_1, dbus-glib, udev, libgudev, libvpx,
  useGtk ? true, wrapGAppsHook ? null, libappindicator-gtk3 ? null
}:

stdenv.mkDerivation rec {
  version = "1.0.7";
  name = "handbrake-${version}";

  src = fetchFromGitHub {
    owner  = "HandBrake";
    repo   = "HandBrake";
    rev    = "${version}";
    sha256 = "1pdrvicq40s8n23n6k8k097kkjs3ah5wbz1mvxnfy3h2mh5rwk57";
  };

  nativeBuildInputs = [
    cmake python2 pkgconfig yasm autoconf automake libtool m4
  ] ++ (lib.optionals useGtk [
    intltool wrapGAppsHook
  ]);

  buildInputs = [
    fribidi fontconfig freetype jansson zlib
    libass libiconv libsamplerate libxml2 bzip2
    libogg libopus libtheora libvorbis libdvdcss a52dec libmkv fdk_aac
    lame ffmpeg libdvdread libdvdnav libbluray mp4v2 mpeg2dec x264 x265 libvpx
  ] ++ (lib.optionals useGtk [
    glib gtk3 libappindicator-gtk3 libnotify
    gst_all_1.gstreamer gst_all_1.gst-plugins-base dbus-glib udev
    libgudev
  ]);

  dontUseCmakeConfigure = true;

  enableParallelBuilding = true;

  preConfigure = ''
    patchShebangs scripts

    echo 'TAG=${version}' > version.txt

    # `configure` errors out when trying to read the current year which is too low
    substituteInPlace make/configure.py \
      --replace developer release \
      --replace 'repo.date.strftime("%Y-%m-%d %H:%M:%S")' '""'

    substituteInPlace libhb/module.defs \
      --replace /usr/include/libxml2 ${libxml2.dev}/include/libxml2

    # Force using nixpkgs dependencies
    sed -i '/MODULES += contrib/d' make/include/main.defs
    sed -i '/PKG_CONFIG_PATH=/d' gtk/module.rules
  '';

  configureFlags = [
    "--disable-df-fetch"
    "--disable-df-verify"
    "--enable-fdk-aac"
    (if useGtk then "--disable-gtk-update-checks" else "--disable-gtk")
  ];

  NIX_LDFLAGS = [
    "-lx265"
  ];

  preBuild = ''
    cd build
  '';

  # icon-theme.cache belongs in the icon theme, not in individual packages
  postInstall = ''
    rm $out/share/icons/hicolor/icon-theme.cache
  '';

  meta = with stdenv.lib; {
    homepage = http://handbrake.fr/;
    description = "A tool for ripping DVDs into video files";
    longDescription = ''
      Handbrake is a versatile transcoding DVD ripper. This package
      provides the cli HandbrakeCLI and the GTK+ version ghb.
    '';
    license = licenses.gpl2;
    maintainers = with maintainers; [ wmertens ];
    # Not tested on anything else
    platforms = platforms.linux;
  };
}