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,39 +533,11 @@ 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
profile.search.engines)) {
${profile.search.default} = { };
});
# Map allEngines to a list and order by search.order
orderedEngineList = (imap (order: name:
let engine = allEngines.${name} or { };
in engine // {
inherit name;
metaData = (engine.metaData or { }) // { inherit order; };
}) profile.search.order) ++ (mapAttrsToList
(name: config: config // { inherit name; })
(removeAttrs allEngines profile.search.order));
engines = map (config:
let
name = config.name;
isAppProvided = removeAttrs config [ "name" "metaData" ]
== { };
metaData = config.metaData or { };
in mapAttrs' (name: value: {
# Map nice field names to internal field names. This is
# intended to be exhaustive, but any future fields will
# either have to be specified with an underscore, or added
# to this map.
name = ((genAttrs [
"name" "name"
"isAppProvided" "isAppProvided"
"loadPath" "loadPath"
@ -580,32 +552,75 @@ in {
"definedAliases" "definedAliases"
"urls" "urls"
] (name: "_${name}")) // { ] (name: "_${name}")) // {
"searchForm" = "__searchForm"; searchForm = "__searchForm";
}).${name} or name; };
inherit value; processCustomEngineInput = input:
}) ((removeAttrs config [ "icon" ]) (removeAttrs input [ "icon" ])
// (optionalAttrs (!isAppProvided) // optionalAttrs (input ? icon) {
(optionalAttrs (config ? iconUpdateURL) { # Convenience to specify absolute path to icon
iconURL = "file://${input.icon}";
} // (optionalAttrs (input ? iconUpdateURL) {
# Convenience to default iconURL to iconUpdateURL so # Convenience to default iconURL to iconUpdateURL so
# the icon is immediately downloaded from the URL # the icon is immediately downloaded from the URL
iconURL = config.iconURL or config.iconUpdateURL; iconURL = input.iconURL or input.iconUpdateURL;
} // optionalAttrs (config ? icon) {
# Convenience to specify absolute path to icon
iconURL = "file://${config.icon}";
} // { } // {
# Required for custom engine configurations, loadPaths # Required for custom engine configurations, loadPaths
# are unique identifiers that are generally formatted # are unique identifiers that are generally formatted
# like: [source]/path/to/engine.xml # like: [source]/path/to/engine.xml
loadPath = '' loadPath = ''
[home-manager]/programs.firefox.profiles.${profile.name}.search.engines."${ [home-manager]/programs.firefox.profiles.${profile.name}.search.engines."${
replaceStrings [ "\\" ] [ "\\\\" ] name replaceStrings [ "\\" ] [ "\\\\" ] input.name
}"''; }"'';
})) // { });
# Required fields for all engine configurations
inherit name isAppProvided metaData; processEngineInput = name: input:
})) orderedEngineList; let
in engines; requiredInput = {
inherit name;
isAppProvided = input.isAppProvided or removeAttrs input
[ "metaData" ] == { };
metaData = input.metaData or { };
};
in if requiredInput.isAppProvided then
requiredInput
else
processCustomEngineInput (input // requiredInput);
buildEngineConfig = name: input:
mapAttrs' (name: value: {
name = internalFieldNames.${name} or name;
inherit value;
}) (processEngineInput name input);
sortEngineConfigs = configs:
let
buildEngineConfigWithOrder = order: name:
let
config = configs.${name} or {
_name = name;
_isAppProvided = true;
_metaData = { };
};
in config // {
_metaData = config._metaData // { inherit order; };
};
engineConfigsWithoutOrder =
attrValues (removeAttrs configs profile.search.order);
sortedEngineConfigs =
(imap buildEngineConfigWithOrder profile.search.order)
++ engineConfigsWithoutOrder;
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;