mirror of
https://git.sr.ht/~goorzhel/turboprop
synced 2024-12-15 17:50:52 +00:00
0529bdf6a2
By overlaying nixhelm's charts with those I use for myself, be they behind nixhelm's or simply absent, I get the best of both worlds.
125 lines
3.7 KiB
Nix
125 lines
3.7 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
|
|
{
|
|
# Services expected to provide custom APIs (e.g.: Gateway API,
|
|
# Istio, Longhorn) go in `./system`. All others in `./services`,
|
|
# including resources for the former dependent on other APIs.
|
|
# This prevents infinite recursion when gathering APIs.
|
|
systemServiceData = rake.leaves ./system;
|
|
serviceData = rake.leaves ./services;
|
|
|
|
repos = rake.leaves ./charts;
|
|
|
|
namespaces = rake.namespaces {
|
|
roots = [./system ./services];
|
|
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;};
|
|
|
|
flakeBuilders = import ./lib/flake-builders.nix {inherit charts lib pkgs;};
|
|
|
|
charts =
|
|
pkgs.lib.attrsets.recursiveUpdate
|
|
(nixhelm.charts {inherit pkgs;})
|
|
(flakeBuilders.charts self.repos);
|
|
|
|
systemServices = flakeBuilders.services self.systemServiceData {
|
|
inherit kubeVersion;
|
|
apiVersions = [];
|
|
};
|
|
|
|
clusterData = {
|
|
inherit kubeVersion;
|
|
apiVersions =
|
|
pkgs.lib.lists.flatten
|
|
(map
|
|
(chartDrv: lib.gatherApis chartDrv.outPath)
|
|
(with pkgs.lib; attrsets.collect isDerivation systemServices));
|
|
};
|
|
|
|
services = flakeBuilders.services self.serviceData clusterData;
|
|
namespaces = flakeBuilders.namespaces self.namespaces;
|
|
|
|
paths = flakeBuilders.paths {
|
|
inherit services;
|
|
system = systemServices;
|
|
};
|
|
in {
|
|
packages = {
|
|
inherit charts;
|
|
|
|
# Useful for debugging; will go to own flake eventually.
|
|
inherit systemServices services namespaces lib;
|
|
inherit (self) serviceData;
|
|
inherit clusterData;
|
|
inherit paths;
|
|
|
|
# Each of the leaves of the `services` 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`.
|
|
default = let
|
|
pname = "kubeflake"; # TODO: find better name
|
|
in
|
|
pkgs.stdenv.mkDerivation {
|
|
inherit pname;
|
|
version = "0.0.1";
|
|
|
|
derivation_paths = paths;
|
|
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;
|
|
});
|
|
}
|