1
0
Fork 0
mirror of https://git.sr.ht/~goorzhel/turboprop synced 2024-12-14 11:37:37 +00:00
turboprop/lib/rake.nix
Antonio Gurgel 1444cb9b18 s/release/service/g
"Helm releases" is what I'd been terming individual services, but
it makes no sense outside of the internal context of the Helm builder.

I also didn't want to call them "apps", however shorter that term is.
These are not apps.
2023-11-24 17:35:15 -08:00

51 lines
1.4 KiB
Nix

# Data from `charts/` and `services/` is gathered into
# nested attrsets resembling the directory structure.
# For example, `rake.leaves ./charts` produces:
# {"bjw-s"={"app-template"={...}}; ...}; ...}
# The data each leaf contains is explained in `./flake-builders.nix`.
let
ls = dir: with builtins; attrNames (readDir dir);
# e.g.: `dirToAttrs ./src "svc"` renders
# {name = "svc"; value = {"sota-slack-spotter" = <lambda>, ...};}
# which, combined with `attrNames`, becomes input to listToAttrs.
# TODO: nixpkgs has lib.attrsets.nameValuePair
dirToAttrs = root: dirName: {
name = dirName;
value = let
dir = root + "/${dirName}";
in
builtins.listToAttrs
(map
(name: {
inherit name;
value = import "${dir}/${name}";
})
(ls dir));
};
mkNamespace = (import ./resources.nix).mkNamespace;
in {
leaves = root:
builtins.listToAttrs (
map (dirToAttrs root) (ls root)
);
namespaces = {
roots,
extraMetadata ? {},
}:
with builtins;
map
(name: let
metadata =
# Can't use `set?name` or `set.name`
# because "name" is taken literally.
if hasAttr name extraMetadata
then getAttr name extraMetadata
else extraMetadata.DEFAULT;
in
mkNamespace name metadata)
(concatLists (map ls roots));
}