mirror of
https://github.com/nix-community/home-manager
synced 2024-12-27 12:19:48 +01:00
firefox: support passing any json value to settings (#3580)
Firefox internally only supports bool, int, and string types for preferences, but often stores objects, arrays and floats as strings. This change makes it nicer to specify those type of preferences in Nix, and it also makes it possible to merge objects & arrays across multiple modules.
This commit is contained in:
parent
e3f28ddb0d
commit
9f4268e6b6
3 changed files with 30 additions and 4 deletions
|
@ -42,6 +42,12 @@ let
|
|||
|
||||
profilesIni = generators.toINI { } profiles;
|
||||
|
||||
userPrefValue = pref:
|
||||
builtins.toJSON (if isBool pref || isInt pref || isString pref then
|
||||
pref
|
||||
else
|
||||
builtins.toJSON pref);
|
||||
|
||||
mkUserJs = prefs: extraPrefs: bookmarks:
|
||||
let
|
||||
prefs' = lib.optionalAttrs ([ ] != bookmarks) {
|
||||
|
@ -52,7 +58,7 @@ let
|
|||
// Generated by Home Manager.
|
||||
|
||||
${concatStrings (mapAttrsToList (name: value: ''
|
||||
user_pref("${name}", ${builtins.toJSON value});
|
||||
user_pref("${name}", ${userPrefValue value});
|
||||
'') prefs')}
|
||||
|
||||
${extraPrefs}
|
||||
|
@ -201,7 +207,10 @@ in {
|
|||
};
|
||||
|
||||
settings = mkOption {
|
||||
type = with types; attrsOf (either bool (either int str));
|
||||
type = types.attrsOf (jsonFormat.type // {
|
||||
description =
|
||||
"Firefox preference (int, bool, string, and also attrs, list, float as a JSON string)";
|
||||
});
|
||||
default = { };
|
||||
example = literalExpression ''
|
||||
{
|
||||
|
@ -211,9 +220,19 @@ in {
|
|||
"distribution.searchplugins.defaultLocale" = "en-GB";
|
||||
"general.useragent.locale" = "en-GB";
|
||||
"browser.bookmarks.showMobileBookmarks" = true;
|
||||
"browser.newtabpage.pinned" = [{
|
||||
title = "NixOS";
|
||||
url = "https://nixos.org";
|
||||
}];
|
||||
}
|
||||
'';
|
||||
description = "Attribute set of Firefox preferences.";
|
||||
description = ''
|
||||
Attribute set of Firefox preferences.
|
||||
|
||||
Firefox only supports int, bool, and string types for
|
||||
preferences, but home-manager will automatically
|
||||
convert all other JSON-compatible values into strings.
|
||||
'';
|
||||
};
|
||||
|
||||
extraConfig = mkOption {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
// Generated by Home Manager.
|
||||
|
||||
user_pref("browser.newtabpage.pinned", "[{\"title\":\"NixOS\",\"url\":\"https://nixos.org\"}]");
|
||||
user_pref("general.smoothScroll", false);
|
||||
|
||||
|
||||
|
|
|
@ -9,7 +9,13 @@ lib.mkIf config.test.enableBig {
|
|||
|
||||
profiles.test = {
|
||||
id = 1;
|
||||
settings = { "general.smoothScroll" = false; };
|
||||
settings = {
|
||||
"general.smoothScroll" = false;
|
||||
"browser.newtabpage.pinned" = [{
|
||||
title = "NixOS";
|
||||
url = "https://nixos.org";
|
||||
}];
|
||||
};
|
||||
};
|
||||
|
||||
profiles.bookmarks = {
|
||||
|
|
Loading…
Reference in a new issue