2024-07-13 18:18:17 +00:00
|
|
|
{ self, pkgs, machines, dns, myLib, flake-utils, kubenix, nixhelm, blog-pim, ... }: flake-utils.lib.eachDefaultSystem
|
2024-04-13 21:25:48 +00:00
|
|
|
(system:
|
|
|
|
let
|
2024-07-17 16:20:49 +00:00
|
|
|
deployScript = (pkgs.writeScriptBin "applyset-deploy.sh" (builtins.readFile ./applyset-deploy.sh)).overrideAttrs (old: {
|
2024-07-13 18:18:17 +00:00
|
|
|
buildCommand = "${old.buildCommand}\npatchShebangs $out";
|
|
|
|
});
|
|
|
|
|
2024-07-17 16:20:49 +00:00
|
|
|
mkKubernetes = name: module: namespace: (kubenix.evalModules.${system} {
|
|
|
|
specialArgs = { inherit namespace myLib blog-pim dns nixhelm system machines; };
|
|
|
|
|
|
|
|
module = { kubenix, ... }:
|
|
|
|
{
|
|
|
|
imports = [
|
|
|
|
kubenix.modules.k8s
|
|
|
|
kubenix.modules.helm
|
|
|
|
"${self}/kubenix-modules/custom"
|
|
|
|
"${self}/kubenix-modules/custom-types.nix"
|
|
|
|
module
|
|
|
|
];
|
|
|
|
|
|
|
|
config = {
|
|
|
|
kubenix.project = name;
|
|
|
|
kubernetes.namespace = namespace;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}).config.kubernetes;
|
|
|
|
|
|
|
|
mkManifest = name: { module, namespace }:
|
|
|
|
{
|
|
|
|
manifest = (mkKubernetes name module namespace).result;
|
|
|
|
};
|
|
|
|
|
|
|
|
mkDeployApp = name: { module, namespace }:
|
2024-07-13 18:18:17 +00:00
|
|
|
let
|
2024-07-17 16:20:49 +00:00
|
|
|
kubernetes = mkKubernetes name module namespace;
|
2024-07-13 18:18:17 +00:00
|
|
|
kubeconfig = kubernetes.kubeconfig or "";
|
|
|
|
result = kubernetes.result or "";
|
|
|
|
|
|
|
|
wrappedDeployScript = pkgs.symlinkJoin
|
|
|
|
{
|
2024-07-17 16:20:49 +00:00
|
|
|
name = "applyset-deploy.sh";
|
2024-07-13 18:18:17 +00:00
|
|
|
paths = [ deployScript pkgs.vals pkgs.kubectl ];
|
|
|
|
buildInputs = [ pkgs.makeWrapper ];
|
|
|
|
passthru.manifest = result;
|
2024-07-17 16:20:49 +00:00
|
|
|
meta.mainProgram = "applyset-deploy.sh";
|
2024-07-13 18:18:17 +00:00
|
|
|
|
|
|
|
postBuild = ''
|
2024-07-17 16:20:49 +00:00
|
|
|
wrapProgram $out/bin/applyset-deploy.sh \
|
2024-07-13 18:18:17 +00:00
|
|
|
--suffix PATH : "$out/bin" \
|
|
|
|
--run 'export KUBECONFIG=''${KUBECONFIG:-${toString kubeconfig}}' \
|
|
|
|
--set MANIFEST '${result}' \
|
2024-07-17 16:20:49 +00:00
|
|
|
--set APPLYSET 'applyset-${name}' \
|
2024-07-13 18:18:17 +00:00
|
|
|
--set NAMESPACE '${namespace}'
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
in
|
|
|
|
{
|
2024-07-17 16:20:49 +00:00
|
|
|
deploy = {
|
|
|
|
type = "app";
|
|
|
|
program = "${pkgs.lib.getExe wrappedDeployScript}";
|
|
|
|
};
|
2024-07-17 14:25:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
deployers = {
|
|
|
|
bootstrap-default = {
|
2024-07-17 15:20:39 +00:00
|
|
|
module = "${self}/kubenix-modules/bootstrap-default.nix";
|
2024-07-17 14:25:41 +00:00
|
|
|
namespace = "default";
|
|
|
|
};
|
|
|
|
|
|
|
|
bootstrap-kube-system = {
|
2024-07-17 15:20:39 +00:00
|
|
|
module = "${self}/kubenix-modules/bootstrap-kube-system.nix";
|
2024-07-17 14:25:41 +00:00
|
|
|
namespace = "kube-system";
|
|
|
|
};
|
|
|
|
|
|
|
|
cyberchef = {
|
|
|
|
module = "${self}/kubenix-modules/cyberchef.nix";
|
|
|
|
namespace = "static-websites";
|
|
|
|
};
|
|
|
|
|
|
|
|
freshrss = {
|
|
|
|
module = "${self}/kubenix-modules/freshrss.nix";
|
|
|
|
namespace = "freshrss";
|
|
|
|
};
|
|
|
|
|
|
|
|
radicale = {
|
|
|
|
module = "${self}/kubenix-modules/radicale.nix";
|
|
|
|
namespace = "radicale";
|
|
|
|
};
|
|
|
|
|
|
|
|
kms = {
|
|
|
|
module = "${self}/kubenix-modules/kms.nix";
|
|
|
|
namespace = "kms";
|
|
|
|
};
|
|
|
|
|
|
|
|
atuin = {
|
|
|
|
module = "${self}/kubenix-modules/atuin.nix";
|
|
|
|
namespace = "atuin";
|
|
|
|
};
|
|
|
|
|
|
|
|
blog = {
|
|
|
|
module = "${self}/kubenix-modules/blog.nix";
|
|
|
|
namespace = "static-websites";
|
|
|
|
};
|
|
|
|
|
|
|
|
nextcloud = {
|
|
|
|
module = "${self}/kubenix-modules/nextcloud.nix";
|
|
|
|
namespace = "nextcloud";
|
|
|
|
};
|
|
|
|
|
|
|
|
hedgedoc = {
|
|
|
|
module = "${self}/kubenix-modules/hedgedoc.nix";
|
|
|
|
namespace = "hedgedoc";
|
|
|
|
};
|
|
|
|
|
|
|
|
kitchenowl = {
|
|
|
|
module = "${self}/kubenix-modules/kitchenowl.nix";
|
|
|
|
namespace = "kitchenowl";
|
|
|
|
};
|
|
|
|
|
|
|
|
forgejo = {
|
|
|
|
module = "${self}/kubenix-modules/forgejo";
|
|
|
|
namespace = "forgejo";
|
|
|
|
};
|
|
|
|
|
|
|
|
paperless = {
|
|
|
|
module = "${self}/kubenix-modules/paperless.nix";
|
|
|
|
namespace = "paperless";
|
|
|
|
};
|
|
|
|
|
|
|
|
syncthing = {
|
|
|
|
module = "${self}/kubenix-modules/syncthing.nix";
|
|
|
|
namespace = "syncthing";
|
|
|
|
};
|
|
|
|
|
|
|
|
pihole = {
|
|
|
|
module = "${self}/kubenix-modules/pihole.nix";
|
|
|
|
namespace = "dns";
|
|
|
|
};
|
|
|
|
|
|
|
|
immich = {
|
|
|
|
module = "${self}/kubenix-modules/immich.nix";
|
|
|
|
namespace = "immich";
|
|
|
|
};
|
|
|
|
|
|
|
|
attic = {
|
|
|
|
module = "${self}/kubenix-modules/attic.nix";
|
|
|
|
namespace = "attic";
|
|
|
|
};
|
|
|
|
|
|
|
|
inbucket = {
|
|
|
|
module = "${self}/kubenix-modules/inbucket.nix";
|
|
|
|
namespace = "inbucket";
|
|
|
|
};
|
|
|
|
|
|
|
|
dnsmasq = {
|
|
|
|
module = "${self}/kubenix-modules/dnsmasq.nix";
|
|
|
|
namespace = "dns";
|
|
|
|
};
|
|
|
|
|
|
|
|
bind9 = {
|
|
|
|
module = "${self}/kubenix-modules/bind9";
|
|
|
|
namespace = "dns";
|
|
|
|
};
|
|
|
|
|
|
|
|
media = {
|
|
|
|
module = "${self}/kubenix-modules/media.nix";
|
|
|
|
namespace = "media";
|
|
|
|
};
|
|
|
|
|
|
|
|
traefik = {
|
|
|
|
module = "${self}/kubenix-modules/traefik.nix";
|
|
|
|
namespace = "kube-system";
|
|
|
|
};
|
|
|
|
|
|
|
|
minecraft = {
|
|
|
|
module = "${self}/kubenix-modules/minecraft.nix";
|
|
|
|
namespace = "minecraft";
|
2024-07-13 18:18:17 +00:00
|
|
|
};
|
2024-07-17 14:25:41 +00:00
|
|
|
};
|
2024-04-13 21:25:48 +00:00
|
|
|
in
|
|
|
|
{
|
2024-07-17 16:20:49 +00:00
|
|
|
apps = builtins.mapAttrs mkDeployApp deployers;
|
|
|
|
packages = builtins.mapAttrs mkManifest deployers;
|
2024-04-13 14:37:18 +00:00
|
|
|
})
|