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,8 +1,4 @@
{ {
machines.atlas = {
kubernetesNodeLabels.storageType = "slow";
nixosModule = {
facter.reportPath = ./facter.json; facter.reportPath = ./facter.json;
lab = { lab = {
@ -14,6 +10,4 @@
serverAddr = "https://jefke.dmz:6443"; 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,8 +1,4 @@
{ {
machines.jefke = {
kubernetesNodeLabels.storageType = "fast";
nixosModule = {
facter.reportPath = ./facter.json; facter.reportPath = ./facter.json;
lab = { lab = {
@ -14,6 +10,4 @@
clusterInit = true; clusterInit = true;
}; };
}; };
};
};
} }

View file

@ -1,11 +1,4 @@
{ {
machines.lewis = {
kubernetesNodeLabels = {
storageType = "fast";
hasMedia = "true";
};
nixosModule = {
facter.reportPath = ./facter.json; facter.reportPath = ./facter.json;
lab = { lab = {
@ -19,6 +12,4 @@
serverAddr = "https://jefke.dmz:6443"; 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,6 +1,4 @@
{ {inputs, ...}: {
machines.warwick = {
nixosModule = {inputs, ...}: {
imports = [inputs.nixos-hardware.nixosModules.raspberry-pi-4]; imports = [inputs.nixos-hardware.nixosModules.raspberry-pi-4];
config = { config = {
@ -16,6 +14,4 @@
}; };
}; };
}; };
};
};
} }

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
]; ];
}); });
} }