1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-12-25 03:09:47 +01:00

firefox: refactor search.json.mozlz4 generation

The new setup should be easier to read.
This commit is contained in:
Kira Bruneau 2023-01-06 18:38:09 -05:00 committed by Robert Helgesson
parent 2c29ae48f9
commit 866a4ddcb3
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89

View file

@ -533,79 +533,94 @@ in {
source = let source = let
settings = { settings = {
version = 6; version = 6;
engines = let engines = let
allEngines = (profile.search.engines // # Map of nice field names to internal field names.
# If search.default isn't in search.engines, assume it's app # This is intended to be exhaustive and should be
# provided and include it in the set of all engines # updated at every version bump.
optionalAttrs (profile.search.default != null internalFieldNames = (genAttrs [
&& !(hasAttr profile.search.default "name"
profile.search.engines)) { "isAppProvided"
${profile.search.default} = { }; "loadPath"
}); "hasPreferredIcon"
"updateInterval"
"updateURL"
"iconUpdateURL"
"iconURL"
"iconMapObj"
"metaData"
"orderHint"
"definedAliases"
"urls"
] (name: "_${name}")) // {
searchForm = "__searchForm";
};
# Map allEngines to a list and order by search.order processCustomEngineInput = input:
orderedEngineList = (imap (order: name: (removeAttrs input [ "icon" ])
let engine = allEngines.${name} or { }; // optionalAttrs (input ? icon) {
in engine // { # Convenience to specify absolute path to icon
inherit name; iconURL = "file://${input.icon}";
metaData = (engine.metaData or { }) // { inherit order; }; } // (optionalAttrs (input ? iconUpdateURL) {
}) profile.search.order) ++ (mapAttrsToList # Convenience to default iconURL to iconUpdateURL so
(name: config: config // { inherit name; }) # the icon is immediately downloaded from the URL
(removeAttrs allEngines profile.search.order)); iconURL = input.iconURL or input.iconUpdateURL;
} // {
# Required for custom engine configurations, loadPaths
# are unique identifiers that are generally formatted
# like: [source]/path/to/engine.xml
loadPath = ''
[home-manager]/programs.firefox.profiles.${profile.name}.search.engines."${
replaceStrings [ "\\" ] [ "\\\\" ] input.name
}"'';
});
engines = map (config: processEngineInput = name: input:
let let
name = config.name; requiredInput = {
isAppProvided = removeAttrs config [ "name" "metaData" ] inherit name;
== { }; isAppProvided = input.isAppProvided or removeAttrs input
metaData = config.metaData or { }; [ "metaData" ] == { };
in mapAttrs' (name: value: { metaData = input.metaData or { };
# Map nice field names to internal field names. This is };
# intended to be exhaustive, but any future fields will in if requiredInput.isAppProvided then
# either have to be specified with an underscore, or added requiredInput
# to this map. else
name = ((genAttrs [ processCustomEngineInput (input // requiredInput);
"name"
"isAppProvided"
"loadPath"
"hasPreferredIcon"
"updateInterval"
"updateURL"
"iconUpdateURL"
"iconURL"
"iconMapObj"
"metaData"
"orderHint"
"definedAliases"
"urls"
] (name: "_${name}")) // {
"searchForm" = "__searchForm";
}).${name} or name;
buildEngineConfig = name: input:
mapAttrs' (name: value: {
name = internalFieldNames.${name} or name;
inherit value; inherit value;
}) ((removeAttrs config [ "icon" ]) }) (processEngineInput name input);
// (optionalAttrs (!isAppProvided)
(optionalAttrs (config ? iconUpdateURL) { sortEngineConfigs = configs:
# Convenience to default iconURL to iconUpdateURL so let
# the icon is immediately downloaded from the URL buildEngineConfigWithOrder = order: name:
iconURL = config.iconURL or config.iconUpdateURL; let
} // optionalAttrs (config ? icon) { config = configs.${name} or {
# Convenience to specify absolute path to icon _name = name;
iconURL = "file://${config.icon}"; _isAppProvided = true;
} // { _metaData = { };
# Required for custom engine configurations, loadPaths };
# are unique identifiers that are generally formatted in config // {
# like: [source]/path/to/engine.xml _metaData = config._metaData // { inherit order; };
loadPath = '' };
[home-manager]/programs.firefox.profiles.${profile.name}.search.engines."${
replaceStrings [ "\\" ] [ "\\\\" ] name engineConfigsWithoutOrder =
}"''; attrValues (removeAttrs configs profile.search.order);
})) // {
# Required fields for all engine configurations sortedEngineConfigs =
inherit name isAppProvided metaData; (imap buildEngineConfigWithOrder profile.search.order)
})) orderedEngineList; ++ engineConfigsWithoutOrder;
in engines; in sortedEngineConfigs;
engineInput = profile.search.engines // {
# Infer profile.search.default as an app provided
# engine if it's not in profile.search.engines
${profile.search.default} =
profile.search.engines.${profile.search.default} or { };
};
in sortEngineConfigs (mapAttrs buildEngineConfig engineInput);
metaData = optionalAttrs (profile.search.default != null) { metaData = optionalAttrs (profile.search.default != null) {
current = profile.search.default; current = profile.search.default;