2023-06-18 03:32:15 +00:00
|
|
|
{ inputs, cell }:
|
|
|
|
let
|
2023-06-16 23:12:54 +00:00
|
|
|
namespace = "repo";
|
|
|
|
|
|
|
|
|
|
|
|
yamlToJsonDrv = pkgs: yamlContent: outputPath: (pkgs.runCommand
|
2023-06-18 03:32:15 +00:00
|
|
|
outputPath
|
|
|
|
{ inherit yamlContent; nativeBuildInputs = [ pkgs.yq ]; }
|
|
|
|
# run yq which outputs '.' (no filter) on file at yamlPath
|
|
|
|
# note that $out is passed onto the bash/sh script for execution
|
|
|
|
''
|
|
|
|
echo "$yamlContent" | yq >$out
|
|
|
|
'')
|
2023-06-16 23:12:54 +00:00
|
|
|
{ });
|
2023-06-18 03:32:15 +00:00
|
|
|
in
|
|
|
|
{
|
2023-06-16 23:12:54 +00:00
|
|
|
fromYAML = yamlContent: bulitins.fromJSON (builtins.readFile (yamlToJsonDrv inputs.nixpkgs yamlContent "fromYaml.json"));
|
|
|
|
|
2023-06-18 00:46:31 +00:00
|
|
|
# NOTE: Deprecate
|
2023-06-16 23:12:54 +00:00
|
|
|
# ctor
|
2023-06-18 03:32:15 +00:00
|
|
|
opt-some = a: [ a ];
|
|
|
|
opt-none = [ ];
|
|
|
|
opt-none_thunk = _: [ ];
|
2023-06-16 23:12:54 +00:00
|
|
|
|
|
|
|
# from-to null
|
2023-06-18 03:32:15 +00:00
|
|
|
opt-fromNullable = nullable: if nullable == null then [ ] else [ nullable ];
|
2023-06-16 23:12:54 +00:00
|
|
|
opt-toNullable = opt-fork (a:a) (_: null);
|
|
|
|
|
|
|
|
opt-map = builtins.map;
|
|
|
|
opt-filter = builtins.filter;
|
2023-06-18 03:32:15 +00:00
|
|
|
opt-fork = on_some: on_none: opt: if opt == [ ] then (on_none null) else (on_some (builtins.elemAt opt 0));
|
2023-06-16 23:12:54 +00:00
|
|
|
|
|
|
|
opt-unwrap = opt-fork (a:a) (_: throw "opt-unwrap: expected some, got none");
|
|
|
|
opt-unwrapOrElse = opt-fork (a:a);
|
|
|
|
opt-unwrapOr = fallback_val: opt-fork (a:a) (_: fallback_val);
|
|
|
|
|
|
|
|
opt-orElse = opt: fallback_opt: opt-fork (opt-some) (opt-none_thunk) (opt ++ fallback_opt);
|
2023-06-18 03:32:15 +00:00
|
|
|
opt-leftmostSome = opts: builtins.foldl' (opt-orElse) [ ] opts;
|
2023-06-16 23:12:54 +00:00
|
|
|
}
|