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 <mail@profpatsch.de>
This commit is contained in:
Profpatsch 2021-08-01 18:59:33 +02:00
parent 28bed07694
commit d41caf2dd6

View file

@ -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";
} ''