diff --git a/modules/programs/firefox.nix b/modules/programs/firefox.nix index 1370d4c2..d4da9477 100644 --- a/modules/programs/firefox.nix +++ b/modules/programs/firefox.nix @@ -60,7 +60,7 @@ let else builtins.toJSON pref); - mkUserJs = prefs: extraPrefs: bookmarks: + mkUserJs = prePrefs: prefs: extraPrefs: bookmarks: let prefs' = lib.optionalAttrs ([ ] != bookmarks) { "browser.bookmarks.file" = toString (firefoxBookmarksFile bookmarks); @@ -69,6 +69,8 @@ let in '' // Generated by Home Manager. + ${prePrefs} + ${concatStrings (mapAttrsToList (name: value: '' user_pref("${name}", ${userPrefValue value}); '') prefs')} @@ -305,6 +307,19 @@ in { ''; }; + preConfig = mkOption { + type = types.lines; + default = ""; + description = '' + Extra preferences to add to {file}`user.js`, before + [{option}`programs.firefox.profiles..settings`](#opt-programs.firefox.profiles._name_.settings). + + Use [{option}`programs.firefox.profiles..extraConfig`](#opt-programs.firefox.profiles._name_.extraConfig), + unless you want to overwrite in + [{option}`programs.firefox.profiles..settings`](#opt-programs.firefox.profiles._name_.settings) + ''; + }; + settings = mkOption { type = types.attrsOf (jsonFormat.type // { description = @@ -770,10 +785,11 @@ in { "${profilesPath}/${profile.path}/chrome/userContent.css" = mkIf (profile.userContent != "") { text = profile.userContent; }; - "${profilesPath}/${profile.path}/user.js" = mkIf (profile.settings != { } - || profile.extraConfig != "" || profile.bookmarks != [ ]) { - text = - mkUserJs profile.settings profile.extraConfig profile.bookmarks; + "${profilesPath}/${profile.path}/user.js" = mkIf (profile.preConfig != "" + || profile.settings != { } || profile.extraConfig != "" + || profile.bookmarks != [ ]) { + text = mkUserJs profile.preConfig profile.settings profile.extraConfig + profile.bookmarks; }; "${profilesPath}/${profile.path}/containers.json" = diff --git a/tests/modules/programs/firefox/profile-settings-expected-bookmarks-user.js b/tests/modules/programs/firefox/profile-settings-expected-bookmarks-user.js index 922d3651..8ffd7696 100644 --- a/tests/modules/programs/firefox/profile-settings-expected-bookmarks-user.js +++ b/tests/modules/programs/firefox/profile-settings-expected-bookmarks-user.js @@ -1,5 +1,7 @@ // Generated by Home Manager. + + user_pref("browser.bookmarks.file", "/nix/store/00000000000000000000000000000000-firefox-bookmarks.html"); user_pref("browser.places.importBookmarksHTML", true); user_pref("general.smoothScroll", false); diff --git a/tests/modules/programs/firefox/profile-settings-expected-overwrite-user.js b/tests/modules/programs/firefox/profile-settings-expected-overwrite-user.js new file mode 100644 index 00000000..cbcc5f26 --- /dev/null +++ b/tests/modules/programs/firefox/profile-settings-expected-overwrite-user.js @@ -0,0 +1,10 @@ +// Generated by Home Manager. + +user_pref("browser.search.suggest.enabled", false); + + +user_pref("browser.search.suggest.enabled", true); + + +user_pref("findbar.highlightAll", true); + diff --git a/tests/modules/programs/firefox/profile-settings-expected-user.js b/tests/modules/programs/firefox/profile-settings-expected-user.js index d929df2b..8118d73b 100644 --- a/tests/modules/programs/firefox/profile-settings-expected-user.js +++ b/tests/modules/programs/firefox/profile-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); diff --git a/tests/modules/programs/firefox/profile-settings.nix b/tests/modules/programs/firefox/profile-settings.nix index 8b781552..7a83ed77 100644 --- a/tests/modules/programs/firefox/profile-settings.nix +++ b/tests/modules/programs/firefox/profile-settings.nix @@ -153,6 +153,17 @@ }; }; }; + + profiles.overwrite = { + id = 6; + preConfig = '' + user_pref("browser.search.suggest.enabled", false); + ''; + settings = { "browser.search.suggest.enabled" = true; }; + extraConfig = '' + user_pref("findbar.highlightAll", true); + ''; + }; }; nmt.script = '' @@ -203,6 +214,10 @@ assertFirefoxSearchContent \ home-files/.mozilla/firefox/searchWithoutDefault/search.json.mozlz4 \ ${./profile-settings-expected-search-without-default.json} + + assertFileContent \ + home-files/.mozilla/firefox/overwrite/user.js \ + ${./profile-settings-expected-overwrite-user.js} ''; }; }