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 = {
|
2022-07-31 10:52:05 +02:00
|
|
|
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable-small";
|
2022-06-12 12:25:46 +02:00
|
|
|
|
2022-05-27 11:41:22 +02:00
|
|
|
colmena.url = "github:zhaofengli/colmena";
|
|
|
|
colmena.inputs.nixpkgs.follows = "nixpkgs";
|
2022-06-12 12:25:46 +02:00
|
|
|
|
2021-11-16 16:28:55 +01:00
|
|
|
serokell-nix.url = "github:serokell/serokell.nix";
|
2022-05-24 21:06:38 +02:00
|
|
|
serokell-nix.inputs.nixpkgs.follows = "nixpkgs";
|
2022-06-12 12:25:46 +02:00
|
|
|
|
2021-11-16 16:28:55 +01:00
|
|
|
vault-secrets.url = "github:serokell/vault-secrets";
|
2022-05-24 21:06:38 +02:00
|
|
|
vault-secrets.inputs.nixpkgs.follows = "nixpkgs";
|
|
|
|
|
2022-05-05 15:16:37 +02:00
|
|
|
minecraft-servers.url = "github:jyooru/nix-minecraft-servers";
|
2022-05-24 21:06:38 +02:00
|
|
|
minecraft-servers.inputs.nixpkgs.follows = "nixpkgs";
|
2022-08-20 12:55:59 +02:00
|
|
|
|
|
|
|
home-manager = {
|
|
|
|
url = "github:nix-community/home-manager";
|
|
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
|
|
};
|
2021-11-16 16:28:55 +01:00
|
|
|
};
|
2021-10-13 16:49:41 +02:00
|
|
|
|
2021-11-17 00:55:01 +01:00
|
|
|
outputs =
|
2022-08-20 12:55:59 +02:00
|
|
|
{ self, nixpkgs, vault-secrets, serokell-nix, minecraft-servers, colmena, home-manager, ... }@inputs:
|
2021-11-16 21:52:43 +01:00
|
|
|
let
|
2021-11-21 15:50:29 +01:00
|
|
|
inherit (nixpkgs) lib;
|
2022-07-30 22:16:44 +02:00
|
|
|
inherit (builtins) filter mapAttrs attrValues concatLists;
|
2021-11-16 21:52:43 +01:00
|
|
|
system = "x86_64-linux";
|
2022-07-30 22:16:44 +02:00
|
|
|
# import and add location qualifier to all hosts
|
|
|
|
hosts = mapAttrs (location: lhosts: map ({ tags ? [ ], ... }@x: x // { tags = [ location ] ++ tags; inherit location; }) lhosts) (import ./nixos/hosts);
|
|
|
|
# flatten hosts to single list
|
|
|
|
flat_hosts = concatLists (attrValues hosts);
|
2022-07-30 17:15:58 +02:00
|
|
|
# Filter all nixos host definitions that are actual nix machines
|
2022-07-30 22:16:44 +02:00
|
|
|
nixHosts = filter ({ nix ? true, ... }: nix) flat_hosts;
|
|
|
|
# Define args each module gets access to (access to hosts is useful for DNS/DHCP)
|
|
|
|
specialArgs = { inherit hosts flat_hosts inputs; };
|
2022-07-30 17:15:58 +02:00
|
|
|
|
2022-07-30 18:02:40 +02:00
|
|
|
# Resolve imports based on a foldername (nixname) and if the host is an LXC container or a VM.
|
2022-07-30 22:16:44 +02:00
|
|
|
resolveImports = { hostname, location, profile ? hostname, lxc ? true, ... }: [
|
2022-07-30 17:15:58 +02:00
|
|
|
./nixos/common
|
2022-07-30 22:16:44 +02:00
|
|
|
"${./.}/nixos/hosts/${location}/${profile}/configuration.nix"
|
2022-07-30 17:15:58 +02:00
|
|
|
] ++ (if lxc then [
|
|
|
|
"${nixpkgs}/nixos/modules/virtualisation/lxc-container.nix"
|
|
|
|
./nixos/common/generic-lxc.nix
|
|
|
|
]
|
|
|
|
else [ ./nixos/common/generic-vm.nix ]);
|
2021-11-21 15:50:29 +01:00
|
|
|
|
2022-07-31 11:01:36 +02:00
|
|
|
mkConfig = { hostname, location, ... }@host: {
|
|
|
|
"${hostname}.${location}" = lib.nixosSystem {
|
2022-07-30 18:02:40 +02:00
|
|
|
inherit system specialArgs;
|
|
|
|
modules = resolveImports host;
|
2021-11-16 16:28:55 +01:00
|
|
|
};
|
2021-10-17 21:02:20 +02:00
|
|
|
};
|
2021-10-18 18:54:07 +02:00
|
|
|
|
2022-07-30 22:57:42 +02:00
|
|
|
mkColmenaHost = { ip, hostname, tags, location, ... }@host: {
|
2022-07-31 11:01:36 +02:00
|
|
|
"${hostname}.${location}" = {
|
2022-07-30 17:15:58 +02:00
|
|
|
imports = resolveImports host;
|
2022-07-30 22:57:42 +02:00
|
|
|
networking = {
|
|
|
|
hostName = hostname;
|
|
|
|
domain = location;
|
|
|
|
};
|
2022-07-30 16:42:46 +02:00
|
|
|
deployment = {
|
2022-07-30 22:16:44 +02:00
|
|
|
inherit tags;
|
2022-07-30 16:42:46 +02:00
|
|
|
targetHost = ip;
|
|
|
|
targetUser = null; # Defaults to $USER
|
2021-11-21 16:32:30 +01:00
|
|
|
};
|
2021-11-21 15:50:29 +01:00
|
|
|
};
|
2021-11-21 16:32:30 +01:00
|
|
|
};
|
2021-10-18 23:26:26 +02:00
|
|
|
|
2022-07-30 18:02:40 +02:00
|
|
|
pkgs = serokell-nix.lib.pkgsWith nixpkgs.legacyPackages.${system} [ vault-secrets.overlay ];
|
2022-05-08 02:13:44 +02:00
|
|
|
in
|
|
|
|
{
|
2022-07-30 23:35:52 +02:00
|
|
|
# Make the nixosConfigurations, mostly for vault-secrets
|
2022-07-30 16:42:46 +02:00
|
|
|
nixosConfigurations = lib.foldr (el: acc: acc // mkConfig el) { } nixHosts;
|
|
|
|
|
2022-07-30 23:35:52 +02:00
|
|
|
# Make the coleman configuration
|
2022-07-30 16:42:46 +02:00
|
|
|
colmena = lib.foldr (el: acc: acc // mkColmenaHost el)
|
|
|
|
{
|
2022-08-20 11:38:55 +02:00
|
|
|
|
|
|
|
null = { ... }: {
|
|
|
|
networking.hostName = "null";
|
|
|
|
|
|
|
|
imports = [
|
|
|
|
./nixos/common
|
|
|
|
./nixos/hosts/other/null/configuration.nix
|
2022-08-20 12:55:59 +02:00
|
|
|
home-manager.nixosModules.home-manager
|
2022-08-20 11:38:55 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
deployment = {
|
|
|
|
allowLocalDeployment = true;
|
|
|
|
targetHost = null;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-07-30 16:42:46 +02:00
|
|
|
meta = {
|
|
|
|
nixpkgs = import nixpkgs {
|
2022-07-30 17:15:58 +02:00
|
|
|
inherit system;
|
2022-07-30 16:42:46 +02:00
|
|
|
overlays = [
|
|
|
|
(import ./nixos/pkgs)
|
|
|
|
minecraft-servers.overlays.default
|
|
|
|
];
|
|
|
|
};
|
2022-07-30 17:15:58 +02:00
|
|
|
inherit specialArgs;
|
2022-07-30 13:12:10 +02:00
|
|
|
};
|
2022-07-30 16:42:46 +02:00
|
|
|
}
|
|
|
|
nixHosts;
|
2022-06-12 17:06:32 +02:00
|
|
|
|
2021-11-16 21:52:43 +01:00
|
|
|
# Use by running `nix develop`
|
2022-07-30 18:02:40 +02:00
|
|
|
devShells.${system}.default = pkgs.mkShell {
|
2021-11-23 17:44:00 +01:00
|
|
|
VAULT_ADDR = "http://vault.olympus:8200/";
|
2021-11-21 16:32:30 +01:00
|
|
|
# This only support bash so just execute zsh in bash as a workaround :/
|
2022-06-12 12:25:46 +02:00
|
|
|
shellHook = "zsh; exit $?";
|
2022-07-30 18:02:40 +02:00
|
|
|
buildInputs = with pkgs; [
|
2022-07-30 23:17:06 +02:00
|
|
|
colmena.packages.x86_64-linux.colmena
|
2021-11-21 15:50:29 +01:00
|
|
|
fluxcd
|
|
|
|
k9s
|
|
|
|
kubectl
|
|
|
|
kubectx
|
2021-11-21 16:32:30 +01:00
|
|
|
terraform
|
2021-11-21 15:50:29 +01:00
|
|
|
nixfmt
|
|
|
|
nixUnstable
|
|
|
|
vault
|
2022-07-31 10:52:05 +02:00
|
|
|
# (vault-push-approle-envs self)
|
|
|
|
# (vault-push-approle-approles self)
|
2021-11-16 16:28:55 +01:00
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
2021-10-13 16:49:41 +02:00
|
|
|
}
|