Skip to content

Instantly share code, notes, and snippets.

@psanford
Created January 22, 2024 23:13
Show Gist options
  • Save psanford/1f70a0838c308d28478cf27a9b55c43d to your computer and use it in GitHub Desktop.
Save psanford/1f70a0838c308d28478cf27a9b55c43d to your computer and use it in GitHub Desktop.
Overlay for chromium widevine support with 16k pages (asahi on m{1,2,3} macs)
final: prev:
let
lacrosVersion = "120.0.6098.0";
widevine-installer = prev.stdenv.mkDerivation rec {
name = "widevine-installer";
version = "7a3928fe1342fb07d96f61c2b094e3287588958b";
src = prev.fetchFromGitHub {
owner = "AsahiLinux";
repo = "${name}";
rev = "${version}";
sha256 = "sha256-XI1y4pVNpXS+jqFs0KyVMrxcULOJ5rADsgvwfLF6e0Y=";
};
buildInputs = with prev.pkgs; [ which python3 squashfsTools ];
installPhase = ''
mkdir -p "$out/bin"
cp widevine-installer "$out/bin/"
cp widevine_fixup.py "$out/bin/"
echo "$(which unsquashfs)"
sed -e "s|unsquashfs|$(which unsquashfs)|" -i "$out/bin/widevine-installer"
sed -e "s|python3|$(which python3)|" -i "$out/bin/widevine-installer"
sed -e "s|read|#read|" -i "$out/bin/widevine-installer"
sed -e 's|$(whoami)|root|' -i "$out/bin/widevine-installer"
sed -e 's|URL=.*|URL="$DISTFILES_BASE"|' -i "$out/bin/widevine-installer"
'';
};
widevine = prev.stdenv.mkDerivation {
name = "widevine";
version = "";
buildInputs = with prev.pkgs; [ curl widevine-installer ];
src = prev.fetchurl {
urls = [ "https://commondatastorage.googleapis.com/chromeos-localmirror/distfiles/chromeos-lacros-arm64-squash-zstd-${lacrosVersion}" ];
hash = "sha256-OKV8w5da9oZ1oSGbADVPCIkP9Y0MVLaQ3PXS3ZBLFXY=";
};
unpackPhase = "true";
installPhase = ''
mkdir -p "$out/"
COPY_CONFIGS=0 INSTALL_BASE="$out" DISTFILES_BASE="file://$src" widevine-installer
'';
};
chromiumWV = prev.runCommand "chromium-wv" { version = prev.chromium.version; }
''
mkdir -p $out
cp -a ${prev.chromium.browser}/* $out/
chmod u+w $out/libexec/chromium
cp -Lr ${widevine}/WidevineCdm $out/libexec/chromium/
'';
in
{
chromium = prev.chromium.overrideAttrs (old: {
buildCommand = builtins.replaceStrings [ "${prev.chromium.browser}" ] [ "${chromiumWV}" ] old.buildCommand;
});
}
@diegobfernandez
Copy link

I've made these changes to make it work on Firefox:

diff --git a/widevine-overlay.nix b/widevine-overlay.nix
index 3c98eb3..77270a3 100644
--- a/widevine-overlay.nix
+++ b/widevine-overlay.nix
@@ -15,8 +15,10 @@ let
 
     installPhase = ''
       mkdir -p "$out/bin"
+      mkdir -p "$out/conf"
       cp widevine-installer "$out/bin/"
       cp widevine_fixup.py "$out/bin/"
+      cp conf/gmpwidevine.js "$out/conf/"
       echo "$(which unsquashfs)"
       sed -e "s|unsquashfs|$(which unsquashfs)|" -i "$out/bin/widevine-installer"
       sed -e "s|python3|$(which python3)|" -i "$out/bin/widevine-installer"
@@ -50,6 +52,11 @@ let
       '';
 in
 {
+  widevine = widevine;
+  firefox = prev.firefox.overrideAttrs (old: {
+    extraPrefsFiles = [ "${widevine-installer}/conf/gmpwidevine.js" ];
+  });
   chromium = prev.chromium.overrideAttrs (old: {
     buildCommand = builtins.replaceStrings [ "${prev.chromium.browser}" ] [ "${chromiumWV}" ] old.buildCommand;
   });

widevine is there so I can add

environment.sessionVariables.MOZ_GMP_PATH = [ "${pkgs.widevine}/gmp-widevinecdm/system-installed" ];

to my configuration.nix.

If anyone knows a way to set the environment variable on the package it would be great and make the overlay work on its own.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment