@@ -8,6 +8,34 @@
88with stdenv.lib;
99
1010let
11+ # Generate a shell fragment that emits flags appended to the
12+ # final makeWrapper call for wrapping the browser's main binary.
13+ #
14+ # Note that this is shell-escaped so that only the variable specified
15+ # by the "output" attribute is substituted.
16+ mkPluginInfo = { output ? "out", allowedVars ? [ output ]
17+ , flags ? [], envVars ? {}
18+ }: let
19+ shSearch = ["'"] ++ map (var: "\$${var}") allowedVars;
20+ shReplace = ["'\\''"] ++ map (var: "'\"\${${var}}\"'") allowedVars;
21+ # We need to triple-escape "val":
22+ # * First because makeWrapper doesn't do any quoting of its arguments by
23+ # itself.
24+ # * Second because it's passed to the makeWrapper call separated by IFS but
25+ # not by the _real_ arguments, for example the Widevine plugin flags
26+ # contain spaces, so they would end up as separate arguments.
27+ # * Third in order to be correctly quoted for the "echo" call below.
28+ shEsc = val: "'${replaceStrings ["'"] ["'\\''"] val}'";
29+ mkSh = val: "'${replaceStrings shSearch shReplace (shEsc val)}'";
30+ mkFlag = flag: ["--add-flags" (shEsc flag)];
31+ mkEnvVar = key: val: ["--set" (shEsc key) (shEsc val)];
32+ envList = mapAttrsToList mkEnvVar envVars;
33+ quoted = map mkSh (flatten ((map mkFlag flags) ++ envList));
34+ in ''
35+ mkdir -p "''$${output}/nix-support"
36+ echo ${toString quoted} > "''$${output}/nix-support/wrapper-flags"
37+ '';
38+
1139 plugins = stdenv.mkDerivation {
1240 name = "chromium-binary-plugins";
1341
@@ -61,40 +89,29 @@ let
6189
6290 install -vD PepperFlash/libpepflashplayer.so \
6391 "$flash/lib/libpepflashplayer.so"
64− mkdir -p "$flash/nix-support"
65− cat > "$flash/nix-support/chromium-plugin.nix" <<NIXOUT
66− { flags = [
67− "--ppapi-flash-path='$flash/lib/libpepflashplayer.so'"
68− "--ppapi-flash-version=$flashVersion"
69− ];
70− }
71− NIXOUT
92+
93+ ${mkPluginInfo {
94+ output = "flash";
95+ allowedVars = [ "flash" "flashVersion" ];
96+ flags = [
97+ "--ppapi-flash-path=$flash/lib/libpepflashplayer.so"
98+ "--ppapi-flash-version=$flashVersion"
99+ ];
100+ }}
72101
73102 install -vD libwidevinecdm.so \
74103 "$widevine/lib/libwidevinecdm.so"
75104 install -vD libwidevinecdmadapter.so \
76105 "$widevine/lib/libwidevinecdmadapter.so"
77− mkdir -p "$widevine/nix-support"
78− cat > "$widevine/nix-support/chromium-plugin.nix" <<NIXOUT
79− { flags = [ "--register-pepper-plugins='${wvModule}${wvInfo}'" ];
80− envVars.NIX_CHROMIUM_PLUGIN_PATH_WIDEVINE = "$widevine/lib";
81− }
82− NIXOUT
106+
107+ ${mkPluginInfo {
108+ output = "widevine";
109+ flags = [ "--register-pepper-plugins=${wvModule}${wvInfo}" ];
110+ envVars.NIX_CHROMIUM_PLUGIN_PATH_WIDEVINE = "$widevine/lib";
111+ }}
83112 '';
84113
85− passthru = let
86− enabledPlugins = optional enablePepperFlash plugins.flash
114+ passthru.enabled = optional enablePepperFlash plugins.flash
87115 ++ optional enableWideVine plugins.widevine;
88− getNix = plugin: import "${plugin}/nix-support/chromium-plugin.nix";
89− mergeAttrsets = let
90− f = v: if all isAttrs v then mergeAttrsets v
91− else if all isList v then concatLists v
92− else if tail v == [] then head v
93− else head (tail v);
94− in fold (l: r: zipAttrsWith (_: f) [ l r ]) {};
95− in {
96− inherit enabledPlugins;
97− settings = mergeAttrsets (map getNix enabledPlugins);
98− };
99116 };
100117in plugins