Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkgbuilds/widevine/.omarchy/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"source": "local",
"sync": false
}
21 changes: 21 additions & 0 deletions pkgbuilds/widevine/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 David Buchanan

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
77 changes: 77 additions & 0 deletions pkgbuilds/widevine/PKGBUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
pkgname=widevine
pkgver=4.10.2891.0
pkgrel=2
pkgdesc='Google DRM content decryption module for Chromium and Firefox, fetched on the device'
arch=('aarch64')
groups=('omarchy-platform-apple-silicon')
url='https://www.widevine.com/'
license=('MIT')
# The CDM itself is Google's and is never in this package: widevine-fetch
# downloads this image on the Mac, checks it and patches the library there.
_lacros_version=120.0.6098.0
_lacros_url="https://commondatastorage.googleapis.com/chromeos-localmirror/distfiles/chromeos-lacros-arm64-squash-zstd-$_lacros_version"
_lacros_sha256=38a57cc3975af68675a1219b00354f08890ff58d0c54b690dcf5d2dd904b1576
depends=('glibc' 'gcc-libs' 'glib2' 'nspr' 'nss'
'bash' 'coreutils' 'curl' 'python' 'squashfs-tools' 'systemd' 'util-linux')
provides=('chromium-widevine')
conflicts=('chromium-widevine')
install=widevine.install
source=(widevine-fetch widevine-fetch.service widevine-fetch.timer widevine_fixup.py LICENSE)
sha256sums=('290ee7c48e6666c19397f7d9ab7f750e390d7b606b03f41445e6ea1cedd77c5e'
'c10503ecbbd7fb1b11b69c37064b91a79e0db59f19000f8ddb2ce487cd97e327'
'6c6d685c79b235cf4539dbe6c184e262417775fef5f526f72bd232e6b7e0624b'
'6e886755201f1ba9dab1ead5f11846bae321cbf343da1112f06c08c8a8012182'
'b1ffbe2d8f0c6363b2dd7cfc9cee62ee63c7e2e4a343ad882fa94cf1357b3052')

