Compare commits

...

2 commits

Author SHA1 Message Date
1e80b36037 Refactor machine logic 2024-11-04 23:35:04 +01:00
fd423b8237 Move kubernetes node labels to k8s repo 2024-11-04 23:17:39 +01:00
11 changed files with 53 additions and 131 deletions

View file

@ -6,14 +6,14 @@
deployArch = "x86_64-linux"; deployArch = "x86_64-linux";
mkDeployNodes = nodeDef: mkDeployNodes = nodeDef:
builtins.mapAttrs builtins.mapAttrs
(name: machine: nodeDef name machine) (name: module: nodeDef name module)
self.machines.${deployArch}; self.machines;
in { in {
deploy = { deploy = {
sshUser = "root"; sshUser = "root";
user = "root"; user = "root";
nodes = mkDeployNodes (name: machine: let nodes = mkDeployNodes (name: _module: let
nixosConfiguration = self.nixosConfigurations.${name}; nixosConfiguration = self.nixosConfigurations.${name};
machineArch = nixosConfiguration.config.facter.report.system; machineArch = nixosConfiguration.config.facter.report.system;
in { in {

View file

@ -1,19 +1,13 @@
{ {
machines.atlas = { facter.reportPath = ./facter.json;
kubernetesNodeLabels.storageType = "slow";
nixosModule = { lab = {
facter.reportPath = ./facter.json; storage.profile = "kubernetes";
tailscale.enable = true;
lab = { k3s = {
storage.profile = "kubernetes"; enable = true;
tailscale.enable = true; serverAddr = "https://jefke.dmz:6443";
k3s = {
enable = true;
serverAddr = "https://jefke.dmz:6443";
};
};
}; };
}; };
} }

View file

@ -1,51 +1,8 @@
{ {...}: {
nixpkgs, machines = {
flake-utils, atlas = import ./atlas;
... jefke = import ./jefke;
}: lewis = import ./lewis;
flake-utils.lib.eachDefaultSystem (system: let warwick = import ./warwick;
pkgs = nixpkgs.legacyPackages.${system};
lib = pkgs.lib;
machineOpts = {config, ...}: {
options = {
nixosModule = lib.mkOption {
default = {...}: {};
type = lib.types.anything;
description = ''
Customized configuration for this machine in the form of a NixOS module.
'';
};
kubernetesNodeLabels = lib.mkOption {
default = null;
type = with lib.types; nullOr attrs;
description = ''
Any labels to add to the Kubernetes node.
'';
};
};
}; };
}
allOpts = {
options = {
machines = lib.mkOption {
type = with lib.types; attrsOf (submodule machineOpts);
};
};
};
in {
machines =
(lib.modules.evalModules {
modules = [
allOpts
./warwick
./atlas
./jefke
./lewis
# ./talos.nix
];
})
.config
.machines;
})

View file

@ -1,19 +1,13 @@
{ {
machines.jefke = { facter.reportPath = ./facter.json;
kubernetesNodeLabels.storageType = "fast";
nixosModule = { lab = {
facter.reportPath = ./facter.json; storage.profile = "kubernetes";
tailscale.enable = true;
lab = { k3s = {
storage.profile = "kubernetes"; enable = true;
tailscale.enable = true; clusterInit = true;
k3s = {
enable = true;
clusterInit = true;
};
};
}; };
}; };
} }

View file

@ -1,24 +1,15 @@
{ {
machines.lewis = { facter.reportPath = ./facter.json;
kubernetesNodeLabels = {
storageType = "fast";
hasMedia = "true";
};
nixosModule = { lab = {
facter.reportPath = ./facter.json; storage.profile = "kubernetes";
backups.enable = true;
data-sharing.enable = true;
tailscale.enable = true;
lab = { k3s = {
storage.profile = "kubernetes"; enable = true;
backups.enable = true; serverAddr = "https://jefke.dmz:6443";
data-sharing.enable = true;
tailscale.enable = true;
k3s = {
enable = true;
serverAddr = "https://jefke.dmz:6443";
};
};
}; };
}; };
} }

View file

@ -1,9 +0,0 @@
{
machines.talos = {
nixosModule = {lib, ...}: {
lab.storage.profile = "normal";
# boot.loader.systemd-boot.enable = lib.mkForce false;
};
};
}

View file

@ -1,20 +1,16 @@
{ {inputs, ...}: {
machines.warwick = { imports = [inputs.nixos-hardware.nixosModules.raspberry-pi-4];
nixosModule = {inputs, ...}: {
imports = [inputs.nixos-hardware.nixosModules.raspberry-pi-4];
config = { config = {
facter.reportPath = ./facter.json; facter.reportPath = ./facter.json;
lab = { lab = {
storage.profile = "pi"; storage.profile = "pi";
monitoring.server.enable = true; monitoring.server.enable = true;
tailscale = { tailscale = {
advertiseExitNode = true; advertiseExitNode = true;
enable = true; enable = true;
};
};
}; };
}; };
}; };

View file

@ -3,7 +3,6 @@
pkgs, pkgs,
lib, lib,
inputs, inputs,
machine,
config, config,
... ...
}: { }: {
@ -16,7 +15,6 @@
./k3s ./k3s
./tailscale.nix ./tailscale.nix
./facter.nix ./facter.nix
machine.nixosModule
inputs.disko.nixosModules.disko inputs.disko.nixosModules.disko
inputs.sops-nix.nixosModules.sops inputs.sops-nix.nixosModules.sops
inputs.nix-snapshotter.nixosModules.nix-snapshotter inputs.nix-snapshotter.nixosModules.nix-snapshotter

View file

@ -38,7 +38,7 @@ in {
let let
generated = generated =
lib.attrsets.mapAttrsToList lib.attrsets.mapAttrsToList
(name: machine: { (name: _module: {
job_name = name; job_name = name;
static_configs = [ static_configs = [
{ {

View file

@ -1,7 +1,6 @@
{ {
lib, lib,
config, config,
machine,
... ...
}: { }: {
config = { config = {

View file

@ -3,22 +3,24 @@
nixpkgs, nixpkgs,
... ...
} @ inputs: let } @ inputs: let
deployArch = "x86_64-linux";
machines = self.machines.${deployArch};
mkNixosSystems = systemDef: mkNixosSystems = systemDef:
builtins.mapAttrs builtins.mapAttrs
( (
name: machine: name: module:
nixpkgs.lib.nixosSystem (systemDef name machine) nixpkgs.lib.nixosSystem (systemDef name module)
) )
machines; self.machines;
in { in {
nixosConfigurations = mkNixosSystems (name: machine: { nixosConfigurations = mkNixosSystems (name: module: {
specialArgs = {inherit self inputs machine machines;}; specialArgs = {
inherit self inputs;
inherit (self) machines;
};
modules = [ modules = [
"${self}/modules" "${self}/modules"
{networking.hostName = name;} {networking.hostName = name;}
module
]; ];
}); });
} }