2020-09-18 19:37:22 +01:00
|
|
|
{ newScope, config, stdenv, fetchurl, makeWrapper
|
2020-11-01 04:59:37 +00:00
|
|
|
, llvmPackages_11, ed, gnugrep, coreutils, xdg_utils
|
2020-04-13 21:17:05 +01:00
|
|
|
, glib, gtk3, gnome3, gsettings-desktop-schemas, gn, fetchgit
|
|
|
|
, libva ? null
|
2020-07-22 18:34:13 +01:00
|
|
|
, pipewire_0_2
|
2020-07-08 20:55:09 +01:00
|
|
|
, gcc, nspr, nss, runCommand
|
2020-04-13 21:17:05 +01:00
|
|
|
, lib
|
|
|
|
|
|
|
|
# package customization
|
2020-04-28 23:40:08 +01:00
|
|
|
# Note: enable* flags should not require full rebuilds (i.e. only affect the wrapper)
|
2020-04-13 21:17:05 +01:00
|
|
|
, channel ? "stable"
|
|
|
|
, gnomeSupport ? false, gnome ? null
|
|
|
|
, gnomeKeyringSupport ? false
|
|
|
|
, proprietaryCodecs ? true
|
|
|
|
, enablePepperFlash ? false
|
|
|
|
, enableWideVine ? false
|
2020-11-01 04:59:37 +00:00
|
|
|
, enableVaapi ? false # Disabled by default due to unofficial support
|
2020-04-13 21:17:05 +01:00
|
|
|
, ungoogled ? true
|
|
|
|
, useOzone ? false
|
|
|
|
, cupsSupport ? true
|
|
|
|
, pulseSupport ? config.pulseaudio or stdenv.isLinux
|
|
|
|
, commandLineArgs ? ""
|
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
2020-11-01 04:59:37 +00:00
|
|
|
llvmPackages = llvmPackages_11;
|
2020-04-13 21:17:05 +01:00
|
|
|
stdenv = llvmPackages.stdenv;
|
|
|
|
|
|
|
|
callPackage = newScope chromium;
|
|
|
|
|
2020-09-18 19:37:22 +01:00
|
|
|
chromium = rec {
|
2020-04-13 21:17:05 +01:00
|
|
|
inherit stdenv llvmPackages;
|
|
|
|
|
2020-09-18 19:37:22 +01:00
|
|
|
upstream-info = (lib.importJSON ./upstream-info.json).${channel};
|
2020-04-13 21:17:05 +01:00
|
|
|
|
|
|
|
mkChromiumDerivation = callPackage ./common.nix ({
|
2020-09-18 19:37:22 +01:00
|
|
|
inherit channel gnome gnomeSupport gnomeKeyringSupport proprietaryCodecs
|
|
|
|
cupsSupport pulseSupport useOzone;
|
2020-04-28 23:40:08 +01:00
|
|
|
inherit ungoogled;
|
2020-07-22 18:34:13 +01:00
|
|
|
gnChromium = gn.overrideAttrs (oldAttrs: {
|
2020-11-08 21:44:11 +00:00
|
|
|
inherit (upstream-info.deps.gn) version;
|
2020-07-22 18:34:13 +01:00
|
|
|
src = fetchgit {
|
2020-11-08 21:44:11 +00:00
|
|
|
inherit (upstream-info.deps.gn) url rev sha256;
|
2020-09-18 19:37:22 +01:00
|
|
|
};
|
|
|
|
});
|
|
|
|
} // lib.optionalAttrs (lib.versionAtLeast upstream-info.version "87") {
|
|
|
|
useOzone = true; # YAY: https://chromium-review.googlesource.com/c/chromium/src/+/2382834 \o/
|
2020-11-01 04:59:37 +00:00
|
|
|
useVaapi = !stdenv.isAarch64; # TODO: Might be best to not set use_vaapi anymore (default is fine)
|
2020-04-13 21:17:05 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
browser = callPackage ./browser.nix { inherit channel enableWideVine; };
|
|
|
|
|
|
|
|
plugins = callPackage ./plugins.nix {
|
|
|
|
inherit enablePepperFlash;
|
|
|
|
};
|
|
|
|
|
|
|
|
ungoogled-chromium = callPackage ./ungoogled.nix {};
|
|
|
|
};
|
|
|
|
|
2020-09-18 19:37:22 +01:00
|
|
|
pkgSuffix = if channel == "dev" then "unstable" else channel;
|
|
|
|
pkgName = "google-chrome-${pkgSuffix}";
|
|
|
|
chromeSrc = fetchurl {
|
|
|
|
urls = map (repo: "${repo}/${pkgName}/${pkgName}_${version}-1_amd64.deb") [
|
|
|
|
"https://dl.google.com/linux/chrome/deb/pool/main/g"
|
|
|
|
"http://95.31.35.30/chrome/pool/main/g"
|
|
|
|
"http://mirror.pcbeta.com/google/chrome/deb/pool/main/g"
|
|
|
|
"http://repo.fdzh.org/chrome/deb/pool/main/g"
|
|
|
|
];
|
|
|
|
sha256 = chromium.upstream-info.sha256bin64;
|
|
|
|
};
|
|
|
|
|
2020-04-13 21:17:05 +01:00
|
|
|
mkrpath = p: "${lib.makeSearchPathOutput "lib" "lib64" p}:${lib.makeLibraryPath p}";
|
2020-09-18 19:37:22 +01:00
|
|
|
widevineCdm = stdenv.mkDerivation {
|
2020-04-13 21:17:05 +01:00
|
|
|
name = "chrome-widevine-cdm";
|
|
|
|
|
2020-09-18 19:37:22 +01:00
|
|
|
src = chromeSrc;
|
2020-04-13 21:17:05 +01:00
|
|
|
|
|
|
|
phases = [ "unpackPhase" "patchPhase" "installPhase" "checkPhase" ];
|
|
|
|
|
|
|
|
unpackCmd = let
|
|
|
|
widevineCdmPath =
|
2020-09-18 19:37:22 +01:00
|
|
|
if channel == "stable" then
|
2020-04-13 21:17:05 +01:00
|
|
|
"./opt/google/chrome/WidevineCdm"
|
2020-09-18 19:37:22 +01:00
|
|
|
else if channel == "beta" then
|
2020-04-13 21:17:05 +01:00
|
|
|
"./opt/google/chrome-beta/WidevineCdm"
|
2020-09-18 19:37:22 +01:00
|
|
|
else if channel == "dev" then
|
2020-04-13 21:17:05 +01:00
|
|
|
"./opt/google/chrome-unstable/WidevineCdm"
|
|
|
|
else
|
|
|
|
throw "Unknown chromium channel.";
|
|
|
|
in ''
|
|
|
|
# Extract just WidevineCdm from upstream's .deb file
|
|
|
|
ar p "$src" data.tar.xz | tar xJ "${widevineCdmPath}"
|
|
|
|
|
|
|
|
# Move things around so that we don't have to reference a particular
|
|
|
|
# chrome-* directory later.
|
|
|
|
mv "${widevineCdmPath}" ./
|
|
|
|
|
|
|
|
# unpackCmd wants a single output directory; let it take WidevineCdm/
|
|
|
|
rm -rf opt
|
|
|
|
'';
|
|
|
|
|
|
|
|
doCheck = true;
|
|
|
|
checkPhase = ''
|
|
|
|
! find -iname '*.so' -exec ldd {} + | grep 'not found'
|
|
|
|
'';
|
|
|
|
|
|
|
|
PATCH_RPATH = mkrpath [ gcc.cc glib nspr nss ];
|
|
|
|
|
|
|
|
patchPhase = ''
|
|
|
|
patchelf --set-rpath "$PATCH_RPATH" _platform_specific/linux_x64/libwidevinecdm.so
|
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
mkdir -p $out/WidevineCdm
|
|
|
|
cp -a * $out/WidevineCdm/
|
|
|
|
'';
|
|
|
|
|
|
|
|
meta = {
|
|
|
|
platforms = [ "x86_64-linux" ];
|
|
|
|
license = lib.licenses.unfree;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
suffix = if channel != "stable" then "-" + channel else "";
|
|
|
|
|
|
|
|
sandboxExecutableName = chromium.browser.passthru.sandboxExecutableName;
|
|
|
|
|
|
|
|
version = chromium.browser.version;
|
|
|
|
|
|
|
|
# We want users to be able to enableWideVine without rebuilding all of
|
|
|
|
# chromium, so we have a separate derivation here that copies chromium
|
|
|
|
# and adds the unfree WidevineCdm.
|
|
|
|
chromiumWV = let browser = chromium.browser; in if enableWideVine then
|
|
|
|
runCommand (browser.name + "-wv") { version = browser.version; }
|
|
|
|
''
|
|
|
|
mkdir -p $out
|
|
|
|
cp -a ${browser}/* $out/
|
|
|
|
chmod u+w $out/libexec/chromium
|
|
|
|
cp -a ${widevineCdm}/WidevineCdm $out/libexec/chromium/
|
|
|
|
''
|
|
|
|
else browser;
|
2020-04-28 23:40:08 +01:00
|
|
|
|
2020-04-13 21:17:05 +01:00
|
|
|
in stdenv.mkDerivation {
|
2020-07-22 18:34:13 +01:00
|
|
|
name = "ungoogled-chromium${suffix}-${version}";
|
2020-04-13 21:17:05 +01:00
|
|
|
inherit version;
|
|
|
|
|
|
|
|
buildInputs = [
|
|
|
|
makeWrapper ed
|
|
|
|
|
|
|
|
# needed for GSETTINGS_SCHEMAS_PATH
|
|
|
|
gsettings-desktop-schemas glib gtk3
|
|
|
|
|
|
|
|
# needed for XDG_ICON_DIRS
|
|
|
|
gnome3.adwaita-icon-theme
|
|
|
|
];
|
|
|
|
|
|
|
|
outputs = ["out" "sandbox"];
|
|
|
|
|
|
|
|
buildCommand = let
|
|
|
|
browserBinary = "${chromiumWV}/libexec/chromium/chromium";
|
|
|
|
getWrapperFlags = plugin: "$(< \"${plugin}/nix-support/wrapper-flags\")";
|
2020-07-22 18:34:13 +01:00
|
|
|
libPath = stdenv.lib.makeLibraryPath [ libva pipewire_0_2 ];
|
2020-04-13 21:17:05 +01:00
|
|
|
|
|
|
|
in with stdenv.lib; ''
|
|
|
|
mkdir -p "$out/bin"
|
|
|
|
|
|
|
|
eval makeWrapper "${browserBinary}" "$out/bin/chromium" \
|
|
|
|
--add-flags ${escapeShellArg (escapeShellArg commandLineArgs)} \
|
2020-11-01 04:59:37 +00:00
|
|
|
${lib.optionalString enableVaapi "--add-flags --enable-accelerated-video-decode"} \
|
2020-04-13 21:17:05 +01:00
|
|
|
${concatMapStringsSep " " getWrapperFlags chromium.plugins.enabled}
|
|
|
|
|
|
|
|
ed -v -s "$out/bin/chromium" << EOF
|
|
|
|
2i
|
|
|
|
|
|
|
|
if [ -x "/run/wrappers/bin/${sandboxExecutableName}" ]
|
|
|
|
then
|
|
|
|
export CHROME_DEVEL_SANDBOX="/run/wrappers/bin/${sandboxExecutableName}"
|
|
|
|
else
|
|
|
|
export CHROME_DEVEL_SANDBOX="$sandbox/bin/${sandboxExecutableName}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
'' + lib.optionalString (libPath != "") ''
|
|
|
|
# To avoid loading .so files from cwd, LD_LIBRARY_PATH here must not
|
|
|
|
# contain an empty section before or after a colon.
|
|
|
|
export LD_LIBRARY_PATH="\$LD_LIBRARY_PATH\''${LD_LIBRARY_PATH:+:}${libPath}"
|
|
|
|
'' + ''
|
|
|
|
|
|
|
|
# libredirect causes chromium to deadlock on startup
|
2020-09-18 19:37:22 +01:00
|
|
|
export LD_PRELOAD="\$(echo -n "\$LD_PRELOAD" | ${coreutils}/bin/tr ':' '\n' | ${gnugrep}/bin/grep -v /lib/libredirect\\\\.so$ | ${coreutils}/bin/tr '\n' ':')"
|
2020-04-13 21:17:05 +01:00
|
|
|
|
|
|
|
export XDG_DATA_DIRS=$XDG_ICON_DIRS:$GSETTINGS_SCHEMAS_PATH\''${XDG_DATA_DIRS:+:}\$XDG_DATA_DIRS
|
|
|
|
|
2020-09-18 19:37:22 +01:00
|
|
|
# Mainly for xdg-open but also other xdg-* tools:
|
|
|
|
export PATH="${xdg_utils}/bin\''${PATH:+:}\$PATH"
|
|
|
|
|
2020-04-13 21:17:05 +01:00
|
|
|
.
|
|
|
|
w
|
|
|
|
EOF
|
|
|
|
|
|
|
|
ln -sv "${chromium.browser.sandbox}" "$sandbox"
|
|
|
|
|
|
|
|
ln -s "$out/bin/chromium" "$out/bin/chromium-browser"
|
|
|
|
|
|
|
|
mkdir -p "$out/share"
|
|
|
|
for f in '${chromium.browser}'/share/*; do # hello emacs */
|
|
|
|
ln -s -t "$out/share/" "$f"
|
|
|
|
done
|
|
|
|
'';
|
|
|
|
|
|
|
|
inherit (chromium.browser) packageName;
|
|
|
|
meta = chromium.browser.meta;
|
|
|
|
passthru = {
|
|
|
|
inherit (chromium) upstream-info browser;
|
|
|
|
mkDerivation = chromium.mkChromiumDerivation;
|
2020-09-18 19:37:22 +01:00
|
|
|
inherit chromeSrc sandboxExecutableName;
|
|
|
|
updateScript = ./update.py;
|
2020-04-13 21:17:05 +01:00
|
|
|
};
|
|
|
|
}
|