diff --git a/modules/misc/news.nix b/modules/misc/news.nix index a0150bf32..779680ba0 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -1899,6 +1899,17 @@ in { registry with the option 'programs.nushell.plugins'. ''; } + + { + time = "2024-12-11T18:32+00:00"; + condition = config.programs.firefox.enable; + message = '' + The Firefox module now provides a + `programs.firefox.profiles..preConfig` option that allows an + arbitrary string to be added to `user.js` *before* the options + specified in `programs.firefox.profiles..settings`. + ''; + } ]; }; } diff --git a/modules/programs/firefox/mkFirefoxModule.nix b/modules/programs/firefox/mkFirefoxModule.nix index 1bb2253f1..5869b488b 100644 --- a/modules/programs/firefox/mkFirefoxModule.nix +++ b/modules/programs/firefox/mkFirefoxModule.nix @@ -75,7 +75,7 @@ let else builtins.toJSON pref); - mkUserJs = prefs: extraPrefs: bookmarks: + mkUserJs = prefs: prePrefs: extraPrefs: bookmarks: let prefs' = lib.optionalAttrs ([ ] != bookmarks) { "browser.bookmarks.file" = toString (browserBookmarksFile bookmarks); @@ -84,6 +84,8 @@ let in '' // Generated by Home Manager. + ${prePrefs} + ${concatStrings (mapAttrsToList (name: value: '' user_pref("${name}", ${userPrefValue value}); '') prefs')} @@ -406,6 +408,14 @@ in { ''; }; + preConfig = mkOption { + type = types.lines; + default = ""; + description = '' + Extra preferences to add to {file}`user.js` before those specified in `settings`. + ''; + }; + userChrome = mkOption { type = types.lines; default = ""; @@ -770,8 +780,8 @@ in { "${profilesPath}/${profile.path}/user.js" = mkIf (profile.settings != { } || profile.extraConfig != "" || profile.bookmarks != [ ]) { - text = - mkUserJs profile.settings profile.extraConfig profile.bookmarks; + text = mkUserJs profile.settings profile.preConfig profile.extraConfig + profile.bookmarks; }; "${profilesPath}/${profile.path}/containers.json" = diff --git a/tests/modules/programs/firefox/profiles/settings/expected-user.js b/tests/modules/programs/firefox/profiles/settings/expected-user.js index d929df2b3..8118d73bf 100644 --- a/tests/modules/programs/firefox/profiles/settings/expected-user.js +++ b/tests/modules/programs/firefox/profiles/settings/expected-user.js @@ -1,5 +1,7 @@ // Generated by Home Manager. + + user_pref("browser.newtabpage.pinned", "[{\"title\":\"NixOS\",\"url\":\"https://nixos.org\"}]"); user_pref("general.smoothScroll", false);