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, ... }: { pkgs, ... }:
let let
# 1. Policies (Extensions & Locks)
# policies.json is best for installing extensions and hard-locking features.
policiesJson = builtins.toJSON { policiesJson = builtins.toJSON {
policies = { policies = {
DisableTelemetry = true; DisableTelemetry = true;
@@ -9,14 +11,17 @@ let
DisableFirefoxAccounts = true; DisableFirefoxAccounts = true;
ExtensionSettings = { ExtensionSettings = {
# Bitwarden
"{446900e4-71c2-419f-a6a7-df9c091e268b}" = { "{446900e4-71c2-419f-a6a7-df9c091e268b}" = {
install_url = "https://addons.mozilla.org/firefox/downloads/latest/bitwarden-password-manager/latest.xpi"; install_url = "https://addons.mozilla.org/firefox/downloads/latest/bitwarden-password-manager/latest.xpi";
installation_mode = "force_installed"; installation_mode = "force_installed";
}; };
# Floccus
"floccus@handmadeideas.org" = { "floccus@handmadeideas.org" = {
install_url = "https://addons.mozilla.org/firefox/downloads/latest/floccus/latest.xpi"; install_url = "https://addons.mozilla.org/firefox/downloads/latest/floccus/latest.xpi";
installation_mode = "force_installed"; installation_mode = "force_installed";
}; };
# uBlock Origin
"uBlock0@raymondhill.net" = { "uBlock0@raymondhill.net" = {
install_url = "https://addons.mozilla.org/firefox/downloads/latest/ublock-origin/latest.xpi"; install_url = "https://addons.mozilla.org/firefox/downloads/latest/ublock-origin/latest.xpi";
installation_mode = "force_installed"; installation_mode = "force_installed";
@@ -27,43 +32,59 @@ let
policiesFile = pkgs.writeText "librewolf-policies.json" policiesJson; policiesFile = pkgs.writeText "librewolf-policies.json" policiesJson;
autoconfigLoader = pkgs.writeText "autoconfig.js" '' # 2. User Preferences (user.js)
pref("general.config.filename", "autoconfig.cfg"); # These are applied to the profile directly.
pref("general.config.obscure_value", 0); # 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" '' // UI Tweaks
// First line must be a comment user_pref("sidebar.revamp", true);
lockPref("extensions.activeThemeID", "firefox-alpenglow@mozilla.org"); 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 // Privacy
lockPref("sidebar.revamp", true); user_pref("privacy.clearOnShutdown.cookies", false);
lockPref("sidebar.verticalTabs", true); user_pref("privacy.clearOnShutdown.history", false);
''; '';
in in
{ {
# Activation script to apply both Policies (System) and user.js (Profile)
system.activationScripts.postActivation.text = '' 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 if [ -d "$APP_DIR" ]; then
echo ">>> Applying LibreWolf Policies & AutoConfig..." echo ">>> Setting LibreWolf policies in $APP_DIR..."
DIST_DIR="$APP_DIR/Contents/Resources/distribution" DIST_DIR="$APP_DIR/Contents/Resources/distribution"
mkdir -p "$DIST_DIR" mkdir -p "$DIST_DIR"
cp -f ${policiesFile} "$DIST_DIR/policies.json" cp -f ${policiesFile} "$DIST_DIR/policies.json"
chmod 644 "$DIST_DIR/policies.json" chmod 644 "$DIST_DIR/policies.json"
fi
done
PREF_DIR="$APP_DIR/Contents/Resources/defaults/pref" # 2. Apply user.js to the User Profile
mkdir -p "$PREF_DIR" # LibreWolf profiles are in ~/Library/Application Support/LibreWolf/Profiles/
cp -f ${autoconfigLoader} "$PREF_DIR/autoconfig.js" LIBREWOLF_DATA="$HOME/Library/Application Support/LibreWolf/Profiles"
chmod 644 "$PREF_DIR/autoconfig.js" 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" # Fallback to *.default if release not found
chmod 644 "$APP_DIR/Contents/Resources/autoconfig.cfg" 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 else
echo ">>> LibreWolf.app not found. Skipping." echo ">>> Warning: Could not find a default LibreWolf profile to apply user.js"
fi
fi fi
''; '';
} }