kubenix/lib/upstreamables.nix
Felix Scheinost e77a3898de
Replace remarshal with yq (#26)
Remarshal doesn’t seem to be maintained anymore.

It is also affected by upstream bugs like https://github.com/yaml/pyyaml/issues/89 which affects e.g. prometheus-operator CRDs.
2023-06-19 12:14:20 -04:00

45 lines
1.1 KiB
Nix

{
lib,
pkgs,
}:
with lib; let
self = {
importYAML = path:
importJSON (pkgs.runCommand "yaml-to-json" {} ''
${pkgs.yq}/bin/yq -c . ${path} > $out
'');
toYAML = config:
builtins.readFile (pkgs.runCommand "to-yaml" {} ''
${pkgs.yq}/bin/yq -y . ${pkgs.writeText "to-json" (builtins.toJSON config)} > $out
'');
toMultiDocumentYaml = name: documents:
pkgs.runCommand name {}
(concatMapStringsSep "\necho --- >> $out\n"
(
d: "${pkgs.yq}/bin/yq -y . ${pkgs.writeText "to-json" (builtins.toJSON config)} >> $out"
)
documents);
toBase64 = value:
builtins.readFile
(pkgs.runCommand "value-to-b64" {} "echo -n '${value}' | ${pkgs.coreutils}/bin/base64 -w0 > $out");
exp = base: exp: foldr (_value: acc: acc * base) 1 (range 1 exp);
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