2021-10-13 16:49:41 +02:00
|
|
|
{
|
|
|
|
description = "Delft Deployment";
|
|
|
|
|
2021-11-21 15:50:29 +01:00
|
|
|
# Based on:
|
|
|
|
# * https://github.com/serokell/pegasus-infra/blob/master/flake.nix
|
|
|
|
# * https://git.voidcorp.nl/j00lz/nixos-configs/src/branch/main/flake.nix
|
2021-11-16 21:52:43 +01:00
|
|
|
|
2021-11-16 16:28:55 +01:00
|
|
|
inputs = {
|
|
|
|
deploy-rs.url = "github:serokell/deploy-rs";
|
|
|
|
nixpkgs.url = "github:NixOS/nixpkgs/master";
|
|
|
|
serokell-nix.url = "github:serokell/serokell.nix";
|
|
|
|
vault-secrets.url = "github:serokell/vault-secrets";
|
|
|
|
};
|
2021-10-13 16:49:41 +02:00
|
|
|
|
2021-11-17 00:55:01 +01:00
|
|
|
outputs =
|
|
|
|
{ self, nixpkgs, deploy-rs, vault-secrets, serokell-nix, ... }@inputs:
|
2021-11-16 21:52:43 +01:00
|
|
|
let
|
2021-11-21 15:50:29 +01:00
|
|
|
inherit (nixpkgs) lib;
|
|
|
|
inherit (builtins) filter;
|
2021-11-16 21:52:43 +01:00
|
|
|
system = "x86_64-linux";
|
2021-11-21 15:50:29 +01:00
|
|
|
merge = a: b: a // b;
|
|
|
|
|
|
|
|
# Create a nixosConfiguration based on a foldername (nixname) and if the host is an LXC container or a VM.
|
|
|
|
mkConfig = nixname: lxc:
|
|
|
|
lib.nixosSystem {
|
2021-11-16 21:52:43 +01:00
|
|
|
inherit system;
|
2021-11-21 15:50:29 +01:00
|
|
|
modules =
|
|
|
|
[ "${./.}/nixos/hosts/${nixname}/configuration.nix" ./nixos/common ]
|
2021-11-21 14:35:09 +01:00
|
|
|
++ (if lxc then [
|
|
|
|
"${nixpkgs}/nixos/modules/virtualisation/lxc-container.nix"
|
|
|
|
./nixos/common/generic-lxc.nix
|
|
|
|
] else
|
|
|
|
[ ./nixos/common/generic-vm.nix ]);
|
2021-11-17 00:55:01 +01:00
|
|
|
specialArgs.inputs = inputs;
|
2021-11-16 16:28:55 +01:00
|
|
|
};
|
2021-11-21 15:50:29 +01:00
|
|
|
|
|
|
|
# Create a deploy-rs config based on profile- and hostname.
|
2021-11-16 21:52:43 +01:00
|
|
|
mkDeploy = hostname: profile: {
|
2021-11-21 15:50:29 +01:00
|
|
|
inherit hostname;
|
2021-11-16 16:28:55 +01:00
|
|
|
fastConnection = true;
|
|
|
|
profiles.system = {
|
|
|
|
user = "root";
|
2021-11-21 15:50:29 +01:00
|
|
|
path = deploy-rs.lib.${system}.activate.nixos
|
|
|
|
self.nixosConfigurations.${profile};
|
2021-11-16 16:28:55 +01:00
|
|
|
};
|
2021-10-17 21:02:20 +02:00
|
|
|
};
|
2021-10-18 18:54:07 +02:00
|
|
|
|
2021-11-21 15:50:29 +01:00
|
|
|
# Convert a host from hosts.nix to something nixosConfigurations understands
|
|
|
|
hostToConfig = { hostname, nixname ? hostname, lxc ? true, ... }:
|
|
|
|
merge {
|
|
|
|
"${nixname}" = mkConfig nixname lxc;
|
|
|
|
};
|
|
|
|
|
|
|
|
# Same as above, but for the nodes part of deploy.
|
|
|
|
hostToDeploy = { ip, hostname, nixname ? hostname, ... }:
|
|
|
|
merge {
|
|
|
|
"${nixname}" = mkDeploy ip nixname;
|
|
|
|
};
|
2021-10-18 23:26:26 +02:00
|
|
|
|
2021-11-21 15:50:29 +01:00
|
|
|
# Import all nixos host definitions that are actual nix machines
|
|
|
|
nixHosts = filter ({ nix ? true, ... }: nix) (import ./nixos/hosts.nix);
|
|
|
|
in {
|
|
|
|
# Make the config and deploy sets
|
|
|
|
nixosConfigurations = lib.foldr hostToConfig { } nixHosts;
|
|
|
|
deploy.nodes = lib.foldr hostToDeploy { } nixHosts;
|
2021-11-03 22:55:03 +01:00
|
|
|
|
2021-11-16 21:52:43 +01:00
|
|
|
# Use by running `nix develop`
|
2021-11-16 16:28:55 +01:00
|
|
|
devShell.${system} = let
|
|
|
|
pkgs = serokell-nix.lib.pkgsWith nixpkgs.legacyPackages.${system}
|
|
|
|
[ vault-secrets.overlay ];
|
|
|
|
in pkgs.mkShell {
|
2021-11-20 23:41:11 +01:00
|
|
|
VAULT_ADDR = "http://10.42.42.6:8200/";
|
2021-11-21 15:50:29 +01:00
|
|
|
buildInputs = with pkgs; [
|
2021-11-16 16:28:55 +01:00
|
|
|
deploy-rs.packages.${system}.deploy-rs
|
2021-11-21 15:50:29 +01:00
|
|
|
fluxcd
|
|
|
|
k9s
|
|
|
|
kubectl
|
|
|
|
kubectx
|
|
|
|
nixfmt
|
|
|
|
nixUnstable
|
|
|
|
vault
|
|
|
|
(vault-push-approle-envs self)
|
|
|
|
(vault-push-approles self)
|
2021-11-16 16:28:55 +01:00
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
checks = builtins.mapAttrs
|
|
|
|
(system: deployLib: deployLib.deployChecks self.deploy) deploy-rs.lib;
|
|
|
|
};
|
2021-10-13 16:49:41 +02:00
|
|
|
}
|