firefox: add preConfig

Add `preConfig`, which acts like `extraConfig`, but placed before `settings`.
This will allow to overwrite settings in `preConfig`, using `settings` option.
This commit is contained in:
Danil Suetin 2024-07-11 14:27:27 +02:00
parent 90ae324e2c
commit 5520739d0a
No known key found for this signature in database
GPG key ID: 9076417E3D01C1B0
5 changed files with 50 additions and 5 deletions

View file

@ -60,7 +60,7 @@ let
else else
builtins.toJSON pref); builtins.toJSON pref);
mkUserJs = prefs: extraPrefs: bookmarks: mkUserJs = prePrefs: prefs: extraPrefs: bookmarks:
let let
prefs' = lib.optionalAttrs ([ ] != bookmarks) { prefs' = lib.optionalAttrs ([ ] != bookmarks) {
"browser.bookmarks.file" = toString (firefoxBookmarksFile bookmarks); "browser.bookmarks.file" = toString (firefoxBookmarksFile bookmarks);
@ -69,6 +69,8 @@ let
in '' in ''
// Generated by Home Manager. // Generated by Home Manager.
${prePrefs}
${concatStrings (mapAttrsToList (name: value: '' ${concatStrings (mapAttrsToList (name: value: ''
user_pref("${name}", ${userPrefValue value}); user_pref("${name}", ${userPrefValue value});
'') prefs')} '') 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.<profile>.settings`](#opt-programs.firefox.profiles._name_.settings).
Use [{option}`programs.firefox.profiles.<profile>.extraConfig`](#opt-programs.firefox.profiles._name_.extraConfig),
unless you want to overwrite in
[{option}`programs.firefox.profiles.<profile>.settings`](#opt-programs.firefox.profiles._name_.settings)
'';
};
settings = mkOption { settings = mkOption {
type = types.attrsOf (jsonFormat.type // { type = types.attrsOf (jsonFormat.type // {
description = description =
@ -770,10 +785,11 @@ in {
"${profilesPath}/${profile.path}/chrome/userContent.css" = "${profilesPath}/${profile.path}/chrome/userContent.css" =
mkIf (profile.userContent != "") { text = profile.userContent; }; mkIf (profile.userContent != "") { text = profile.userContent; };
"${profilesPath}/${profile.path}/user.js" = mkIf (profile.settings != { } "${profilesPath}/${profile.path}/user.js" = mkIf (profile.preConfig != ""
|| profile.extraConfig != "" || profile.bookmarks != [ ]) { || profile.settings != { } || profile.extraConfig != ""
text = || profile.bookmarks != [ ]) {
mkUserJs profile.settings profile.extraConfig profile.bookmarks; text = mkUserJs profile.preConfig profile.settings profile.extraConfig
profile.bookmarks;
}; };
"${profilesPath}/${profile.path}/containers.json" = "${profilesPath}/${profile.path}/containers.json" =

View file

@ -1,5 +1,7 @@
// Generated by Home Manager. // Generated by Home Manager.
user_pref("browser.bookmarks.file", "/nix/store/00000000000000000000000000000000-firefox-bookmarks.html"); user_pref("browser.bookmarks.file", "/nix/store/00000000000000000000000000000000-firefox-bookmarks.html");
user_pref("browser.places.importBookmarksHTML", true); user_pref("browser.places.importBookmarksHTML", true);
user_pref("general.smoothScroll", false); user_pref("general.smoothScroll", false);

View file

@ -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);

View file

@ -1,5 +1,7 @@
// Generated by Home Manager. // Generated by Home Manager.
user_pref("browser.newtabpage.pinned", "[{\"title\":\"NixOS\",\"url\":\"https://nixos.org\"}]"); user_pref("browser.newtabpage.pinned", "[{\"title\":\"NixOS\",\"url\":\"https://nixos.org\"}]");
user_pref("general.smoothScroll", false); user_pref("general.smoothScroll", false);

View file

@ -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 = '' nmt.script = ''
@ -203,6 +214,10 @@
assertFirefoxSearchContent \ assertFirefoxSearchContent \
home-files/.mozilla/firefox/searchWithoutDefault/search.json.mozlz4 \ home-files/.mozilla/firefox/searchWithoutDefault/search.json.mozlz4 \
${./profile-settings-expected-search-without-default.json} ${./profile-settings-expected-search-without-default.json}
assertFileContent \
home-files/.mozilla/firefox/overwrite/user.js \
${./profile-settings-expected-overwrite-user.js}
''; '';
}; };
} }