mirror of
https://git.sr.ht/~goorzhel/turboprop
synced 2024-12-14 11:37:37 +00:00
3e7a376329
Release trees are now split into API-producing and API-using ones. Namespace rake must now take a list of roots of release trees.
110 lines
3.4 KiB
Nix
110 lines
3.4 KiB
Nix
{
|
|
description = "Kubernetes deployments flake";
|
|
|
|
inputs = {
|
|
# Base
|
|
nixpkgs.url = "github:NixOS/nixpkgs";
|
|
flake-utils.url = "github:numtide/flake-utils";
|
|
nix-kube-generators.url = "github:farcaller/nix-kube-generators";
|
|
nixhelm.url = "github:farcaller/nixhelm";
|
|
|
|
# Dev
|
|
devshell = {
|
|
url = "github:numtide/devshell";
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
};
|
|
|
|
# TODO: My whole homelab is a flake. It would be
|
|
# pretty wild to be able to import data from it.
|
|
};
|
|
|
|
outputs = inputs @ {
|
|
self,
|
|
nixpkgs,
|
|
flake-utils,
|
|
nix-kube-generators,
|
|
nixhelm,
|
|
devshell,
|
|
}: let
|
|
rake = import ./lib/rake.nix;
|
|
in
|
|
{
|
|
# Releases expected to provide custom APIs
|
|
# (e.g.: Gateway API, Istio, Longhorn)
|
|
# go in `./system`. All others in `./releases`.
|
|
systemReleaseData = rake.leaves ./system;
|
|
releaseData = rake.leaves ./releases;
|
|
|
|
repos = rake.leaves ./charts;
|
|
|
|
namespaces = rake.namespaces {
|
|
roots = [./system ./releases];
|
|
extraMetadata = import ./namespaces.nix;
|
|
};
|
|
}
|
|
// flake-utils.lib.eachDefaultSystem (system: let
|
|
pkgs = import nixpkgs {
|
|
inherit system;
|
|
overlays = [devshell.overlays.default];
|
|
};
|
|
kubelib = nix-kube-generators.lib {inherit pkgs;};
|
|
|
|
# When I move lib/eureka to a separate flake
|
|
# this'll look something like:
|
|
# lib = import ./lib {...} // {eureka=import ./eureka {...};}
|
|
lib = import ./lib {inherit charts kubelib pkgs;};
|
|
|
|
buildDerivations = import ./lib/flake-builders.nix {inherit pkgs lib;};
|
|
collectDerivations = with pkgs.lib; attrsets.collect isDerivation;
|
|
|
|
charts = buildDerivations.charts self.repos;
|
|
|
|
systemReleases = buildDerivations.releases self.systemReleaseData;
|
|
customApis =
|
|
map
|
|
(chartDrv: lib.gatherApis (builtins.readFile chartDrv.outPath))
|
|
(collectDerivations systemReleases);
|
|
|
|
releases = buildDerivations.releases self.releaseData;
|
|
extras = buildDerivations.extras self.releaseData;
|
|
namespaces = buildDerivations.namespaces self.namespaces;
|
|
in {
|
|
packages = {
|
|
inherit charts;
|
|
|
|
# Useful for debugging; will go to own flake eventually.
|
|
inherit releases extras namespaces lib;
|
|
inherit (self) releaseData;
|
|
inherit customApis;
|
|
|
|
# Each of the leaves of the `releases` and `extras` attrsets
|
|
# is a derivation (explained better in `lib/flake-builders.nix`).
|
|
# Here, they are gathered into one mega-derivation, with
|
|
# Kustomizations at each level for usage with `kubectl apply -k $path`.
|
|
default = let
|
|
pname = "kubeflake"; # TODO: find better name
|
|
in
|
|
pkgs.stdenv.mkDerivation {
|
|
inherit pname;
|
|
version = "0.0.1";
|
|
|
|
release_drvs = collectDerivations releases;
|
|
extra_drvs = collectDerivations extras;
|
|
namespace_drv = namespaces;
|
|
|
|
src = builtins.path {
|
|
path = ./.;
|
|
name = pname;
|
|
};
|
|
|
|
buildInputs = with pkgs; [kustomize];
|
|
phases = ["installPhase"];
|
|
installPhase = builtins.readFile ./lib/output.sh;
|
|
};
|
|
};
|
|
devShell = pkgs.devshell.mkShell {
|
|
imports = [(pkgs.devshell.importTOML ./devshell.toml)];
|
|
};
|
|
formatter = pkgs.alejandra;
|
|
});
|
|
}
|