kubenix/lib/upstreamables.nix

46 lines
1.2 KiB
Nix
Raw Normal View History

2022-04-02 12:40:35 -07:00
{
lib,
pkgs,
}:
with lib; let
self = {
importYAML = path:
importJSON (pkgs.runCommand "yaml-to-json" {} ''
${pkgs.remarshal}/bin/remarshal -i ${path} -if yaml -of json > $out
'');
toYAML = config:
builtins.readFile (pkgs.runCommand "to-yaml" {} ''
${pkgs.remarshal}/bin/remarshal -i ${pkgs.writeText "to-json" (builtins.toJSON config)} -if json -of yaml > $out
'');
toMultiDocumentYaml = name: documents:
pkgs.runCommand name {}
(concatMapStringsSep "\necho --- >> $out\n"
(
d: "${pkgs.remarshal}/bin/remarshal -i ${builtins.toFile "doc" (builtins.toJSON d)} -if json -of yaml >> $out"
)
documents);
toBase64 = value:
builtins.readFile
(pkgs.runCommand "value-to-b64" {} "echo -n '${value}' | ${pkgs.coreutils}/bin/base64 -w0 > $out");
2022-04-02 13:41:07 -07:00
exp = base: exp: foldr (_value: acc: acc * base) 1 (range 1 exp);
2022-04-02 12:40:35 -07:00
octalToDecimal = value:
(foldr
(char: acc: {
i = acc.i + 1;
value = acc.value + (toInt char) * (self.exp 8 acc.i);
})
{
i = 0;
value = 0;
}
(stringToCharacters value))
.value;
};
in
self