1
0
Fork 0
mirror of https://git.sr.ht/~goorzhel/turboprop synced 2024-12-14 11:37:37 +00:00
turboprop/flake.nix
Antonio Gurgel 61c040df2c Revert silly name for import flake-builders
Also, clean out unused variables.
2023-11-23 10:22:34 -08:00

122 lines
3.6 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;};
flakeBuilders = import ./lib/flake-builders.nix {inherit charts lib pkgs;};
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;
# 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`.
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;
});
}