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 3b5168fdc0 Identify another messy refactor on the horizon
Packages can either output new APIs or expect them in the cluster.

Examples of packages which
- output APIs: Gateway API, which installs various versions of
  gateway.networking.k8s.io resources.
- take APIs as input: app-template, which queries the cluster to
  choose v1a2, v1b1, or v1 for its HTTPRoute (etc.) objects.

("Packages" here collectively refers to Helm charts and YAML bundles.)

I will have to impose strict ordering on them, i.e., build the former
before the latter.
2023-11-20 21:46:44 -08:00

99 lines
3 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
{
# systemData = rake.leaves ./system;
# serviceData = rake.leaves ./services;
releaseData = rake.leaves ./releases;
repos = rake.leaves ./charts;
namespaces = rake.namespaces {
root = ./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;
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;
inherit (self) releaseData;
# 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;
});
}