diff --git a/deploy.nix b/deploy.nix index 7547945..dcfa2a2 100644 --- a/deploy.nix +++ b/deploy.nix @@ -6,14 +6,14 @@ deployArch = "x86_64-linux"; mkDeployNodes = nodeDef: builtins.mapAttrs - (name: module: nodeDef name module) - self.machines; + (name: machine: nodeDef name machine) + self.machines.${deployArch}; in { deploy = { sshUser = "root"; user = "root"; - nodes = mkDeployNodes (name: _module: let + nodes = mkDeployNodes (name: machine: 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 8f55a09..c2d4f98 100644 --- a/machines/atlas/default.nix +++ b/machines/atlas/default.nix @@ -1,13 +1,19 @@ { - facter.reportPath = ./facter.json; + machines.atlas = { + kubernetesNodeLabels.storageType = "slow"; - lab = { - storage.profile = "kubernetes"; - tailscale.enable = true; + nixosModule = { + facter.reportPath = ./facter.json; - k3s = { - enable = true; - serverAddr = "https://jefke.dmz:6443"; + lab = { + storage.profile = "kubernetes"; + tailscale.enable = true; + + k3s = { + enable = true; + serverAddr = "https://jefke.dmz:6443"; + }; + }; }; }; } diff --git a/machines/default.nix b/machines/default.nix index 74151fb..fdbae99 100644 --- a/machines/default.nix +++ b/machines/default.nix @@ -1,8 +1,51 @@ -{...}: { - machines = { - atlas = import ./atlas; - jefke = import ./jefke; - lewis = import ./lewis; - warwick = import ./warwick; +{ + 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. + ''; + }; + + 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; +}) diff --git a/machines/jefke/default.nix b/machines/jefke/default.nix index dd0e03f..742e9b1 100644 --- a/machines/jefke/default.nix +++ b/machines/jefke/default.nix @@ -1,13 +1,19 @@ { - facter.reportPath = ./facter.json; + machines.jefke = { + kubernetesNodeLabels.storageType = "fast"; - lab = { - storage.profile = "kubernetes"; - tailscale.enable = true; + nixosModule = { + facter.reportPath = ./facter.json; - k3s = { - enable = true; - clusterInit = true; + lab = { + storage.profile = "kubernetes"; + tailscale.enable = true; + + k3s = { + enable = true; + clusterInit = true; + }; + }; }; }; } diff --git a/machines/lewis/default.nix b/machines/lewis/default.nix index 9cabbcf..790041f 100644 --- a/machines/lewis/default.nix +++ b/machines/lewis/default.nix @@ -1,15 +1,24 @@ { - facter.reportPath = ./facter.json; + machines.lewis = { + kubernetesNodeLabels = { + storageType = "fast"; + hasMedia = "true"; + }; - lab = { - storage.profile = "kubernetes"; - backups.enable = true; - data-sharing.enable = true; - tailscale.enable = true; + nixosModule = { + facter.reportPath = ./facter.json; - k3s = { - enable = true; - serverAddr = "https://jefke.dmz:6443"; + lab = { + storage.profile = "kubernetes"; + backups.enable = true; + data-sharing.enable = true; + tailscale.enable = true; + + k3s = { + enable = true; + serverAddr = "https://jefke.dmz:6443"; + }; + }; }; }; } diff --git a/machines/talos.nix b/machines/talos.nix new file mode 100644 index 0000000..cbcc0b1 --- /dev/null +++ b/machines/talos.nix @@ -0,0 +1,9 @@ +{ + 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 b3daee7..81bd94f 100644 --- a/machines/warwick/default.nix +++ b/machines/warwick/default.nix @@ -1,16 +1,20 @@ -{inputs, ...}: { - imports = [inputs.nixos-hardware.nixosModules.raspberry-pi-4]; +{ + machines.warwick = { + nixosModule = {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 da36e7d..fe31225 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -3,6 +3,7 @@ pkgs, lib, inputs, + machine, config, ... }: { @@ -15,6 +16,7 @@ ./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 58aa4aa..a67b12e 100644 --- a/modules/monitoring/default.nix +++ b/modules/monitoring/default.nix @@ -38,7 +38,7 @@ in { let generated = lib.attrsets.mapAttrsToList - (name: _module: { + (name: machine: { job_name = name; static_configs = [ { diff --git a/modules/networking/default.nix b/modules/networking/default.nix index 41c0174..ef68c4e 100644 --- a/modules/networking/default.nix +++ b/modules/networking/default.nix @@ -1,6 +1,7 @@ { lib, config, + machine, ... }: { config = { diff --git a/nixos.nix b/nixos.nix index d00b9a5..34f3fb8 100644 --- a/nixos.nix +++ b/nixos.nix @@ -3,24 +3,22 @@ nixpkgs, ... } @ inputs: let + deployArch = "x86_64-linux"; + machines = self.machines.${deployArch}; mkNixosSystems = systemDef: builtins.mapAttrs ( - name: module: - nixpkgs.lib.nixosSystem (systemDef name module) + name: machine: + nixpkgs.lib.nixosSystem (systemDef name machine) ) - self.machines; + machines; in { - nixosConfigurations = mkNixosSystems (name: module: { - specialArgs = { - inherit self inputs; - inherit (self) machines; - }; + nixosConfigurations = mkNixosSystems (name: machine: { + specialArgs = {inherit self inputs machine machines;}; modules = [ "${self}/modules" {networking.hostName = name;} - module ]; }); }