1
0
Fork 0
mirror of https://git.sr.ht/~goorzhel/turboprop synced 2024-12-15 17:50:52 +00:00
turboprop/lib/default.nix
Antonio Gurgel 70fae512d1 Refactor crisis
Two imperfections have come to bite me simultaneously:
- I wanted strict ordering of services but implemented it very sloppily.
- The flake builders represent implementation leakage. I want to present
  a clean interface to users, not "first, you must evaluate these
  twenty-eight variables".

So now I'm fixing too many things at once. Luckily it's hard to lose
things in Git.
2023-11-29 23:06:13 -08:00

52 lines
1.5 KiB
Nix

{
charts,
kubelib,
pkgs,
}: rec {
app-template = import ./app-template.nix {inherit builders charts pkgs;};
builders = import ./builders.nix {inherit kubelib pkgs;};
fetchers = import ./fetchers.nix {inherit kubelib pkgs;};
resources = import ./resources.nix;
parseYAMLsFile = p: kubelib.fromYAML (builtins.readFile p);
parseYAMLFile = p: builtins.head (parseYAMLsFile p);
# Helm cannot see my cluster from within the sandbox, so it cannot
# infer capabilities from it. Therefore, API versions must be gathered
# from charts that provide them.
# Doc: https://helm.sh/docs/chart_template_guide/builtin_objects/
gatherApis = yamlPath: let
crds = builtins.filter
(obj: obj.kind == "CustomResourceDefinition")
(parseYAMLsFile yamlPath);
in
pkgs.lib.lists.flatten
(map
(
crd:
map
(
crdVersion: let
group = crd.spec.group;
version = crdVersion.name;
kind = crd.spec.names.kind;
in "${group}/${version}/${kind}"
)
(builtins.filter
(crdVersion: (! crdVersion ? "deprecated") || crdVersion.deprecated != true)
crd.spec.versions)
)
crds);
mkClusterData = {
kubeVersion,
services,
}: {
inherit kubeVersion;
apiVersions =
pkgs.lib.lists.flatten
(map
(chartDrv: gatherApis chartDrv.outPath)
(with pkgs.lib; attrsets.collect isDerivation services));
};
}