From fd423b8237384c1718180fd1b177a625ddde0ca3 Mon Sep 17 00:00:00 2001 From: Pim Kunis Date: Mon, 4 Nov 2024 23:17:39 +0100 Subject: [PATCH 1/2] Move kubernetes node labels to k8s repo --- machines/atlas/default.nix | 2 -- machines/default.nix | 8 -------- machines/jefke/default.nix | 2 -- machines/lewis/default.nix | 5 ----- 4 files changed, 17 deletions(-) diff --git a/machines/atlas/default.nix b/machines/atlas/default.nix index c2d4f98..bea4f2c 100644 --- a/machines/atlas/default.nix +++ b/machines/atlas/default.nix @@ -1,7 +1,5 @@ { machines.atlas = { - kubernetesNodeLabels.storageType = "slow"; - nixosModule = { facter.reportPath = ./facter.json; diff --git a/machines/default.nix b/machines/default.nix index fdbae99..59d4f2e 100644 --- a/machines/default.nix +++ b/machines/default.nix @@ -16,14 +16,6 @@ flake-utils.lib.eachDefaultSystem (system: let 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. - ''; - }; }; }; diff --git a/machines/jefke/default.nix b/machines/jefke/default.nix index 742e9b1..3502ab1 100644 --- a/machines/jefke/default.nix +++ b/machines/jefke/default.nix @@ -1,7 +1,5 @@ { machines.jefke = { - kubernetesNodeLabels.storageType = "fast"; - nixosModule = { facter.reportPath = ./facter.json; diff --git a/machines/lewis/default.nix b/machines/lewis/default.nix index 790041f..47aef36 100644 --- a/machines/lewis/default.nix +++ b/machines/lewis/default.nix @@ -1,10 +1,5 @@ { machines.lewis = { - kubernetesNodeLabels = { - storageType = "fast"; - hasMedia = "true"; - }; - nixosModule = { facter.reportPath = ./facter.json; From 1e80b3603777ce600ef8374d12d823c909e92408 Mon Sep 17 00:00:00 2001 From: Pim Kunis Date: Mon, 4 Nov 2024 23:35:04 +0100 Subject: [PATCH 2/2] Refactor machine logic --- deploy.nix | 6 ++--- machines/atlas/default.nix | 18 +++++-------- machines/default.nix | 49 +++++----------------------------- machines/jefke/default.nix | 18 +++++-------- machines/lewis/default.nix | 22 +++++++-------- machines/talos.nix | 9 ------- machines/warwick/default.nix | 24 +++++++---------- modules/default.nix | 2 -- modules/monitoring/default.nix | 2 +- modules/networking/default.nix | 1 - nixos.nix | 16 ++++++----- 11 files changed, 53 insertions(+), 114 deletions(-) delete mode 100644 machines/talos.nix diff --git a/deploy.nix b/deploy.nix index dcfa2a2..7547945 100644 --- a/deploy.nix +++ b/deploy.nix @@ -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 { diff --git a/machines/atlas/default.nix b/machines/atlas/default.nix index bea4f2c..8f55a09 100644 --- a/machines/atlas/default.nix +++ b/machines/atlas/default.nix @@ -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"; }; }; } diff --git a/machines/default.nix b/machines/default.nix index 59d4f2e..74151fb 100644 --- a/machines/default.nix +++ b/machines/default.nix @@ -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; -}) +} diff --git a/machines/jefke/default.nix b/machines/jefke/default.nix index 3502ab1..dd0e03f 100644 --- a/machines/jefke/default.nix +++ b/machines/jefke/default.nix @@ -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; }; }; } diff --git a/machines/lewis/default.nix b/machines/lewis/default.nix index 47aef36..9cabbcf 100644 --- a/machines/lewis/default.nix +++ b/machines/lewis/default.nix @@ -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"; }; }; } diff --git a/machines/talos.nix b/machines/talos.nix deleted file mode 100644 index cbcc0b1..0000000 --- a/machines/talos.nix +++ /dev/null @@ -1,9 +0,0 @@ -{ - machines.talos = { - nixosModule = {lib, ...}: { - lab.storage.profile = "normal"; - - # boot.loader.systemd-boot.enable = lib.mkForce false; - }; - }; -} diff --git a/machines/warwick/default.nix b/machines/warwick/default.nix index 81bd94f..b3daee7 100644 --- a/machines/warwick/default.nix +++ b/machines/warwick/default.nix @@ -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; }; }; }; diff --git a/modules/default.nix b/modules/default.nix index fe31225..da36e7d 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -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 diff --git a/modules/monitoring/default.nix b/modules/monitoring/default.nix index a67b12e..58aa4aa 100644 --- a/modules/monitoring/default.nix +++ b/modules/monitoring/default.nix @@ -38,7 +38,7 @@ in { let generated = lib.attrsets.mapAttrsToList - (name: machine: { + (name: _module: { job_name = name; static_configs = [ { diff --git a/modules/networking/default.nix b/modules/networking/default.nix index ef68c4e..41c0174 100644 --- a/modules/networking/default.nix +++ b/modules/networking/default.nix @@ -1,7 +1,6 @@ { lib, config, - machine, ... }: { config = { diff --git a/nixos.nix b/nixos.nix index 34f3fb8..d00b9a5 100644 --- a/nixos.nix +++ b/nixos.nix @@ -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 ]; }); }