mirror of
https://git.sr.ht/~goorzhel/turboprop
synced 2024-12-14 11:37:37 +00:00
e8016e5bc5
I try to insert line breaks where a thought fragment ends (a habit learnt from writing subtitles), but in comments and Git commit messages it doesn't make as much sense.
120 lines
3.8 KiB
Nix
120 lines
3.8 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`.
|
|
# This prevents infinite recursion when gathering APIs.
|
|
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];
|
|
};
|
|
kubeVersion = pkgs.k3s.version;
|
|
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 charts lib pkgs;};
|
|
collectDerivations = with pkgs.lib; attrsets.collect isDerivation;
|
|
|
|
charts = buildDerivations.charts self.repos;
|
|
|
|
systemReleases = buildDerivations.releases self.systemReleaseData {
|
|
inherit kubeVersion;
|
|
apiVersions = [];
|
|
};
|
|
|
|
clusterData = {
|
|
inherit kubeVersion;
|
|
apiVersions =
|
|
pkgs.lib.lists.flatten
|
|
(map
|
|
(chartDrv: lib.gatherApis chartDrv.outPath)
|
|
(collectDerivations systemReleases));
|
|
};
|
|
|
|
releases = buildDerivations.releases self.releaseData clusterData;
|
|
systemExtras = buildDerivations.extras self.systemReleaseData;
|
|
extras = buildDerivations.extras self.releaseData;
|
|
namespaces = buildDerivations.namespaces self.namespaces;
|
|
in {
|
|
packages = {
|
|
inherit charts;
|
|
|
|
# Useful for debugging; will go to own flake eventually.
|
|
inherit systemReleases releases extras namespaces lib;
|
|
inherit (self) releaseData;
|
|
inherit clusterData;
|
|
|
|
# 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 `k apply -k $path`.
|
|
default = let
|
|
pname = "kubeflake"; # TODO: find better name
|
|
in
|
|
pkgs.stdenv.mkDerivation {
|
|
inherit pname;
|
|
version = "0.0.1";
|
|
|
|
system_drvs = collectDerivations systemReleases;
|
|
release_drvs = collectDerivations releases;
|
|
extra_drvs = collectDerivations extras ++ collectDerivations systemExtras;
|
|
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;
|
|
});
|
|
}
|