Update librewolf.nix

This commit is contained in:
2026-02-16 15:57:13 -07:00
parent 7b87de4700
commit ba6d171055

View File

@@ -1,6 +1,8 @@
{ pkgs, ... }:
let
# 1. Policies (Extensions & Locks)
# policies.json is best for installing extensions and hard-locking features.
policiesJson = builtins.toJSON {
policies = {
DisableTelemetry = true;
@@ -9,14 +11,17 @@ let
DisableFirefoxAccounts = true;
ExtensionSettings = {
# Bitwarden
"{446900e4-71c2-419f-a6a7-df9c091e268b}" = {
install_url = "https://addons.mozilla.org/firefox/downloads/latest/bitwarden-password-manager/latest.xpi";
installation_mode = "force_installed";
};
# Floccus
"floccus@handmadeideas.org" = {
install_url = "https://addons.mozilla.org/firefox/downloads/latest/floccus/latest.xpi";
installation_mode = "force_installed";
};
# uBlock Origin
"uBlock0@raymondhill.net" = {
install_url = "https://addons.mozilla.org/firefox/downloads/latest/ublock-origin/latest.xpi";
installation_mode = "force_installed";
@@ -27,43 +32,59 @@ let
policiesFile = pkgs.writeText "librewolf-policies.json" policiesJson;
autoconfigLoader = pkgs.writeText "autoconfig.js" ''
pref("general.config.filename", "autoconfig.cfg");
pref("general.config.obscure_value", 0);
'';
# 2. User Preferences (user.js)
# These are applied to the profile directly.
# This avoids code-signing issues with modifying the App Bundle.
userJs = pkgs.writeText "user.js" ''
// Force Alpenglow Theme
user_pref("extensions.activeThemeID", "firefox-alpenglow@mozilla.org");
autoconfigCfg = pkgs.writeText "autoconfig.cfg" ''
// First line must be a comment
lockPref("extensions.activeThemeID", "firefox-alpenglow@mozilla.org");
// UI Tweaks
user_pref("sidebar.revamp", true);
user_pref("sidebar.verticalTabs", true);
user_pref("sidebar.main.tools", "bookmarks,history,tabs");
user_pref("sidebar.visibility", "always");
// Other stubborn prefs can go here if needed
lockPref("sidebar.revamp", true);
lockPref("sidebar.verticalTabs", true);
// Privacy
user_pref("privacy.clearOnShutdown.cookies", false);
user_pref("privacy.clearOnShutdown.history", false);
'';
in
{
# Activation script to apply both Policies (System) and user.js (Profile)
system.activationScripts.postActivation.text = ''
APP_DIR="/Applications/LibreWolf.app"
# 1. Apply Policies to the App Bundle (Distribution folder is usually safe to modify)
# We check both standard locations
for APP_DIR in "/Applications/LibreWolf.app" "$HOME/Applications/LibreWolf.app"; do
if [ -d "$APP_DIR" ]; then
echo ">>> Applying LibreWolf Policies & AutoConfig..."
echo ">>> Setting LibreWolf policies in $APP_DIR..."
DIST_DIR="$APP_DIR/Contents/Resources/distribution"
mkdir -p "$DIST_DIR"
cp -f ${policiesFile} "$DIST_DIR/policies.json"
chmod 644 "$DIST_DIR/policies.json"
fi
done
PREF_DIR="$APP_DIR/Contents/Resources/defaults/pref"
mkdir -p "$PREF_DIR"
cp -f ${autoconfigLoader} "$PREF_DIR/autoconfig.js"
chmod 644 "$PREF_DIR/autoconfig.js"
# 2. Apply user.js to the User Profile
# LibreWolf profiles are in ~/Library/Application Support/LibreWolf/Profiles/
LIBREWOLF_DATA="$HOME/Library/Application Support/LibreWolf/Profiles"
if [ -d "$LIBREWOLF_DATA" ]; then
# Find the default release profile (usually ends in .default-release or .default)
PROFILE_DIR=$(find "$LIBREWOLF_DATA" -maxdepth 1 -type d -name "*.default-release" | head -n 1)
cp -f ${autoconfigCfg} "$APP_DIR/Contents/Resources/autoconfig.cfg"
chmod 644 "$APP_DIR/Contents/Resources/autoconfig.cfg"
# Fallback to *.default if release not found
if [ -z "$PROFILE_DIR" ]; then
PROFILE_DIR=$(find "$LIBREWOLF_DATA" -maxdepth 1 -type d -name "*.default" | head -n 1)
fi
echo ">>> Done."
if [ -n "$PROFILE_DIR" ]; then
echo ">>> Updating LibreWolf profile: $PROFILE_DIR"
# We cat the file to ensure we don't mess up symlinks or permissions logic
cat ${userJs} > "$PROFILE_DIR/user.js"
else
echo ">>> LibreWolf.app not found. Skipping."
echo ">>> Warning: Could not find a default LibreWolf profile to apply user.js"
fi
fi
'';
}