1
0
Fork 0
mirror of https://git.sr.ht/~goorzhel/turboprop synced 2024-12-14 11:37:37 +00:00

Move kubeV to loader; allow user to set apiV

It doesn't make sense for `kubeVersions` to be an _input_ to the module,
i.e., one provided by the Haumea loader. Let it be passed inside the
foldler instead, like `apiVersions`.

En passant, I realized it's as easy to expose apiVersions to user input;
maybe one'd want to specify APIs not installed by this flake.
This commit is contained in:
Antonio Gurgel 2023-12-04 19:34:22 -08:00
parent 964a2d115e
commit 7c0b843315
2 changed files with 21 additions and 12 deletions

View file

@ -14,8 +14,9 @@ in {
serviceRoot,
nsMetadata ? {},
kubeVersion ? pkgs.kubernetes.version,
apiVersions ? []
}: let
services = mk.services serviceRoot kubeVersion;
services = mk.services {inherit serviceRoot kubeVersion apiVersions;};
in
pkgs.stdenv.mkDerivation {
inherit pname version src;

View file

@ -8,7 +8,7 @@
# This is a Haumea loader that transforms unbuilt service modules:
# {charts, lib, pkgs, user, ...} -> {builder, args}
# into almost-built modules:
# [apiVersion] -> {out, extra}
# {kubeVersion, apiVersions} -> {out, extra}
#
# The list of apiVersions is a separate input so that `services`' foldl
# operation can accumulate APIs in order.
@ -17,17 +17,20 @@
lib,
pkgs,
user,
kubeVersion,
...
} @ inputs: p: let
module = import p inputs;
# p is `.../${ns}/${name}/default.nix`
# TODO: Remove all this after `lib.gatherNamespaces` implemented.
srcPath = builtins.dirOf p;
name = builtins.baseNameOf srcPath;
namespace = with builtins; baseNameOf (dirOf srcPath);
in
apiVersions: {
{
kubeVersion,
apiVersions,
}: {
out = module.builder (module.args
// {
# By injecting `name` and `namespace` here, I remove
@ -52,20 +55,25 @@
inherit srcPath;
};
in {
services = src: kubeVersion: let
services = {serviceRoot, kubeVersion, apiVersions}: let
modules = haumea.lib.load {
inherit src;
inputs = {inherit charts lib pkgs user kubeVersion;};
src = serviceRoot;
inputs = {inherit charts lib pkgs user;};
loader = serviceLoader;
transformer = lib.liftDefault;
};
serviceFoldler = acc: modPath: mod: let
foldler = acc: modPath: mod: let
# Kubernetes clusters often consist of many interdependent services.
# This line allows the user to make a DAG of these services.
# By using foldl, these services can be organized into a quasi-DAG,
# where APIs are exported and evaluated cumulatively.
# For example, Gateway API provides gateway.networking.k8s.io, which
# subsequent Helm charts may query (see documentation of lib.gatherApis).
module = mod acc.apis;
module = mod {
inherit kubeVersion;
apiVersions = acc.apis;
};
# TODO: Namespaces should be gathered from module.out instead.
namespace = with builtins; baseNameOf (dirOf module.srcPath);
# Associating a derivation with the path of the module that created it
@ -85,9 +93,9 @@ in {
};
in
pkgs.lib.attrsets.foldlAttrs
serviceFoldler
foldler
{
apis = [];
apis = apiVersions; # usually []
paths = [];
namespaces = [];
}