refactor(nixos): simplify Firefox configuration

This commit was merged in pull request #143.
This commit is contained in:
2026-10-07 22:57:25 -04:00
parent 79c56dfb1c
commit 4908c4751f

View File

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