From 4ea15b6a9c2749e3efde77e143a25b910106ce62 Mon Sep 17 00:00:00 2001
From: matt1432 <matt@nelim.org>
Date: Sun, 21 Jan 2024 20:08:27 -0500
Subject: [PATCH] feat(servers): add init cluster hw configs

---
 devices/binto/hardware-configuration.nix   |  1 +
 devices/cluster/default.nix                | 43 +++++++++++++++++++
 devices/cluster/hardware-configuration.nix | 48 ++++++++++++++++++++++
 flake.nix                                  |  8 ++++
 4 files changed, 100 insertions(+)
 create mode 100644 devices/cluster/default.nix
 create mode 100644 devices/cluster/hardware-configuration.nix

diff --git a/devices/binto/hardware-configuration.nix b/devices/binto/hardware-configuration.nix
index 7b07e8fb..55d32cf9 100644
--- a/devices/binto/hardware-configuration.nix
+++ b/devices/binto/hardware-configuration.nix
@@ -67,6 +67,7 @@
 
   virtualisation = {
     libvirtd.enable = true;
+    spiceUSBRedirection.enable = true;
   };
   environment.systemPackages = with pkgs; [
     qemu
diff --git a/devices/cluster/default.nix b/devices/cluster/default.nix
new file mode 100644
index 00000000..c5b1635b
--- /dev/null
+++ b/devices/cluster/default.nix
@@ -0,0 +1,43 @@
+deviceName: {config, ...}: let
+  inherit (config.vars) mainUser hostName;
+in {
+  imports = [
+    ./hardware-configuration.nix
+
+    ../../modules/kmscon.nix
+    ../../modules/sshd.nix
+    ../../modules/tailscale.nix
+  ];
+
+  vars = {
+    mainUser = "matt";
+    hostName = deviceName;
+  };
+
+  users.users.${mainUser} = {
+    isNormalUser = true;
+    extraGroups = [
+      "wheel"
+      "adm"
+    ];
+  };
+
+  home-manager.users.${mainUser} = {
+    imports = [];
+
+    # No touchy
+    home.stateVersion = "24.05";
+  };
+
+  networking = {
+    inherit hostName;
+    resolvconf.enable = true;
+    firewall.enable = false;
+  };
+
+  # Set your time zone.
+  time.timeZone = "America/Montreal";
+
+  # No touchy
+  system.stateVersion = "24.05";
+}
diff --git a/devices/cluster/hardware-configuration.nix b/devices/cluster/hardware-configuration.nix
new file mode 100644
index 00000000..7d12a4cc
--- /dev/null
+++ b/devices/cluster/hardware-configuration.nix
@@ -0,0 +1,48 @@
+{
+  config,
+  modulesPath,
+  ...
+}: {
+  nixpkgs.hostPlatform = "x86_64-linux";
+  imports = [(modulesPath + "/installer/scan/not-detected.nix")];
+
+  boot = {
+    loader = {
+      timeout = 2;
+
+      systemd-boot.enable = true;
+      efi.canTouchEfiVariables = true;
+    };
+
+    initrd.availableKernelModules = [
+      "xhci_pci"
+      "ahci"
+      "usbhid"
+      "usb_storage"
+      "sd_mod"
+    ];
+  };
+
+  fileSystems = {
+    "/" = {
+      device = "/dev/disk/by-label/NIXROOT";
+      fsType = "btrfs";
+    };
+
+    "/boot" = {
+      device = "/dev/disk/by-label/NIXBOOT";
+      fsType = "vfat";
+    };
+  };
+
+  swapDevices = [
+    {
+      device = "/var/lib/swapfile";
+      size = 16 * 1024;
+    }
+  ];
+
+  zramSwap.enable = true;
+
+  hardware.cpu.intel.updateMicrocode = config.hardware.enableRedistributableFirmware;
+}
diff --git a/flake.nix b/flake.nix
index ac4af89a..6b4b7453 100644
--- a/flake.nix
+++ b/flake.nix
@@ -48,6 +48,14 @@
         secrets.nixosModules.oksys
       ];
 
+      # Cluster
+      thingone = mkNixOS [
+        (import ./devices/cluster "thingone")
+      ];
+      thingtwo = mkNixOS [
+        (import ./devices/cluster "thingtwo")
+      ];
+
       live-image = mkNixOS [
         ("${nixpkgs}/nixos/modules/installer/"
           + "cd-dvd/installation-cd-minimal.nix")