-
Notifications
You must be signed in to change notification settings - Fork 11
/
config.nix
35 lines (32 loc) · 1.1 KB
/
config.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
{ lib
, keybindings ? {}
, options ? {}
}:
let
# escape a value for usage in the CC argument list
mkEscapedValue = name: value:
let
# escape the value for the macro defintion
# int's and floats aren't quoted but converted to string instead
type = builtins.typeOf value;
v =
if lib.elem type [ "float" "int" ] then
toString value
else lib.escapeShellArg ''"${value}"'';
in v;
listOfKeybindings = lib.mapAttrsToList (key: value:
let
keyList = lib.reverseList (lib.splitString "+" value);
modifiers = builtins.tail keyList;
keyValue = builtins.head keyList;
in {
"${key}_KEYVAL" = mkEscapedValue "" keyValue;
"${key}_MODIFIER_MASK" = ''"${lib.concatStringsSep " | " (map (m: "GDK_${lib.toUpper m}_MASK") modifiers)}"'';
}) keybindings;
keybindingDefines = lib.foldr (accu: val: accu // val) {} listOfKeybindings;
optionDefines = lib.mapAttrs mkEscapedValue options;
mkCFlag = key: value: "-D${key}=${value}";
in
lib.concatStringsSep " " (
lib.mapAttrsToList mkCFlag (keybindingDefines // optionDefines)
)