From d41caf2dd60a20668cf6ec5de03df412622f1627 Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Sun, 1 Aug 2021 18:59:33 +0200 Subject: feat(users/Profpatsch/netstring): add nix toNetstring* functions 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 --- users/Profpatsch/netstring/default.nix | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'users/Profpatsch') diff --git a/users/Profpatsch/netstring/default.nix b/users/Profpatsch/netstring/default.nix index 2b21cde388e5..eee5358fddd9 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"; } '' -- cgit 1.4.1