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

123 lines
3.6 KiB
Nix
Raw Normal View History

{
2023-11-15 16:43:46 +00:00
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";
};
2023-11-18 10:08:23 +00:00
# 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;
2023-11-15 06:55:56 +00:00
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;};
flakeBuilders = import ./lib/flake-builders.nix {inherit charts lib pkgs;};
2023-11-19 07:22:51 +00:00
collectDerivations = with pkgs.lib; attrsets.collect isDerivation;
charts = flakeBuilders.charts self.repos;
systemReleases = flakeBuilders.releases self.systemReleaseData {
inherit kubeVersion;
apiVersions = [];
};
clusterData = {
inherit kubeVersion;
apiVersions =
pkgs.lib.lists.flatten
(map
(chartDrv: lib.gatherApis chartDrv.outPath)
(collectDerivations systemReleases));
};
releases = flakeBuilders.releases self.releaseData clusterData;
namespaces = flakeBuilders.namespaces self.namespaces;
paths = flakeBuilders.paths {
inherit releases;
system = systemReleases;
};
in {
packages = {
inherit charts;
2023-11-19 19:46:27 +00:00
# Useful for debugging; will go to own flake eventually.
inherit systemReleases releases namespaces lib;
inherit (self) releaseData;
inherit clusterData;
inherit paths;
# Each of the leaves of the `releases` attrset 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`.
2023-11-19 22:23:50 +00:00
default = let
pname = "kubeflake"; # TODO: find better name
in
pkgs.stdenv.mkDerivation {
inherit pname;
version = "0.0.1";
derivation_paths = paths;
2023-11-19 22:23:50 +00:00
namespace_drv = namespaces;
2023-11-19 22:23:50 +00:00
src = builtins.path {
path = ./.;
name = pname;
};
2023-11-19 22:23:50 +00:00
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;
});
}