commit c8ec3ce4ab1a0b469c3bb7f80e6bf748a4ddcc85
parent 685a2709317c4b8f8d4e174a86256c51d09231d7
Author: Divan Visagie <me@divanv.com>
Date: Sat, 28 Nov 2026 01:46:47 +0100
firefox: a new profile starts with the new tab widgets off, as the user's own prefs (ADR-0018)
What the user asked for: no widgets on the new tab page, as in the state they made by hand, without taking
the choice away from anyone later.
Why it cannot be a default: I tried every unlocked default Firefox offers, and read back the real value from a
running Firefox each time. The policy engine (Preferences, FirefoxHome.Widgets), a default-pref file (which
does load: a sentinel pref in it arrived) and the market-gate pref all left widgets.enabled and the individual
widgets at true. Firefox computes those defaults itself, after all of those have run, and the computed value
wins. The only other route is to lock them off, which would take the choice away.
What this does instead: patina-firefox-theme, which already runs at login for the Firefox theme, now also
makes the profile when the machine has none at all, before Firefox's first start, with the widgets, weather
and master switch already off in its prefs.js, as the person's own values (exactly what switching them off in
Customize leaves behind). It also writes installs.ini, because Firefox picks its profile through that file and
ignored mine without it (first try: it made a second profile and left mine unused). The install key in it,
11457493C5A56847, is a hash of Firefox's install path; Firefox in the image writes the same one, as it does on
the user's machine.
It is applied once and then belongs to the person: the script does nothing when profiles.ini exists, so a login
or an update never touches a profile, and a profile that already exists (the user's test machine, an older
install) is not seeded at all. Side effect: a first start is also themed, because the theme now goes into the
profile before Firefox has run.
Tried against a real Firefox in the image: no profile, script, then Firefox with no -profile flag: it adopts
the profile (the only one on disk), widgets, clocks, lists and weather read false and are the user's values, the
account and VPN buttons are absent, vertical tabs on, 0 bookmarks. A user turning widgets and clocks on and
Firefox closing cleanly: still on after the next start. (My first run of that check failed because I killed
Firefox before it saved; it was the test, not the design, and the clean-quit version passes.) And a user putting
the account button back in the toolbar: it stays after a restart.
linux/tests/patina-firefox-theme.sh is new and runs in `make check`: 11 cases: a fresh machine gets one
profile mapped to the install, seeded and themed; a second login changes nothing; the user's own changed value is
not put back; an existing profile keeps its prefs.js and profiles.ini and gets no second profile; a profile under
~/.mozilla counts as a profile; the user's own userChrome rules and a do-not-manage gtk.css are kept.
Diffstat:
4 files changed, 109 insertions(+), 1 deletion(-)
diff --git a/Makefile b/Makefile
@@ -45,10 +45,11 @@ iso-ssh: ## A root shell in the ISO VM (needs an ISO built with DEBUG=1; or: mak
iso-reset: ## Stop the ISO VM and blank its two drives
linux/live/try.sh reset
-check: ## Tests and clippy for the greeter, the installer and the updater
+check: ## Tests and clippy for the greeter, the installer and the updater, and the login script's tests
$(MAKE) -C greeter check
$(MAKE) -C installer check
$(MAKE) -C updater check
+ sh linux/tests/patina-firefox-theme.sh
publish: ## Push the image `make build` made to ghcr.io/sector-f-labs (the only target that pushes)
linux/publish.sh
diff --git a/docs/adr/0018-firefox-is-the-browser-and-themed-to-patina.md b/docs/adr/0018-firefox-is-the-browser-and-themed-to-patina.md
@@ -60,6 +60,21 @@ system-wide place for it.
Compared on the machine with a throwaway Firefox profile: without the block the wedge shows; with
it the outline follows the page's corner.
+- **A new profile starts with the new tab widgets off, as the user's own values.** Clocks, timer, lists,
+ weather and the widgets master switch cannot be a default: Firefox works out their defaults itself, after
+ the policy engine and the default-pref files have run (the market gate in the new tab code), and the value
+ it computes wins. Tried and failed: the `Preferences` policy, `FirefoxHome.Widgets`, a default-pref file in
+ Firefox's folder (which does load), and the market-gate pref. The only other way is to lock them, which takes
+ the choice away. So `patina-firefox-theme`, at login, **when there is no Firefox profile at all**, makes the
+ profile before Firefox's first start, with those prefs in its `prefs.js`, mapped to this install in
+ `installs.ini` (the key, `11457493C5A56847`, is a hash of `/usr/lib64/firefox`; Firefox writes it itself;
+ without it Firefox ignored the profile and made another). It is the state a person who switches the widgets
+ off in Customize ends up in. From then on the values are theirs: the script does nothing when a profile
+ exists, so no login or update changes it. Tried: the first start adopts the profile (the only one on disk),
+ and a pref the user changes stays changed after a clean restart. A first start is also themed, since the
+ theme goes into the profile before Firefox runs. Tested in `linux/tests/patina-firefox-theme.sh`.
+ A machine that already has a profile (one that was set up by hand, or an older install) is not seeded.
+
## Tried and rejected
- **A system-wide GTK CSS file** (`/etc/xdg/gtk-3.0/gtk.css`, through `XDG_CONFIG_DIRS`): GTK3 did not
diff --git a/linux/system/usr/libexec/patina-firefox-theme b/linux/system/usr/libexec/patina-firefox-theme
@@ -39,6 +39,44 @@ EOF
[ "$(cat "$gtk")" = "$new" ] || printf '%s\n' "$new" > "$gtk"
fi
+# A machine with no Firefox profile yet gets one made for it, with a few of the new tab page's
+# settings already the user's own (ADR-0018). Why not defaults: Firefox works out the new tab
+# widgets' defaults itself after policies and pref files have run, so a default cannot keep them off
+# (and the only other way, locking them, would take the choice away). A profile that starts with
+# the values in it is exactly what a person who switches them off in Customize ends up with, and
+# from then on the values are theirs: this runs only when there is no profiles.ini at all, so it never
+# touches a profile that exists, and an update never changes one.
+seed_new_profile() {
+ config=${XDG_CONFIG_HOME:-$HOME/.config}
+ root=$config/mozilla/firefox
+ [ -e "$root/profiles.ini" ] || [ -e "$HOME/.mozilla/firefox/profiles.ini" ] && return 0
+ # Firefox running with no profiles.ini cannot happen, but never write under one that is starting.
+ ! pgrep -u "$(id -u)" -x firefox >/dev/null 2>&1 || return 0
+ dir=patina.default-release
+ mkdir -p "$root/$dir"
+ cat > "$root/$dir/prefs.js" <<'EOF'
+// Mozilla User Preferences
+// Seeded once by patina-firefox-theme when this profile was made (ADR-0018). These are the user's
+// own now: change them in Firefox's Customize or Settings, and they stay as changed.
+user_pref("browser.newtabpage.activity-stream.widgets.enabled", false);
+user_pref("browser.newtabpage.activity-stream.widgets.clocks.enabled", false);
+user_pref("browser.newtabpage.activity-stream.widgets.focusTimer.enabled", false);
+user_pref("browser.newtabpage.activity-stream.widgets.lists.enabled", false);
+user_pref("browser.newtabpage.activity-stream.widgets.sportsWidget.enabled", false);
+user_pref("browser.newtabpage.activity-stream.widgets.weather.enabled", false);
+user_pref("browser.newtabpage.activity-stream.showWeather", false);
+EOF
+ # Firefox picks its profile through installs.ini, which maps this installation to one; the key is
+ # a hash of the install path, the same on every Fedora machine (Firefox writes this one itself).
+ # Without it Firefox would not use this profile and would make another. The files are written the
+ # way Firefox writes them, profiles.ini last: it is what says the profile exists.
+ install=11457493C5A56847
+ printf '[%s]\nDefault=%s\nLocked=1\n' "$install" "$dir" > "$root/installs.ini"
+ printf '[Install%s]\nDefault=%s\nLocked=1\n\n[Profile0]\nName=default-release\nIsRelative=1\nPath=%s\n\n[General]\nStartWithLastProfile=1\nVersion=2\n' "$install" "$dir" "$dir" > "$root/profiles.ini.new"
+ mv "$root/profiles.ini.new" "$root/profiles.ini"
+}
+seed_new_profile
+
theme=patina-default
src=/usr/share/patina-os/firefox/$theme.css
[ -f "$src" ] || exit 0
diff --git a/linux/tests/patina-firefox-theme.sh b/linux/tests/patina-firefox-theme.sh
@@ -0,0 +1,54 @@
+#!/bin/sh
+# Tests patina-firefox-theme (linux/system/usr/libexec/): what it does to a home folder at login.
+# It runs the script against throwaway home folders, with the system's CSS file and `pgrep` stood in.
+# Usage: sh linux/tests/patina-firefox-theme.sh
+here=$(cd "$(dirname "$0")" && pwd)
+script=$here/../system/usr/libexec/patina-firefox-theme
+css=$here/../system/usr/share/patina-os/firefox/patina-default.css
+tmp=$(mktemp -d); trap 'rm -rf "$tmp"' EXIT
+mkdir -p "$tmp/share" "$tmp/bin"; cp "$css" "$tmp/share/"
+sed "s#/usr/share/patina-os/firefox#$tmp/share#" "$script" > "$tmp/run.sh"
+printf '#!/bin/sh\nexit 1\n' > "$tmp/bin/pgrep"; chmod +x "$tmp/bin/pgrep" # no Firefox is running
+run() { HOME=$1 XDG_CONFIG_HOME= PATH="$tmp/bin:$PATH" sh "$tmp/run.sh"; }
+fail=0
+check() { if eval "$2"; then echo "ok $1"; else echo "FAIL $1"; fail=1; fi; }
+snapshot() { (cd "$1" && find . -type f | sort | xargs md5sum | md5sum); }
+
+# 1. A machine with no Firefox profile: one is made, seeded, mapped to this install, and themed.
+h=$tmp/fresh; mkdir -p "$h"; run "$h"; r=$h/.config/mozilla/firefox; p=$r/patina.default-release
+check "a fresh machine gets one profile, and profiles.ini and installs.ini say it is the install's" \
+ '[ "$(ls -d $r/*.default-release | wc -l)" = 1 ] && grep -q "Default=patina.default-release" $r/installs.ini && grep -q "Path=patina.default-release" $r/profiles.ini && grep -q "^\[Install11457493C5A56847\]" $r/profiles.ini'
+check "the new tab widgets and weather are off in it, as the user's own prefs" \
+ 'for k in widgets.enabled widgets.clocks.enabled widgets.focusTimer.enabled widgets.lists.enabled widgets.sportsWidget.enabled widgets.weather.enabled; do grep -q "user_pref(\"browser.newtabpage.activity-stream.$k\", false);" $p/prefs.js || exit 1; done; grep -q "showWeather\", false" $p/prefs.js'
+check "it is themed before Firefox has ever started (the import first in userChrome.css)" \
+ '[ "$(head -n 1 $p/chrome/userChrome.css)" = "@import url(\"patina-default.css\");" ] && [ -f $p/chrome/patina-default.css ]'
+check "the GTK corner block is written" 'grep -q ">>> patina" $h/.config/gtk-3.0/gtk.css'
+before=$(snapshot "$h"); run "$h"
+check "a second run (the next login) changes nothing" '[ "$before" = "$(snapshot "$h")" ]'
+
+# 2. A user who has changed a seeded pref, then logs in again: their value stays.
+sed -i 's/widgets.enabled", false/widgets.enabled", true/' "$p/prefs.js"; run "$h"
+check "the user's own value is not put back at the next login" 'grep -q "widgets.enabled\", true" $p/prefs.js'
+
+# 3. A machine that already has a profile: left alone (themed, not seeded or replaced).
+h=$tmp/existing; r=$h/.config/mozilla/firefox; mkdir -p "$r/abc.default-release"
+printf '[Profile0]\nName=x\nIsRelative=1\nPath=abc.default-release\nDefault=1\n' > "$r/profiles.ini"
+echo 'user_pref("browser.newtabpage.activity-stream.widgets.enabled", true);' > "$r/abc.default-release/prefs.js"
+ini=$(md5sum < "$r/profiles.ini"); prefs=$(md5sum < "$r/abc.default-release/prefs.js"); run "$h"
+check "an existing profile keeps its prefs.js and profiles.ini, and no second profile appears" \
+ '[ "$ini" = "$(md5sum < $r/profiles.ini)" ] && [ "$prefs" = "$(md5sum < $r/abc.default-release/prefs.js)" ] && [ "$(ls -d $r/*.default* | wc -l)" = 1 ] && [ ! -e $r/installs.ini ]'
+check "but it is themed" '[ -f $r/abc.default-release/chrome/patina-default.css ]'
+
+# 4. The older profile location counts as "has a profile" too.
+h=$tmp/legacy; mkdir -p "$h/.mozilla/firefox"; printf '[Profile0]\nPath=x\n' > "$h/.mozilla/firefox/profiles.ini"; run "$h"
+check "a profile under ~/.mozilla is not mistaken for none" '[ ! -e $h/.config/mozilla/firefox/profiles.ini ]'
+
+# 5. The user's own CSS survives, and a do-not-manage line is respected.
+h=$tmp/css; r=$h/.config/mozilla/firefox; mkdir -p "$r/p.default/chrome" "$h/.config/gtk-3.0"
+printf '[Profile0]\nPath=p.default\nIsRelative=1\n' > "$r/profiles.ini"; printf '#nav-bar { color: red; }\n' > "$r/p.default/chrome/userChrome.css"
+printf '/* patina: do not manage */\nbutton { color: red; }\n' > "$h/.config/gtk-3.0/gtk.css"; run "$h"
+check "the user's own userChrome rules are kept, with the import first" 'grep -q "color: red" $r/p.default/chrome/userChrome.css && [ "$(head -n 1 $r/p.default/chrome/userChrome.css)" = "@import url(\"patina-default.css\");" ]'
+check "a gtk.css with the do-not-manage line is left alone" '! grep -q ">>> patina" $h/.config/gtk-3.0/gtk.css'
+
+[ $fail = 0 ] && echo "patina-firefox-theme does what it should"
+exit $fail