2019-11-06 20:37:25 +01:00
|
|
|
{ newScope, config, stdenv, fetchurl, makeWrapper
|
2022-03-05 21:30:31 +01:00
|
|
|
, llvmPackages_14, ed, gnugrep, coreutils, xdg-utils
|
2021-05-07 23:18:14 +02:00
|
|
|
, glib, gtk3, gnome, gsettings-desktop-schemas, gn, fetchgit
|
2021-07-21 11:46:49 +02:00
|
|
|
, libva, pipewire, wayland
|
2020-07-08 21:55:09 +02:00
|
|
|
, gcc, nspr, nss, runCommand
|
2019-08-11 01:09:55 +02:00
|
|
|
, lib
|
2012-12-03 17:55:09 +01:00
|
|
|
|
2012-12-03 18:23:49 +01:00
|
|
|
# package customization
|
2020-04-13 15:26:09 +02:00
|
|
|
# Note: enable* flags should not require full rebuilds (i.e. only affect the wrapper)
|
2012-12-03 17:55:09 +01:00
|
|
|
, channel ? "stable"
|
2012-12-03 18:23:49 +01:00
|
|
|
, proprietaryCodecs ? true
|
2014-09-30 06:00:47 +02:00
|
|
|
, enableWideVine ? false
|
2020-12-09 19:13:26 +01:00
|
|
|
, ungoogled ? false # Whether to build chromium or ungoogled-chromium
|
2014-12-07 14:52:36 +01:00
|
|
|
, cupsSupport ? true
|
2019-02-03 16:31:25 +01:00
|
|
|
, pulseSupport ? config.pulseaudio or stdenv.isLinux
|
2017-01-05 17:46:37 +01:00
|
|
|
, commandLineArgs ? ""
|
chromium: Minimal build (no install) from source.
This only gets chromium to build so far, installation is missing by upstream, so
we need to manually copy the corresponding files. And I guess with nix, we also
need to patch a few paths on installation.
Another issue is that at the moment, a lot of dependencies are used from the
source tree, rather than from the system.
Also, it would be nice to build using LLVM, as it really speeds up compilation a
*LOT* and also has the side effect of resulting in smaller binaries.
Working unit tests would be nice, too. Unfortunately they're quite heavyweight
and take hours to run, so I guess "someday" would be the most appropriate time
to integrate.
Further todo's:
- Allow to disable GConf, GIO and CUPS.
- Option to disable the sandbox (for whatever reason the user might have).
- Integrate gold binutils.
- Pulseaudio support.
- Clearly separate Linux specific stuff.
2012-06-12 10:19:22 +02:00
|
|
|
}:
|
2009-10-30 09:45:58 +01:00
|
|
|
|
chromium: Minimal build (no install) from source.
This only gets chromium to build so far, installation is missing by upstream, so
we need to manually copy the corresponding files. And I guess with nix, we also
need to patch a few paths on installation.
Another issue is that at the moment, a lot of dependencies are used from the
source tree, rather than from the system.
Also, it would be nice to build using LLVM, as it really speeds up compilation a
*LOT* and also has the side effect of resulting in smaller binaries.
Working unit tests would be nice, too. Unfortunately they're quite heavyweight
and take hours to run, so I guess "someday" would be the most appropriate time
to integrate.
Further todo's:
- Allow to disable GConf, GIO and CUPS.
- Option to disable the sandbox (for whatever reason the user might have).
- Integrate gold binutils.
- Pulseaudio support.
- Clearly separate Linux specific stuff.
2012-06-12 10:19:22 +02:00
|
|
|
let
|
2022-03-05 21:30:31 +01:00
|
|
|
llvmPackages = llvmPackages_14;
|
2020-02-26 19:14:44 +01:00
|
|
|
stdenv = llvmPackages.stdenv;
|
2019-02-03 16:31:25 +01:00
|
|
|
|
2021-08-28 23:12:27 +02:00
|
|
|
upstream-info = (lib.importJSON ./upstream-info.json).${channel};
|
|
|
|
|
|
|
|
# Helper functions for changes that depend on specific versions:
|
|
|
|
warnObsoleteVersionConditional = min-version: result:
|
|
|
|
let ungoogled-version = (lib.importJSON ./upstream-info.json).ungoogled-chromium.version;
|
|
|
|
in lib.warnIf
|
|
|
|
(lib.versionAtLeast ungoogled-version min-version)
|
|
|
|
"chromium: ungoogled version ${ungoogled-version} is newer than a conditional bounded at ${min-version}. You can safely delete it."
|
|
|
|
result;
|
|
|
|
chromiumVersionAtLeast = min-version:
|
|
|
|
let result = lib.versionAtLeast upstream-info.version min-version;
|
|
|
|
in warnObsoleteVersionConditional min-version result;
|
|
|
|
versionRange = min-version: upto-version:
|
|
|
|
let inherit (upstream-info) version;
|
|
|
|
result = lib.versionAtLeast version min-version && lib.versionOlder version upto-version;
|
|
|
|
in warnObsoleteVersionConditional upto-version result;
|
|
|
|
|
2014-03-19 12:21:10 +01:00
|
|
|
callPackage = newScope chromium;
|
2014-03-19 11:32:39 +01:00
|
|
|
|
2020-08-25 23:03:35 +02:00
|
|
|
chromium = rec {
|
2021-08-28 23:12:27 +02:00
|
|
|
inherit stdenv llvmPackages upstream-info;
|
2014-03-19 12:51:39 +01:00
|
|
|
|
2020-04-03 19:17:57 +02:00
|
|
|
mkChromiumDerivation = callPackage ./common.nix ({
|
2021-08-28 23:12:27 +02:00
|
|
|
inherit channel chromiumVersionAtLeast versionRange;
|
2022-03-28 16:10:35 +02:00
|
|
|
inherit proprietaryCodecs
|
2020-12-09 19:13:26 +01:00
|
|
|
cupsSupport pulseSupport ungoogled;
|
2020-07-23 22:43:09 +02:00
|
|
|
gnChromium = gn.overrideAttrs (oldAttrs: {
|
2020-11-03 13:08:09 +01:00
|
|
|
inherit (upstream-info.deps.gn) version;
|
2020-07-23 22:43:09 +02:00
|
|
|
src = fetchgit {
|
2020-11-03 13:08:09 +01:00
|
|
|
inherit (upstream-info.deps.gn) url rev sha256;
|
2020-07-23 22:43:09 +02:00
|
|
|
};
|
|
|
|
});
|
2020-04-03 19:17:57 +02:00
|
|
|
});
|
2014-03-19 12:57:49 +01:00
|
|
|
|
2021-08-28 23:12:27 +02:00
|
|
|
browser = callPackage ./browser.nix {
|
|
|
|
inherit channel chromiumVersionAtLeast enableWideVine ungoogled;
|
|
|
|
};
|
2014-03-22 17:05:14 +01:00
|
|
|
|
2020-12-09 19:13:26 +01:00
|
|
|
ungoogled-chromium = callPackage ./ungoogled.nix {};
|
2018-10-28 17:07:19 +01:00
|
|
|
};
|
2014-03-19 11:32:39 +01:00
|
|
|
|
2020-12-22 13:21:12 +01:00
|
|
|
pkgSuffix = if channel == "dev" then "unstable" else
|
|
|
|
(if channel == "ungoogled-chromium" then "stable" else channel);
|
2019-11-06 20:37:25 +01:00
|
|
|
pkgName = "google-chrome-${pkgSuffix}";
|
2021-01-30 19:03:45 +01:00
|
|
|
chromeSrc =
|
|
|
|
let
|
|
|
|
# Use the latest stable Chrome version if necessary:
|
|
|
|
version = if chromium.upstream-info.sha256bin64 != null
|
|
|
|
then chromium.upstream-info.version
|
|
|
|
else (lib.importJSON ./upstream-info.json).stable.version;
|
|
|
|
sha256 = if chromium.upstream-info.sha256bin64 != null
|
|
|
|
then chromium.upstream-info.sha256bin64
|
|
|
|
else (lib.importJSON ./upstream-info.json).stable.sha256bin64;
|
|
|
|
in 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"
|
|
|
|
];
|
|
|
|
inherit sha256;
|
2020-12-22 13:21:12 +01:00
|
|
|
};
|
2019-11-06 20:37:25 +01:00
|
|
|
|
2019-08-11 01:09:55 +02:00
|
|
|
mkrpath = p: "${lib.makeSearchPathOutput "lib" "lib64" p}:${lib.makeLibraryPath p}";
|
2019-11-06 20:37:25 +01:00
|
|
|
widevineCdm = stdenv.mkDerivation {
|
2019-12-15 05:16:24 +01:00
|
|
|
name = "chrome-widevine-cdm";
|
2019-08-11 01:09:55 +02:00
|
|
|
|
2019-11-06 20:37:25 +01:00
|
|
|
src = chromeSrc;
|
2019-08-11 01:09:55 +02:00
|
|
|
|
|
|
|
unpackCmd = let
|
2019-12-15 05:16:24 +01:00
|
|
|
widevineCdmPath =
|
2020-12-22 13:21:12 +01:00
|
|
|
if (channel == "stable" || channel == "ungoogled-chromium") then
|
2019-12-15 05:16:24 +01:00
|
|
|
"./opt/google/chrome/WidevineCdm"
|
2019-11-06 20:37:25 +01:00
|
|
|
else if channel == "beta" then
|
2019-12-15 05:16:24 +01:00
|
|
|
"./opt/google/chrome-beta/WidevineCdm"
|
2019-11-06 20:37:25 +01:00
|
|
|
else if channel == "dev" then
|
2019-12-15 05:16:24 +01:00
|
|
|
"./opt/google/chrome-unstable/WidevineCdm"
|
2019-09-18 23:30:15 +02:00
|
|
|
else
|
|
|
|
throw "Unknown chromium channel.";
|
2019-08-11 01:09:55 +02:00
|
|
|
in ''
|
2019-12-15 05:16:24 +01:00
|
|
|
# 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
|
2019-08-11 01:09:55 +02:00
|
|
|
'';
|
|
|
|
|
|
|
|
doCheck = true;
|
|
|
|
checkPhase = ''
|
|
|
|
! find -iname '*.so' -exec ldd {} + | grep 'not found'
|
|
|
|
'';
|
|
|
|
|
|
|
|
PATCH_RPATH = mkrpath [ gcc.cc glib nspr nss ];
|
|
|
|
|
|
|
|
patchPhase = ''
|
2019-12-15 05:16:24 +01:00
|
|
|
patchelf --set-rpath "$PATCH_RPATH" _platform_specific/linux_x64/libwidevinecdm.so
|
2019-08-11 01:09:55 +02:00
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = ''
|
2019-12-15 05:16:24 +01:00
|
|
|
mkdir -p $out/WidevineCdm
|
|
|
|
cp -a * $out/WidevineCdm/
|
2019-08-11 01:09:55 +02:00
|
|
|
'';
|
|
|
|
|
2019-09-18 23:30:15 +02:00
|
|
|
meta = {
|
|
|
|
platforms = [ "x86_64-linux" ];
|
|
|
|
license = lib.licenses.unfree;
|
|
|
|
};
|
2019-08-11 01:09:55 +02:00
|
|
|
};
|
|
|
|
|
2020-12-09 19:29:31 +01:00
|
|
|
suffix = if (channel == "stable" || channel == "ungoogled-chromium")
|
|
|
|
then ""
|
|
|
|
else "-" + channel;
|
2014-11-25 10:08:28 +01:00
|
|
|
|
2016-08-06 10:13:20 +02:00
|
|
|
sandboxExecutableName = chromium.browser.passthru.sandboxExecutableName;
|
|
|
|
|
2017-06-16 07:49:50 +02:00
|
|
|
version = chromium.browser.version;
|
|
|
|
|
2019-09-18 23:30:15 +02:00
|
|
|
# We want users to be able to enableWideVine without rebuilding all of
|
|
|
|
# chromium, so we have a separate derivation here that copies chromium
|
2019-12-15 05:16:24 +01:00
|
|
|
# and adds the unfree WidevineCdm.
|
2019-08-11 01:09:55 +02:00
|
|
|
chromiumWV = let browser = chromium.browser; in if enableWideVine then
|
|
|
|
runCommand (browser.name + "-wv") { version = browser.version; }
|
|
|
|
''
|
|
|
|
mkdir -p $out
|
2019-09-18 23:30:15 +02:00
|
|
|
cp -a ${browser}/* $out/
|
|
|
|
chmod u+w $out/libexec/chromium
|
2019-12-15 05:16:24 +01:00
|
|
|
cp -a ${widevineCdm}/WidevineCdm $out/libexec/chromium/
|
2019-08-11 01:09:55 +02:00
|
|
|
''
|
|
|
|
else browser;
|
2020-04-13 15:26:09 +02:00
|
|
|
|
2014-03-22 17:05:14 +01:00
|
|
|
in stdenv.mkDerivation {
|
2022-03-22 17:57:23 +01:00
|
|
|
pname = lib.optionalString ungoogled "ungoogled-"
|
|
|
|
+ "chromium${suffix}";
|
2017-06-16 07:49:50 +02:00
|
|
|
inherit version;
|
2014-03-22 17:05:14 +01:00
|
|
|
|
2021-07-05 14:58:52 +02:00
|
|
|
nativeBuildInputs = [
|
2017-06-16 07:49:50 +02:00
|
|
|
makeWrapper ed
|
2021-07-05 14:58:52 +02:00
|
|
|
];
|
2017-06-16 07:49:50 +02:00
|
|
|
|
2021-07-05 14:58:52 +02:00
|
|
|
buildInputs = [
|
2017-06-16 07:49:50 +02:00
|
|
|
# needed for GSETTINGS_SCHEMAS_PATH
|
2018-02-25 03:23:58 +01:00
|
|
|
gsettings-desktop-schemas glib gtk3
|
2017-06-16 07:49:50 +02:00
|
|
|
|
|
|
|
# needed for XDG_ICON_DIRS
|
2021-05-07 23:18:14 +02:00
|
|
|
gnome.adwaita-icon-theme
|
2017-06-16 07:49:50 +02:00
|
|
|
];
|
2014-03-22 17:05:14 +01:00
|
|
|
|
2016-08-06 10:13:20 +02:00
|
|
|
outputs = ["out" "sandbox"];
|
|
|
|
|
2014-03-22 17:05:14 +01:00
|
|
|
buildCommand = let
|
2019-08-11 01:09:55 +02:00
|
|
|
browserBinary = "${chromiumWV}/libexec/chromium/chromium";
|
2021-07-21 11:46:49 +02:00
|
|
|
libPath = lib.makeLibraryPath [ libva pipewire wayland gtk3 ];
|
2019-02-18 09:17:05 +01:00
|
|
|
|
2021-01-15 14:21:58 +01:00
|
|
|
in with lib; ''
|
2016-08-27 17:38:25 +02:00
|
|
|
mkdir -p "$out/bin"
|
2012-06-15 10:19:26 +02:00
|
|
|
|
2022-02-02 12:07:18 +01:00
|
|
|
makeWrapper "${browserBinary}" "$out/bin/chromium" \
|
|
|
|
--add-flags ${escapeShellArg commandLineArgs} \
|
2021-11-27 01:54:14 +01:00
|
|
|
--add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--enable-features=UseOzonePlatform --ozone-platform=wayland}}"
|
2012-06-15 10:19:26 +02:00
|
|
|
|
2016-08-19 20:18:14 +02:00
|
|
|
ed -v -s "$out/bin/chromium" << EOF
|
|
|
|
2i
|
|
|
|
|
2017-01-29 11:11:01 +01:00
|
|
|
if [ -x "/run/wrappers/bin/${sandboxExecutableName}" ]
|
2016-08-19 20:18:14 +02:00
|
|
|
then
|
2017-01-29 11:11:01 +01:00
|
|
|
export CHROME_DEVEL_SANDBOX="/run/wrappers/bin/${sandboxExecutableName}"
|
2016-08-19 20:18:14 +02:00
|
|
|
else
|
|
|
|
export CHROME_DEVEL_SANDBOX="$sandbox/bin/${sandboxExecutableName}"
|
|
|
|
fi
|
|
|
|
|
2019-10-30 23:39:17 +01:00
|
|
|
'' + 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}"
|
|
|
|
'' + ''
|
2019-02-18 09:17:05 +01:00
|
|
|
|
2016-08-19 20:18:14 +02:00
|
|
|
# libredirect causes chromium to deadlock on startup
|
2020-08-03 17:58:41 +02:00
|
|
|
export LD_PRELOAD="\$(echo -n "\$LD_PRELOAD" | ${coreutils}/bin/tr ':' '\n' | ${gnugrep}/bin/grep -v /lib/libredirect\\\\.so$ | ${coreutils}/bin/tr '\n' ':')"
|
2016-08-19 20:18:14 +02:00
|
|
|
|
2017-06-16 07:49:50 +02:00
|
|
|
export XDG_DATA_DIRS=$XDG_ICON_DIRS:$GSETTINGS_SCHEMAS_PATH\''${XDG_DATA_DIRS:+:}\$XDG_DATA_DIRS
|
|
|
|
|
2022-02-26 12:45:52 +01:00
|
|
|
# Mainly for xdg-open but also other xdg-* tools (this is only a fallback; \$PATH is suffixed so that other implementations can be used):
|
|
|
|
export PATH="\$PATH\''${PATH:+:}${xdg-utils}/bin"
|
2020-09-06 23:20:30 +02:00
|
|
|
|
2016-08-19 20:18:14 +02:00
|
|
|
.
|
|
|
|
w
|
|
|
|
EOF
|
2016-08-06 10:13:20 +02:00
|
|
|
|
2016-08-06 11:09:40 +02:00
|
|
|
ln -sv "${chromium.browser.sandbox}" "$sandbox"
|
2016-08-06 10:13:20 +02:00
|
|
|
|
2014-09-19 07:51:11 +02:00
|
|
|
ln -s "$out/bin/chromium" "$out/bin/chromium-browser"
|
2016-08-27 17:38:25 +02:00
|
|
|
|
2019-05-28 02:32:18 +02:00
|
|
|
mkdir -p "$out/share"
|
2018-01-22 00:33:47 +01:00
|
|
|
for f in '${chromium.browser}'/share/*; do # hello emacs */
|
2016-08-27 17:38:25 +02:00
|
|
|
ln -s -t "$out/share/" "$f"
|
|
|
|
done
|
2014-03-22 17:05:14 +01:00
|
|
|
'';
|
2014-03-23 19:48:53 +01:00
|
|
|
|
2018-01-22 00:33:47 +01:00
|
|
|
inherit (chromium.browser) packageName;
|
2019-04-23 03:47:19 +02:00
|
|
|
meta = chromium.browser.meta;
|
2014-04-01 07:36:26 +02:00
|
|
|
passthru = {
|
2016-08-06 15:40:56 +02:00
|
|
|
inherit (chromium) upstream-info browser;
|
2014-04-01 07:36:26 +02:00
|
|
|
mkDerivation = chromium.mkChromiumDerivation;
|
2019-11-06 20:37:25 +01:00
|
|
|
inherit chromeSrc sandboxExecutableName;
|
|
|
|
updateScript = ./update.py;
|
2014-04-01 07:36:26 +02:00
|
|
|
};
|
2014-03-22 17:05:14 +01:00
|
|
|
}
|