I can't believe its not an integer parser

(now with more integer parsing)

on a serious note:
- adds integer to string parsing (because thats not dangerous at all)
- adds a container spec generator for OCI containers using a custom template

Signed-off-by: ahuston-0 <aliceghuston@gmail.com>
This commit is contained in:
ahuston-0 2024-06-22 00:49:54 -04:00
parent acbf9a6124
commit 67a337dfaf
No known key found for this signature in database
GPG Key ID: 1FACF4075E3212F7

View File

@ -56,5 +56,32 @@
# type:
# fileList :: Path -> String -> [Path]
fileList = dir: map (file: dir + "/${file}") (ls dir);
createContainers =
containers: container-spec:
builtins.listToAttrs (
lib.flatten (
lib.mapAttrsToList (
name: value:
(map (num: {
name = "${name}-${parseInt num}";
value = container-spec value.image;
}) (lib.lists.range 1 value.scale))
) containers
)
);
parseInt =
num:
let
digits = "0123456789";
mod = num: (lib.trivial.mod num 10);
in
if num > 9 then
((parseInt (builtins.div num 10)) + (lib.substring (mod num) 1 digits))
else if num < 0 then
"-" + (parseInt (builtins.mul num (-1)))
else
lib.substring (mod num) 1 digits;
};
}