summary refs log tree commit diff
path: root/pkgs/applications/networking/browsers/chromium/plugins.nix
blob: 30fa4c39a4e6682cd4829c24627442324322f339 (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
{ stdenv
, enablePepperFlash ? false
, enableWideVine ? false

, source
}:

with stdenv.lib;

let
  plugins = stdenv.mkDerivation {
    name = "chromium-binary-plugins";

    # XXX: Only temporary and has to be version-specific
    src = source.plugins;

    phases = [ "unpackPhase" "patchPhase" "installPhase" "checkPhase" ];
    outputs = [ "flash" "widevine" ];

    unpackCmd = let
      chan = if source.channel == "dev"    then "chrome-unstable"
        else if source.channel == "stable" then "chrome"
        else "chrome-${source.channel}";
    in ''
      mkdir -p plugins
      ar p "$src" data.tar.lzma | tar xJ -C plugins --strip-components=4 \
        ./opt/google/${chan}/PepperFlash \
        ./opt/google/${chan}/libwidevinecdm.so \
        ./opt/google/${chan}/libwidevinecdmadapter.so
    '';

    doCheck = true;
    checkPhase = ''
      ! find -iname '*.so' -exec ldd {} + | grep 'not found'
    '';

    patchPhase = let
      rpaths = [ stdenv.cc.cc ];
      mkrpath = p: "${makeSearchPath "lib64" p}:${makeSearchPath "lib" p}";
    in ''
      for sofile in PepperFlash/libpepflashplayer.so \
                    libwidevinecdm.so libwidevinecdmadapter.so; do
        chmod +x "$sofile"
        patchelf --set-rpath "${mkrpath rpaths}" "$sofile"
      done

      patchelf --set-rpath "$widevine/lib:${mkrpath rpaths}" \
        libwidevinecdmadapter.so
    '';

    installPhase = let
      wvName = "Widevine Content Decryption Module";
      wvDescription = "Playback of encrypted HTML audio/video content";
      wvMimeTypes = "application/x-ppapi-widevine-cdm";
      wvModule = "$widevine/lib/libwidevinecdmadapter.so";
      wvInfo = "#${wvName}#${wvDescription}:${wvMimeTypes}";
    in ''
      flashVersion="$(
        sed -n -r 's/.*"version": "([^"]+)",.*/\1/p' PepperFlash/manifest.json
      )"

      install -vD PepperFlash/libpepflashplayer.so \
        "$flash/lib/libpepflashplayer.so"
      mkdir -p "$flash/nix-support"
      cat > "$flash/nix-support/chromium-plugin.nix" <<NIXOUT
        { flags = [
            "--ppapi-flash-path='$flash/lib/libpepflashplayer.so'"
            "--ppapi-flash-version=$flashVersion"
          ];
        }
      NIXOUT

      install -vD libwidevinecdm.so \
        "$widevine/lib/libwidevinecdm.so"
      install -vD libwidevinecdmadapter.so \
        "$widevine/lib/libwidevinecdmadapter.so"
      mkdir -p "$widevine/nix-support"
      cat > "$widevine/nix-support/chromium-plugin.nix" <<NIXOUT
        { flags = [ "--register-pepper-plugins='${wvModule}${wvInfo}'" ];
          envVars.NIX_CHROMIUM_PLUGIN_PATH_WIDEVINE = "$widevine/lib";
        }
      NIXOUT
    '';

    passthru = let
      enabledPlugins = optional enablePepperFlash plugins.flash
                    ++ optional enableWideVine    plugins.widevine;
      getNix = plugin: import "${plugin}/nix-support/chromium-plugin.nix";
      mergeAttrsets = let
        f = v: if all isAttrs v then mergeAttrsets v
          else if all isList  v then concatLists   v
          else if tail v == []  then head          v
          else head (tail v);
      in fold (l: r: zipAttrsWith (_: f) [ l r ]) {};
    in {
      settings = mergeAttrsets (map getNix enabledPlugins);
    };
  };
in plugins