package() {
local cdm=/opt/WidevineCdm/chromium major=${pkgver%%.*} minor
minor=${pkgver#*.}; minor=${minor%%.*}

install -Dm755 "$srcdir/widevine-fetch" "$pkgdir/usr/bin/widevine-fetch"
install -Dm644 "$srcdir/widevine_fixup.py" "$pkgdir/usr/lib/widevine/widevine_fixup.py"
printf 'WIDEVINE_VERSION=%s\nLACROS_VERSION=%s\nLACROS_URL=%s\nLACROS_SHA256=%s\n' \
"$pkgver" "$_lacros_version" "$_lacros_url" "$_lacros_sha256" > "$srcdir/source"
install -Dm644 "$srcdir/source" "$pkgdir/usr/lib/widevine/source"
install -Dm644 "$srcdir/widevine-fetch.service" -t "$pkgdir/usr/lib/systemd/system/"
install -Dm644 "$srcdir/widevine-fetch.timer" -t "$pkgdir/usr/lib/systemd/system/"
# Enabled by the package, not a preset: image presets only cover omarchy-mac's units.
install -d "$pkgdir/usr/lib/systemd/system/timers.target.wants"
ln -s ../widevine-fetch.timer "$pkgdir/usr/lib/systemd/system/timers.target.wants/widevine-fetch.timer"

# Chromium: the CDM directory, its manifest, and the link Chromium looks for.
install -d "$pkgdir$cdm/_platform_specific/linux_arm64" "$pkgdir$cdm/_platform_specific/linux_x64"
cat > "$srcdir/manifest.json" <<JSON
{
"name": "WidevineCdm",
"description": "Widevine Content Decryption Module",
"version": "$pkgver",
"x-cdm-codecs": "vp8,vp9.0,avc1,av01",
"x-cdm-host-versions": "$minor",
"x-cdm-interface-versions": "$minor",
"x-cdm-module-versions": "$major",
"x-cdm-persistent-license-support": true
}
JSON
install -Dm644 "$srcdir/manifest.json" "$pkgdir$cdm/manifest.json"
install -d "$pkgdir/usr/lib/chromium"
ln -s "$cdm" "$pkgdir/usr/lib/chromium/WidevineCdm"

# Firefox: a system GMP directory, and prefs. widevine-fetch adds the library's link.
local gmp=/opt/WidevineCdm/firefox/gmp-widevinecdm/system-installed
install -d "$pkgdir$gmp"
ln -s ../../../chromium/manifest.json "$pkgdir$gmp/manifest.json"
cat > "$srcdir/widevine.js" <<JS
// Set preferences related to widevine loading
pref("media.gmp-widevinecdm.version", "$pkgver");
pref("media.gmp-widevinecdm.visible", true);
pref("media.gmp-widevinecdm.enabled", true);
pref("media.gmp-widevinecdm.autoupdate", false);
pref("media.eme.enabled", true);
pref("media.eme.encrypted-media-encryption-scheme.enabled", true);
JS
install -Dm644 "$srcdir/widevine.js" -t "$pkgdir/usr/lib/firefox/browser/defaults/preferences/"
printf '%s\n' "MOZ_GMP_PATH=\"\$MOZ_GMP_PATH\${MOZ_GMP_PATH:+:}$gmp\"" 'export MOZ_GMP_PATH' > "$srcdir/firefox_widevine.sh"
install -Dm644 "$srcdir/firefox_widevine.sh" -t "$pkgdir/etc/profile.d/"

install -Dm644 "$srcdir/LICENSE" "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}
14 changes: 14 additions & 0 deletions pkgbuilds/widevine/README.package.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# widevine

Google's Widevine CDM for Chromium and Firefox on Apple Silicon, installed on the Mac itself. This package holds none of Google's code.

Google's terms forbid copying, modifying or distributing its software, and the CDM has to be patched to run on Asahi kernels (16K pages, missing glibc symbols). So we never host the library, never put it in an image, and never fetch it during a package or image build. The package ships only our own files and the MIT-licensed fixup script:

- `widevine-fetch` downloads the ChromeOS Lacros arm64 image pinned in the recipe (`_lacros_version`, `_lacros_sha256`) from Google's `chromeos-localmirror`, checks its sha256, extracts `libwidevinecdm.so`, patches it with David Buchanan's `widevine_fixup.py` and installs it in `/opt/WidevineCdm/chromium/_platform_specific/linux_arm64/`.
- `widevine-fetch.timer` is enabled by the package itself (image presets only cover omarchy-mac's units). It runs the fetch two minutes after boot and hourly after that. Once the library is installed, a run only checks its hash. Offline runs exit cleanly and the next run tries again.
- The fetch exits without doing anything off a booted system (a chroot, or a container with no systemd), so an image build can't trigger it. The install scriptlet only starts the timer, and only on a booted system.
- The Chromium manifest, the `/usr/lib/chromium/WidevineCdm` link, the Firefox GMP directory, prefs and `profile.d` script come from asahi-alarm's recipe. The fetch adds the links to the library, so no path in the package is named `libwidevinecdm.so`.

`sudo widevine-fetch` fetches it right away, and `--force` fetches it again. Restart the browser afterwards. Removing the package deletes the fetched library and its cache.

The recipe follows asahi-alarm's: same name and `pkgver`, a higher `pkgrel`, and `provides`/`conflicts` on `chromium-widevine`. Upgrading from asahi-alarm's build removes its packaged library, and the timer installs ours a few minutes later. `pkgver` and the manifest say 4.10.2891.0, as asahi-alarm's do. The library in Lacros 120.0.6098.0 is really 4.10.2662.3. Lacros was discontinued, so no newer arm64 image exists.
63 changes: 63 additions & 0 deletions pkgbuilds/widevine/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/bash
# The package carries only our own bytes: no Google library or image, nothing
# fetched at build or install time, and a fetch that refuses to run in a chroot.
set -euo pipefail

package_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)
scratch=$(mktemp -d)
trap 'rm -rf "$scratch"' EXIT

fail() {
echo "not ok - $1" >&2
exit 1
}

source "$package_dir/PKGBUILD"
for item in "${source[@]}"; do
[[ $item != *://* ]] || fail "widevine downloads nothing at build time ($item)"
done
[[ $(type -t build) != function && $(type -t prepare) != function ]] ||
fail "widevine has no build or prepare step"
(( $(vercmp "$pkgver-$pkgrel" 4.10.2891.0-1) > 0 )) || fail "widevine upgrades asahi-alarm's 4.10.2891.0-1"
[[ $pkgver == 4.10.2891.0 ]] || fail "widevine keeps asahi-alarm's pkgver"

srcdir="$scratch/src"
pkgdir="$scratch/pkg"
mkdir -p "$srcdir"
for item in "${source[@]}"; do cp "$package_dir/$item" "$srcdir/"; done
(cd "$srcdir" && package)

while IFS= read -r -d '' path; do
rel=${path#"$pkgdir"}
[[ $rel != *.so* && $rel != *libwidevinecdm* ]] || fail "the package ships a path named for the library ($rel)"
[[ $rel != *squash* ]] || fail "the package ships a path named for an image ($rel)"
done < <(find "$pkgdir" -mindepth 1 -print0)

while IFS= read -r -d '' file; do
rel=${file#"$pkgdir"}
magic=$(head -c4 "$file" | od -An -tx1 | tr -d ' \n')
[[ $magic != 7f454c46 ]] || fail "the package ships an ELF binary ($rel)"
[[ $magic != 68737173 ]] || fail "the package ships a squashfs image ($rel)"
(( $(stat -c %s "$file") < 65536 )) || fail "the package ships a large file ($rel)"
done < <(find "$pkgdir" -type f -print0)

cdm=/opt/WidevineCdm/chromium/_platform_specific/linux_arm64/libwidevinecdm.so
[[ -d $pkgdir/opt/WidevineCdm/firefox/gmp-widevinecdm/system-installed ]] || fail "Firefox's GMP directory"
grep -qF 'ln -sfn ../../../chromium/_platform_specific/linux_arm64/libwidevinecdm.so "$GMP_LINK"' "$pkgdir/usr/bin/widevine-fetch" ||
fail "the fetch links Firefox's GMP directory to the library"
[[ $(readlink "$pkgdir/usr/lib/chromium/WidevineCdm") == /opt/WidevineCdm/chromium ]] || fail "Chromium's WidevineCdm link"
[[ $(readlink "$pkgdir/usr/lib/systemd/system/timers.target.wants/widevine-fetch.timer") == ../widevine-fetch.timer ]] ||
fail "the fetch timer is enabled by the package"
grep -qxF "LACROS_SHA256=$_lacros_sha256" "$pkgdir/usr/lib/widevine/source" || fail "the fetch is pinned to the recipe's sha256"
grep -qF "\"version\": \"$pkgver\"" "$pkgdir/opt/WidevineCdm/chromium/manifest.json" || fail "the manifest names pkgver"

# The scriptlet may start the timer, never fetch.
! grep -qE 'widevine-fetch( |$)|curl|unsquashfs|widevine_fixup' "$package_dir/widevine.install" ||
fail "the install scriptlet fetches"
grep -qF "${cdm%/*/*}" "$package_dir/widevine.install" || fail "removal deletes the fetched library"

# Off a booted system (a container or an image build chroot) the fetch does nothing and succeeds.
out=$(bash "$pkgdir/usr/bin/widevine-fetch" 2>&1) || fail "widevine-fetch fails off a booted system: $out"
[[ $out == *"not on a booted system"* ]] || fail "widevine-fetch refuses off a booted system: $out"

echo "ok - widevine"
91 changes: 91 additions & 0 deletions pkgbuilds/widevine/widevine-fetch
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#!/bin/bash
# Download Google's Widevine CDM on this Mac and install it for Chromium and
# Firefox. The package ships no Google code: this fetches the pinned ChromeOS
# Lacros image from Google, checks its sha256, extracts libwidevinecdm.so and
# patches it for Asahi kernels (16K pages, missing glibc symbols).
#
# widevine-fetch fetch and install unless already installed
# widevine-fetch --force fetch and install again
#
# Being offline is not an error: it exits 0 and widevine-fetch.timer tries
# again. It never runs in a chroot, so an image build cannot fetch the blob.
set -euo pipefail

say() { echo "widevine-fetch: $*"; }

if [[ ! -d /run/systemd/system ]] || systemd-detect-virt --quiet --chroot; then
say "not on a booted system; Widevine is fetched on the Mac itself"
exit 0
fi

source /usr/lib/widevine/source

CDM_DIR=/opt/WidevineCdm/chromium/_platform_specific
LIB=$CDM_DIR/linux_arm64/libwidevinecdm.so
# Chromium finds the arm64 library only when the x64 directory has one too.
PLACEHOLDER=$CDM_DIR/linux_x64/libwidevinecdm.so
GMP_LINK=/opt/WidevineCdm/firefox/gmp-widevinecdm/system-installed/libwidevinecdm.so
STATE=${STATE_DIRECTORY:-/var/lib/widevine}
CACHE=${CACHE_DIRECTORY:-/var/cache/widevine}
STAMP=$STATE/installed
# Shared with the package's pre_remove, so removal and fetches never overlap.
LOCK=/run/widevine/fetch.lock

force=false
case ${1:-} in
--force) force=true ;;
"") ;;
*) echo "usage: widevine-fetch [--force]" >&2; exit 2 ;;
esac

(( EUID == 0 )) || { echo "widevine-fetch: run it as root (sudo widevine-fetch)" >&2; exit 1; }

mkdir -p "${LOCK%/*}"
exec 9>"$LOCK"
flock 9
# The package may have been removed while this run waited for the lock.
[[ -f /usr/lib/widevine/source ]] || exit 0

stamp="$WIDEVINE_VERSION $LACROS_SHA256"
if [[ $force == false && -f $LIB && -L $GMP_LINK && -f $STAMP && $(head -n1 "$STAMP") == "$stamp" ]] &&
[[ $(sed -n 2p "$STAMP") == "$(sha256sum "$LIB" | cut -d' ' -f1)" ]]; then
say "Widevine $WIDEVINE_VERSION is installed"
exit 0
fi

mkdir -p "$STATE" "$CACHE"
image=$CACHE/lacros-$LACROS_VERSION.squashfs
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved
work=$(mktemp -d)
trap 'rm -rf "$work"' EXIT

if [[ ! -f $image ]] || ! sha256sum --quiet -c - <<<"$LACROS_SHA256 $image" 2>/dev/null; then
say "downloading ChromeOS Lacros $LACROS_VERSION from Google"
status=0
curl --fail --location --silent --show-error --continue-at - --retry 3 --retry-delay 10 \
--connect-timeout 30 --output "$image.part" "$LACROS_URL" || status=$?
case $status in
0) ;;
5 | 6 | 7 | 28 | 35 | 52 | 55 | 56)
say "no network (curl exit $status); widevine-fetch.timer will try again"
exit 0 ;;
*) rm -f "$image.part"; say "download failed (curl exit $status)" >&2; exit 1 ;;
esac
if ! sha256sum --quiet -c - <<<"$LACROS_SHA256 $image.part"; then
rm -f "$image.part"
say "the download does not match its pinned sha256; nothing installed" >&2
exit 1
fi
mv -f "$image.part" "$image"
fi

