refactor(nixos): simplify Firefox configuration #143

Merged
alexion merged 1 commits from refactor/simplify-firefox-module into main 2026-10-07 23:01:21 -04:00
Showing only changes of commit 4908c4751f - Show all commits

View File

@@ -5,11 +5,9 @@
pkgs,
...
}:
# Firefox as the desktop browser: stock mainline, hardened and de-monetized by policy.
# Configures Firefox as the desktop browser.
let
cfg = config.modules.desktop.apps.firefox; # NOLINT(let_order)
firefoxAddons = inputs.firefox-addons.packages.${pkgs.stdenv.hostPlatform.system};
user = config.user.name;
in
{
options.modules.desktop.apps.firefox = {
@@ -19,19 +17,20 @@ in
type = lib.types.str;
default = "1.0";
description = ''
Firefox UI and page scale, passed to `layout.css.devPixelsPerPx`.
Override it on hosts that need a larger browser scale, such as small
high-DPI laptop panels.
Scales Firefox UI and page content.
Sets `layout.css.devPixelsPerPx`.
Use a larger value for high-DPI displays.
'';
};
};
config = lib.mkIf cfg.enable {
home-manager.users.${user} = hm: {
home-manager.users.${config.user.name} = hm: {
programs.firefox = {
enable = true;
# Enterprise policies: enforced and unchangeable from the browser UI.
# Applies policies that users cannot change in Firefox.
policies = {
DisableTelemetry = true;
DisableFirefoxStudies = true;
@@ -40,7 +39,7 @@ in
DontCheckDefaultBrowser = true;
DisableFirefoxAccounts = true;
# Strip the monetized surfaces from the new-tab page.
# Removes sponsored content from the new-tab page.
FirefoxHome = {
SponsoredTopSites = false;
SponsoredPocket = false;
@@ -49,23 +48,19 @@ in
};
profiles.default = {
isDefault = true;
extensions = {
packages = with firefoxAddons; [
packages = with inputs.firefox-addons.packages.${pkgs.stdenv.hostPlatform.system}; [
ublock-origin
proton-pass
sponsorblock
];
# The Nord chrome theme is a declared extension setting, so home-manager
# owns the extension-settings store, overwriting runtime changes to it.
# Home Manager overwrites Nord theme changes made in Firefox.
force = true;
};
# Stylix's Nord mapping paints the selected address-bar result a
# near-white grey, leaving its light text unreadable. Darken that one
# highlight to the Nord selection grey, from the same scheme.
# Stylix uses a near-white selection background.
# Use the Nord selection color because its text stays readable.
extensions.settings."FirefoxColor@mozilla.com".settings.theme.colors.popup_highlight =
let
c = hm.config.lib.stylix.colors;
@@ -77,32 +72,26 @@ in
};
settings = {
# Scale the UI and page by a fixed factor.
# Left at auto (-1), Firefox reads the panel's 1.5x and inflates its
# whole chrome while point-sized apps stay put.
# A shade under that brings it into line without dropping to true
# 1:1, which reads too small at this DPI.
"layout.css.devPixelsPerPx" = cfg.uiScale;
# Auto-enable the sideloaded Firefox Color add-on carrying the Nord
# chrome theme, which Firefox otherwise leaves disabled.
# Enables Firefox Color after Firefox sideloads the add-on.
"extensions.autoDisableScopes" = 0;
# Sponsored surfaces the policies above do not reach.
# Removes sponsored content outside Firefox policies.
"browser.urlbar.suggest.quicksuggest.sponsored" = false;
"browser.newtabpage.activity-stream.showSponsored" = false;
"browser.newtabpage.activity-stream.showSponsoredTopSites" = false;
};
search = {
# Declaring search overwrites Firefox's own engine list wholesale,
# so engines added later in the UI do not survive a rebuild.
# Home Manager replaces the engine list when this setting is enabled.
# Engines added in Firefox do not survive a rebuild.
force = true;
default = "ddg";
# The general-purpose commercial engines, hidden to leave a lean
# DuckDuckGo-and-Wikipedia list. They stay reachable through bangs.
# An engine carrying only metaData is treated as a builtin.
# Hides commercial search engines.
# Bangs still reach these engines.
# Entries with only `metaData` configure Firefox built-in engines.
engines = {
google.metaData.hidden = true;
bing.metaData.hidden = true;
@@ -114,8 +103,7 @@ in
};
};
# Nord chrome for the one profile, applied through the Stylix-managed
# Firefox Color add-on that colorTheme enables.
# Applies the Nord theme through Stylix's Firefox Color add-on.
stylix.targets.firefox = {
enable = true;
profileNames = [ "default" ];
@@ -133,8 +121,8 @@ in
};
};
# Firefox writes profiles.ini itself on first launch, so home-manager is
# told to own the file rather than fail activation refusing to clobber it.
# Firefox creates `profiles.ini` on its first launch.
# Force replacement during Home Manager activation.
home.file."${hm.config.programs.firefox.configPath}/profiles.ini".force = true;
};
};