Refactor machine logic

This commit is contained in:
Pim Kunis 2024-11-04 23:35:04 +01:00
parent fd423b8237
commit 1e80b36037
11 changed files with 53 additions and 114 deletions

View file

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

View file

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

View file

@ -1,43 +1,8 @@
{
nixpkgs,
flake-utils,
...
}:
flake-utils.lib.eachDefaultSystem (system: let
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.
'';
};
};
{...}: {
machines = {
atlas = import ./atlas;
jefke = import ./jefke;
lewis = import ./lewis;
warwick = import ./warwick;
};
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,17 +1,13 @@
{
machines.jefke = {
nixosModule = {
facter.reportPath = ./facter.json;
facter.reportPath = ./facter.json;
lab = {
storage.profile = "kubernetes";
tailscale.enable = true;
lab = {
storage.profile = "kubernetes";
tailscale.enable = true;
k3s = {
enable = true;
clusterInit = true;
};
};
k3s = {
enable = true;
clusterInit = true;
};
};
}

View file

@ -1,19 +1,15 @@
{
machines.lewis = {
nixosModule = {
facter.reportPath = ./facter.json;
facter.reportPath = ./facter.json;
lab = {
storage.profile = "kubernetes";
backups.enable = true;
data-sharing.enable = true;
tailscale.enable = true;
lab = {
storage.profile = "kubernetes";
backups.enable = true;
data-sharing.enable = true;
tailscale.enable = true;
k3s = {
enable = true;
serverAddr = "https://jefke.dmz:6443";
};
};
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 @@
{
machines.warwick = {
nixosModule = {inputs, ...}: {
imports = [inputs.nixos-hardware.nixosModules.raspberry-pi-4];
{inputs, ...}: {
imports = [inputs.nixos-hardware.nixosModules.raspberry-pi-4];
config = {
facter.reportPath = ./facter.json;
config = {
facter.reportPath = ./facter.json;
lab = {
storage.profile = "pi";
monitoring.server.enable = true;
lab = {
storage.profile = "pi";
monitoring.server.enable = true;
tailscale = {
advertiseExitNode = true;
enable = true;
};
};
tailscale = {
advertiseExitNode = true;
enable = true;
};
};
};

View file

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

View file

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

View file

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

View file

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