unsquashfs -q -n -d "$work/root" "$image" 'WidevineCdm/_platform_specific/cros_arm64/libwidevinecdm.so'
python3 -I /usr/lib/widevine/widevine_fixup.py \
"$work/root/WidevineCdm/_platform_specific/cros_arm64/libwidevinecdm.so" "$work/libwidevinecdm.so" >/dev/null

install -Dm755 "$work/libwidevinecdm.so" "$LIB.new"
mv -f "$LIB.new" "$LIB"
[[ -e $PLACEHOLDER ]] || install -Dm644 /dev/null "$PLACEHOLDER"
ln -sfn ../../../chromium/_platform_specific/linux_arm64/libwidevinecdm.so "$GMP_LINK"
printf '%s\n%s\n' "$stamp" "$(sha256sum "$LIB" | cut -d' ' -f1)" > "$STAMP"
rm -f "$CACHE"/lacros-*.squashfs "$CACHE"/lacros-*.part
say "installed Widevine $WIDEVINE_VERSION; restart Chromium or Firefox to use it"
19 changes: 19 additions & 0 deletions pkgbuilds/widevine/widevine-fetch.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[Unit]
Description=Fetch the Widevine CDM from Google
Wants=network-online.target
After=network-online.target

[Service]
Type=oneshot
ExecStart=/usr/bin/widevine-fetch
StateDirectory=widevine
CacheDirectory=widevine
RuntimeDirectory=widevine
RuntimeDirectoryPreserve=yes
ProtectSystem=strict
ReadWritePaths=/opt/WidevineCdm
ProtectHome=true
PrivateTmp=true
NoNewPrivileges=true
Nice=10
IOSchedulingClass=idle
10 changes: 10 additions & 0 deletions pkgbuilds/widevine/widevine-fetch.timer
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Unit]
Description=Fetch the Widevine CDM once the network is up

