2024-02-26 05:28:07 +01:00
|
|
|
{lib}: let
|
|
|
|
inherit (lib.options) mkOption;
|
2024-03-12 01:48:53 +01:00
|
|
|
inherit (lib.modules) mkIf mkDefault;
|
2024-02-26 05:28:07 +01:00
|
|
|
inherit (lib.types) nullOr str;
|
|
|
|
inherit (lib.attrsets) isAttrs mapAttrs;
|
|
|
|
|
2024-08-12 02:07:45 +02:00
|
|
|
mkLuaBinding = mode: key: action: desc:
|
|
|
|
mkIf (key != null) {
|
|
|
|
${key} = {
|
|
|
|
inherit mode action desc;
|
|
|
|
lua = true;
|
|
|
|
silent = true;
|
2024-02-26 05:28:07 +01:00
|
|
|
};
|
2024-08-12 02:07:45 +02:00
|
|
|
};
|
2024-02-26 05:28:07 +01:00
|
|
|
|
2024-08-12 02:07:45 +02:00
|
|
|
mkExprBinding = mode: key: action: desc:
|
|
|
|
mkIf (key != null) {
|
|
|
|
${key} = {
|
|
|
|
inherit mode action desc;
|
|
|
|
lua = true;
|
|
|
|
silent = true;
|
|
|
|
expr = true;
|
2024-02-26 05:28:07 +01:00
|
|
|
};
|
2024-08-12 02:07:45 +02:00
|
|
|
};
|
2024-02-26 05:28:07 +01:00
|
|
|
|
2024-08-12 02:07:45 +02:00
|
|
|
mkBinding = mode: key: action: desc:
|
|
|
|
mkIf (key != null) {
|
|
|
|
${key} = {
|
|
|
|
inherit mode action desc;
|
|
|
|
silent = true;
|
2024-02-26 05:28:07 +01:00
|
|
|
};
|
2024-08-12 02:07:45 +02:00
|
|
|
};
|
2024-02-26 05:28:07 +01:00
|
|
|
|
2024-08-12 02:07:45 +02:00
|
|
|
mkMappingOption = description: default:
|
|
|
|
mkOption {
|
|
|
|
type = nullOr str;
|
|
|
|
inherit default description;
|
|
|
|
};
|
2024-02-26 05:28:07 +01:00
|
|
|
|
2024-08-12 02:07:45 +02: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 05:28:07 +01:00
|
|
|
|
2024-08-12 02:07:45 +02:00
|
|
|
mkSetBinding = mode: binding: action:
|
|
|
|
mkBinding mode binding.value action binding.description;
|
2024-02-26 05:28:07 +01:00
|
|
|
|
2024-08-12 02:07:45 +02:00
|
|
|
mkSetExprBinding = mode: binding: action:
|
|
|
|
mkExprBinding mode binding.value action binding.description;
|
2024-02-26 05:28:07 +01:00
|
|
|
|
2024-08-12 02:07:45 +02:00
|
|
|
mkSetLuaBinding = mode: binding: action:
|
|
|
|
mkLuaBinding mode binding.value action binding.description;
|
2024-03-12 01:48:53 +01:00
|
|
|
|
2024-08-12 02:07:45 +02:00
|
|
|
pushDownDefault = attr: mapAttrs (_: mkDefault) attr;
|
|
|
|
in {
|
|
|
|
inherit mkLuaBinding mkExprBinding mkBinding mkMappingOption addDescriptionsToMappings mkSetBinding mkSetExprBinding mkSetLuaBinding pushDownDefault;
|
|
|
|
}
|