From dda6ce376fe253e9968b1db53eff2f002fc061c4 Mon Sep 17 00:00:00 2001 From: Antonio Gurgel Date: Sun, 3 Dec 2023 13:50:44 -0800 Subject: [PATCH] Write ADR 2 --- adr/1.md | 19 +++++---------- adr/2.md | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 13 deletions(-) create mode 100644 adr/2.md diff --git a/adr/1.md b/adr/1.md index 2d0cabb..c3754dc 100644 --- a/adr/1.md +++ b/adr/1.md @@ -51,24 +51,17 @@ services = flakeBuilders.services self.serviceData { I do instead: ```nix -stages = [ - services/0-istio - services/1-kyverno - services/2-longhorn - services/3-registry-cache - services/4-metallb - <...> -]; +stages = (ls ./services); -serviceData = rake.leaves stages; +serviceData = rake.stages stages; # This should return a list of unbuilt service trees. ``` I'm not sure what to do past this point but I know what I want: -1. `services/0-istio` is built by flakeBuilders.services with `apiVersions = []`. -2. `services/1-kyverno` is built by flakeBuilders.services with `apiVersions = []`. -3. `services/2-longhorn` is built by flakeBuilders.services with `apiVersions = [ ]`. +1. `services/00-istio` is built by flakeBuilders.services with `apiVersions = []`. +2. `services/01-kyverno` is built by flakeBuilders.services with `apiVersions = []`. +3. `services/02-longhorn` is built by flakeBuilders.services with `apiVersions = [ ]`. 4. And so on, until `services/XX-services` is built with all APIs accumulated from previous stages. -It looks like a `pkgs.lib.lists.foldl`. Also, the stages can be gathered with `ls ./services | filter()`. +It looks like a `pkgs.lib.lists.foldl`. diff --git a/adr/2.md b/adr/2.md new file mode 100644 index 0000000..dc159bd --- /dev/null +++ b/adr/2.md @@ -0,0 +1,73 @@ +# ADR 2: Using directory trees as data + +In `a2abba2` or sometime around then, I borrowed Nixhelm's [leaf-raking paradigm](https://github.com/farcaller/nixhelm/blob/e0383f7c11000f8c141a7d26197ee402424b017d/flake.nix#L9-L23) (and named it after [Digga's](https://github.com/divnix/digga/blob/baa54f8641ee9128cdda8b508553284c331fc9f1/src/importers.nix#L61-L114)...although this is the first time I'm looking directly at it, and now I'm realizing I could have just borrowed that very code.) + +Example input and output, using `kubernetes@2de43d7`: + +``` +services +├── cert-manager +│   └── cert-manager +│   ├── default.nix +│   └── prometheusrule.yaml +├── cnpg-system +│   └── cloudnative-pg +│   └── default.nix +... +system +├── argo +│   └── workflows +│   └── default.nix +├── cert-manager +│   └── cert-manager +│   ├── default.nix +│   └── k8s-intermediate.sops.yaml +├── cnpg-system +│   └── cloudnative-pg +│   └── default.nix +``` + +```nix +systemServiceData = rake.leaves ./system; +serviceData = rake.leaves ./services; +``` + +```nix +serviceData = { + # These two derivations consist only of resources + # (`ClusterIssuer`, CNPG `Cluster`); the applications themselves + # are installed in `system`. + cert-manager.cert-manager = {lib, ...} -> {builder, args}; + cnpg-system.cloudnative-pg = {lib, ...} -> {builder, args}; + ... +}; +systemServiceData = { + argo.workflows = {charts, lib, user, ...} -> {builder, args, extraObjects}; + cert-manager.cert-manager = {charts, lib, user, ...} -> {builder, args, extraObjects}; + cnpg-system.cloudnative-pg = {charts, lib, ...} -> {builder, args}; + ... +}; +``` + +Raking a service tree like this reduces the need to litter the source tree with +`default.nix` files (as seen in, e.g., [nixos-hardware](https://github.com/NixOS/nixos-hardware/tree/a89745edd5f657e2e5be5ed1bea86725ca78d92e)). +However, it imposes assumptions about the source tree that ADR 1 rendered invalid. + +## Considered Options + +### Adapt existing code + +The most work. + +### Borrow Digga's code + +It's MIT-licensed, hence compatible with this project's Apache 2. + +### Use Haumea + +In reading about Digga's deprecation I was tipped off to Haumea. +It does exactly what I want: map a filesystem tree to an attrset. + +## Decision + +Use Haumea.