2024-10-28 15:05:06 +00:00
|
|
|
inputs @ {
|
|
|
|
self,
|
|
|
|
servers,
|
|
|
|
flake-utils,
|
|
|
|
nixpkgs,
|
|
|
|
kubenix,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
flake-utils.lib.eachDefaultSystem
|
|
|
|
(system: let
|
|
|
|
pkgs = nixpkgs.legacyPackages.${system};
|
|
|
|
lib = pkgs.lib;
|
|
|
|
deployScript = (pkgs.writeScriptBin "applyset-deploy.sh" (builtins.readFile ./applyset-deploy.sh)).overrideAttrs (old: {
|
|
|
|
buildCommand = "${old.buildCommand}\npatchShebangs $out";
|
|
|
|
});
|
2024-09-07 19:59:41 +00:00
|
|
|
|
2024-10-28 15:05:06 +00:00
|
|
|
machines = servers.machines.${system};
|
2024-09-07 19:59:41 +00:00
|
|
|
|
2024-10-28 15:05:06 +00:00
|
|
|
mkKubernetes = name: module: namespace:
|
|
|
|
(kubenix.evalModules.${system} {
|
2024-09-07 19:59:41 +00:00
|
|
|
specialArgs = {
|
2024-10-01 20:51:08 +00:00
|
|
|
inherit namespace system machines self;
|
2024-09-24 21:00:55 +00:00
|
|
|
inherit (inputs) nixhelm blog-pim dns nixpkgs nixng;
|
2024-09-22 19:11:51 +00:00
|
|
|
inherit (self) globals;
|
2024-10-01 20:51:08 +00:00
|
|
|
|
|
|
|
utils = import ./utils.nix {
|
|
|
|
inherit pkgs;
|
|
|
|
inherit (inputs) nixpkgs nixng;
|
|
|
|
inherit (self) globals;
|
|
|
|
};
|
2024-09-07 19:59:41 +00:00
|
|
|
};
|
|
|
|
|
2024-10-28 15:05:06 +00:00
|
|
|
module = {kubenix, ...}: {
|
|
|
|
imports = [
|
|
|
|
kubenix.modules.k8s
|
|
|
|
kubenix.modules.helm
|
|
|
|
./modules
|
|
|
|
module
|
|
|
|
];
|
2024-09-07 19:59:41 +00:00
|
|
|
|
2024-10-28 15:05:06 +00:00
|
|
|
config = {
|
|
|
|
kubenix.project = name;
|
|
|
|
kubernetes.namespace = namespace;
|
2024-09-07 19:59:41 +00:00
|
|
|
};
|
2024-10-28 15:05:06 +00:00
|
|
|
};
|
|
|
|
})
|
|
|
|
.config
|
|
|
|
.kubernetes;
|
2024-09-07 19:59:41 +00:00
|
|
|
|
2024-10-28 15:05:06 +00:00
|
|
|
mkManifest = name: {
|
|
|
|
module,
|
|
|
|
namespace,
|
|
|
|
}: {
|
|
|
|
name = "${name}-manifest";
|
|
|
|
value = (mkKubernetes name module namespace).result;
|
|
|
|
};
|
2024-09-07 19:59:41 +00:00
|
|
|
|
2024-10-28 15:05:06 +00:00
|
|
|
mkDeployApp = name: {
|
|
|
|
module,
|
|
|
|
namespace,
|
|
|
|
}: let
|
|
|
|
kubernetes = mkKubernetes name module namespace;
|
|
|
|
kubeconfig = kubernetes.kubeconfig or "";
|
|
|
|
result = kubernetes.result or "";
|
2024-09-07 19:59:41 +00:00
|
|
|
|
2024-10-28 15:05:06 +00:00
|
|
|
wrappedDeployScript =
|
|
|
|
pkgs.symlinkJoin
|
2024-09-07 19:59:41 +00:00
|
|
|
{
|
2024-10-28 15:05:06 +00:00
|
|
|
name = "applyset-deploy.sh";
|
|
|
|
paths = [deployScript pkgs.vals pkgs.kubectl];
|
|
|
|
buildInputs = [pkgs.makeWrapper];
|
|
|
|
passthru.manifest = result;
|
|
|
|
meta.mainProgram = "applyset-deploy.sh";
|
|
|
|
|
|
|
|
postBuild = let
|
|
|
|
# HACK: create normal way of checking if server runs k8s
|
|
|
|
k8sMachines = lib.filterAttrs (n: m: m.kubernetesNodeLabels != null) machines;
|
|
|
|
k8sServerNames = builtins.concatStringsSep " " (builtins.attrNames k8sMachines);
|
|
|
|
in
|
|
|
|
/*
|
|
|
|
bash
|
|
|
|
*/
|
|
|
|
''
|
|
|
|
wrapProgram $out/bin/applyset-deploy.sh \
|
|
|
|
--suffix PATH : "$out/bin" \
|
|
|
|
--run 'export KUBECONFIG=''${KUBECONFIG:-${toString kubeconfig}}' \
|
|
|
|
--set MANIFEST '${result}' \
|
|
|
|
--set NAME '${name}' \
|
|
|
|
--set NAMESPACE '${namespace}' \
|
|
|
|
--set SERVERS '${k8sServerNames}' \
|
|
|
|
--set DYFF '${lib.getExe pkgs.dyff}' \
|
|
|
|
--set GCROOTDIR '/nix/var/nix/gcroots/kubernetes-manifests'
|
|
|
|
'';
|
2024-09-07 19:59:41 +00:00
|
|
|
};
|
2024-10-28 15:05:06 +00:00
|
|
|
in {
|
|
|
|
name = "${name}-deploy";
|
|
|
|
value = wrappedDeployScript;
|
|
|
|
};
|
2024-09-07 19:59:41 +00:00
|
|
|
|
2024-10-28 15:05:06 +00:00
|
|
|
deployments = import ./deployments.nix;
|
|
|
|
in {
|
|
|
|
packages = pkgs.lib.mergeAttrs (pkgs.lib.mapAttrs' mkDeployApp deployments) (pkgs.lib.mapAttrs' mkManifest deployments);
|
|
|
|
})
|