[Timer]
OnBootSec=2min
OnUnitInactiveSec=1h
RandomizedDelaySec=5min

[Install]
WantedBy=timers.target
47 changes: 47 additions & 0 deletions pkgbuilds/widevine/widevine.install
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Never fetch here: an image build installs this package in a chroot.
# Outside one, start the timer so widevine-fetch.service runs on its own.
_widevine_schedule() {
if [ -d /run/systemd/system ] && ! systemd-detect-virt --quiet --chroot; then
systemctl --no-block start widevine-fetch.timer >/dev/null 2>&1 || true
fi
echo ":: Widevine is downloaded from Google once the network is up."
echo " Run 'sudo widevine-fetch' to fetch it now, then restart the browser."
}

post_install() {
_widevine_schedule
}

post_upgrade() {
_widevine_schedule
}

_widevine_cleanup() {
rm -f /opt/WidevineCdm/chromium/_platform_specific/linux_arm64/libwidevinecdm.so \
/opt/WidevineCdm/chromium/_platform_specific/linux_arm64/libwidevinecdm.so.new \
/opt/WidevineCdm/chromium/_platform_specific/linux_x64/libwidevinecdm.so \
/opt/WidevineCdm/firefox/gmp-widevinecdm/system-installed/libwidevinecdm.so
rm -rf /var/lib/widevine /var/cache/widevine
}

# Stop the units, then take widevine-fetch's lock so no fetch is mid-install
# while the fetched files are deleted.
pre_remove() {
if [ -d /run/systemd/system ] && ! systemd-detect-virt --quiet --chroot; then
systemctl stop widevine-fetch.timer widevine-fetch.service >/dev/null 2>&1 || true
fi
mkdir -p /run/widevine
(flock -w 600 9 || true; _widevine_cleanup) 9>/run/widevine/fetch.lock
}

# A manual fetch that started before removal stops once the package is gone,
# but clean up after it anyway, along with the directories it leaves.
post_remove() {
_widevine_cleanup
rmdir /opt/WidevineCdm/chromium/_platform_specific/linux_arm64 \
/opt/WidevineCdm/chromium/_platform_specific/linux_x64 \
/opt/WidevineCdm/chromium/_platform_specific /opt/WidevineCdm/chromium \
/opt/WidevineCdm/firefox/gmp-widevinecdm/system-installed \
/opt/WidevineCdm/firefox/gmp-widevinecdm /opt/WidevineCdm/firefox /opt/WidevineCdm 2>/dev/null || true
rm -rf /run/widevine
}
Loading
Loading