2024-02-26 04:28:07 +00:00
|
|
|
{lib}: let
|
|
|
|
inherit (lib.options) mkOption;
|
2024-03-12 00:48:53 +00:00
|
|
|
inherit (lib.modules) mkIf mkDefault;
|
2024-02-26 04:28:07 +00:00
|
|
|
inherit (lib.types) nullOr str;
|
|
|
|
inherit (lib.attrsets) isAttrs mapAttrs;
|
|
|
|
|
2024-08-10 13:06:06 +00:00
|
|
|
mkLuaBinding = mode: key: action: desc:
|
|
|
|
mkIf (key != null) {
|
|
|
|
${key} = {
|
|
|
|
inherit mode action desc;
|
|
|
|
lua = true;
|
|
|
|
silent = true;
|
2024-02-26 04:28:07 +00:00
|
|
|
};
|
2024-08-10 13:06:06 +00:00
|
|
|
};
|
2024-02-26 04:28:07 +00:00
|
|
|
|
2024-08-10 13:06:06 +00:00
|
|
|
mkExprBinding = mode: key: action: desc:
|
|
|
|
mkIf (key != null) {
|
|
|
|
${key} = {
|
|
|
|
inherit mode action desc;
|
|
|
|
lua = true;
|
|
|
|
silent = true;
|
|
|
|
expr = true;
|
2024-02-26 04:28:07 +00:00
|
|
|
};
|
2024-08-10 13:06:06 +00:00
|
|
|
};
|
2024-02-26 04:28:07 +00:00
|
|
|
|
2024-08-10 13:06:06 +00:00
|
|
|
mkBinding = mode: key: action: desc:
|
|
|
|
mkIf (key != null) {
|
|
|
|
${key} = {
|
|
|
|
inherit mode action desc;
|
|
|
|
silent = true;
|
2024-02-26 04:28:07 +00:00
|
|
|
};
|
2024-08-10 13:06:06 +00:00
|
|
|
};
|
2024-02-26 04:28:07 +00:00
|
|
|
|
2024-08-10 13:06:06 +00:00
|
|
|
mkMappingOption = description: default:
|
|
|
|
mkOption {
|
|
|
|
type = nullOr str;
|
|
|
|
inherit default description;
|
|
|
|
};
|
2024-02-26 04:28:07 +00:00
|
|
|
|
2024-08-10 13:06:06 +00:00
|
|
|
# Utility function that takes two attrsets:
|
|
|
|
# { someKey = "some_value" } and
|
|
|
|
# { someKey = { description = "Some Description"; }; }
|
|
|
|
# and merges them into
|
|
|
|
# { someKey = { value = "some_value"; description = "Some Description"; }; }
|
|
|
|
addDescriptionsToMappings = actualMappings: mappingDefinitions:
|
|
|
|
mapAttrs (name: value: let
|
|
|
|
isNested = isAttrs value;
|
|
|
|
returnedValue =
|
|
|
|
if isNested
|
|
|
|
then addDescriptionsToMappings actualMappings.${name} mappingDefinitions.${name}
|
|
|
|
else {
|
|
|
|
inherit value;
|
|
|
|
inherit (mappingDefinitions.${name}) description;
|
|
|
|
};
|
|
|
|
in
|
|
|
|
returnedValue)
|
|
|
|
actualMappings;
|
2024-02-26 04:28:07 +00:00
|
|
|
|
2024-08-10 13:06:06 +00:00
|
|
|
mkSetBinding = mode: binding: action:
|
|
|
|
mkBinding mode binding.value action binding.description;
|
2024-02-26 04:28:07 +00:00
|
|
|
|
2024-08-10 13:06:06 +00:00
|
|
|
mkSetExprBinding = mode: binding: action:
|
|
|
|
mkExprBinding mode binding.value action binding.description;
|
2024-02-26 04:28:07 +00:00
|
|
|
|
2024-08-10 13:06:06 +00:00
|
|
|
mkSetLuaBinding = mode: binding: action:
|
|
|
|
mkLuaBinding mode binding.value action binding.description;
|
2024-03-12 00:48:53 +00:00
|
|
|
|
2024-08-10 13:06:06 +00:00
|
|
|
pushDownDefault = attr: mapAttrs (_: mkDefault) attr;
|
|
|
|
in {
|
|
|
|
inherit mkLuaBinding mkExprBinding mkBinding mkMappingOption addDescriptionsToMappings mkSetBinding mkSetExprBinding mkSetLuaBinding pushDownDefault;
|
|
|
|
}
|