-
Notifications
You must be signed in to change notification settings - Fork 26
/
upstreamables.nix
41 lines (36 loc) · 1.11 KB
/
upstreamables.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
{ 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 d)} >> $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