about summary refs log tree commit diff
path: root/users/Profpatsch
diff options
context:
space:
mode:
authorProfpatsch <mail@profpatsch.de>2021-08-01T16·59+0200
committerProfpatsch <mail@profpatsch.de>2021-11-13T00·57+0000
commitd41caf2dd60a20668cf6ec5de03df412622f1627 (patch)
tree71c9b028e1adc0d9d2831ce3ec277b8e0e99fdb9 /users/Profpatsch
parent28bed07694d16685ecf8d2e179222b3d4920611d (diff)
feat(users/Profpatsch/netstring): add nix toNetstring* functions r/3040
We can easily construct netstrings from nix strings, which is super
helpful to inject proper structured data into execline scripts.

Change-Id: Ie8bffed285896223db83652eaea868ece43592b9
Reviewed-on: https://cl.tvl.fyi/c/depot/+/3265
Tested-by: BuildkiteCI
Reviewed-by: Profpatsch <mail@profpatsch.de>
Diffstat (limited to 'users/Profpatsch')
-rw-r--r--users/Profpatsch/netstring/default.nix12
1 files changed, 12 insertions, 0 deletions
diff --git a/users/Profpatsch/netstring/default.nix b/users/Profpatsch/netstring/default.nix
index 2b21cde388..eee5358fdd 100644
--- a/users/Profpatsch/netstring/default.nix
+++ b/users/Profpatsch/netstring/default.nix
@@ -1,5 +1,17 @@
 { lib, pkgs, depot, ... }:
 let
+  toNetstring = s:
+    "${toString (builtins.stringLength s)}:${s},";
+
+  toNetstringList = xs:
+    lib.concatStrings (map toNetstring xs);
+
+  toNetstringKeyVal = attrs:
+    lib.concatStrings
+      (lib.mapAttrsToList
+        (k: v: toNetstring (toNetstring k + toNetstring v))
+        attrs);
+
   python-netstring = depot.users.Profpatsch.writers.python3Lib {
     name = "netstring";
   } ''