ctucx.git: nixfiles

ctucx' nixfiles

commit ab2127687cf56165053e13959c58b5b18fc8b667
parent 444d23e0a5babaedb03561f406777dc3840ecfcf
Author: Leah (ctucx) <git@ctu.cx>
Date: Fri, 16 Sep 2022 09:28:19 +0200

modules/hidutil: use `builtins.fromTOML` to convert hex to decimal
1 file changed, 1 insertion(+), 7 deletions(-)
diff --git a/modules/darwin/hidutil.nix b/modules/darwin/hidutil.nix
@@ -6,13 +6,7 @@ let
   cfg = config.hidutil;
 
   # convert hex to int with nix!
-  pow      = base: exp: lib.foldl' (a: x: x * a) 1 (lib.genList (_: base) exp);
-  hexToDec = v:
-    let
-      hexToInt = { "0" = 0; "1" = 1;  "2" = 2; "3" = 3; "4" = 4;  "5" = 5; "6" = 6; "7" = 7;  "8" = 8; "9" = 9; "a" = 10; "b" = 11; "c" = 12;"d" = 13; "e" = 14; "f" = 15; };
-      chars    = lib.stringToCharacters v;
-      charsLen = lib.length chars;
-    in lib.foldl (a: v: a + v) 0 (lib.imap0 (k: v: hexToInt."${v}" * (pow 16 (charsLen - k - 1))) chars);
+  hexToDec = hex: (builtins.fromTOML "a = 0x${removePrefix "0x" hex}").a;
 
 in {
   ###### interface