about summary refs log tree commit diff
path: root/users/Profpatsch/netencode/netencode.nix
diff options
context:
space:
mode:
Diffstat (limited to 'users/Profpatsch/netencode/netencode.nix')
-rw-r--r--users/Profpatsch/netencode/netencode.nix18
1 files changed, 17 insertions, 1 deletions
diff --git a/users/Profpatsch/netencode/netencode.nix b/users/Profpatsch/netencode/netencode.nix
index 6bb2fa002796..5f98f27f6779 100644
--- a/users/Profpatsch/netencode/netencode.nix
+++ b/users/Profpatsch/netencode/netencode.nix
@@ -1,3 +1,4 @@
+{ lib }:
 let
 
   netstring = tag: suffix: s:
@@ -26,10 +27,24 @@ let
   concatStrings = builtins.concatStringsSep "";
 
   record = lokv: netstring "{" "}"
-    (concatStrings (map (kv: tag kv.key kv.val) lokv));
+    (concatStrings (map ({key, val}: tag key val) lokv));
 
   list = l: netstring "[" "]" (concatStrings l);
 
+  dwim = val:
+    let match = {
+      "bool" = n1;
+      "int" = i6;
+      "string" = text;
+      "set" = attrs: record (lib.mapAttrsToList
+        (k: v: {
+          key = k;
+          val = dwim v;
+        }) attrs);
+      "list" = l: list (map dwim l);
+    };
+    in match.${builtins.typeOf val} val;
+
 in {
   inherit
     unit
@@ -45,5 +60,6 @@ in {
     tag
     record
     list
+    dwim
     ;
 }