From d988da89ca0b87320ba00847a29dab6f9815d838 Mon Sep 17 00:00:00 2001
From: Jean-Paul Calderone <exarkun@twistedmatrix.com>
Date: Thu, 29 Aug 2019 14:32:12 -0400
Subject: [PATCH] Add one of the 100TB machines - now working, wow.

---
 morph/staging.nix             |  2 +
 morph/staging002-config.nix   |  8 ++++
 morph/staging002-hardware.nix | 37 ++++++++++++++++
 morph/staging002.nix          | 17 ++++++++
 nixos/modules/100tb.nix       | 82 +++++++++++++++++++++++++++++++++++
 5 files changed, 146 insertions(+)
 create mode 100644 morph/staging002-config.nix
 create mode 100644 morph/staging002-hardware.nix
 create mode 100644 morph/staging002.nix
 create mode 100644 nixos/modules/100tb.nix

diff --git a/morph/staging.nix b/morph/staging.nix
index 056f8363..de578484 100644
--- a/morph/staging.nix
+++ b/morph/staging.nix
@@ -24,4 +24,6 @@ in
     publicIPv4 = "209.95.51.251";
     inherit publicStoragePort;
   };
+
+  "staging002" = import ./staging002.nix;
 }
diff --git a/morph/staging002-config.nix b/morph/staging002-config.nix
new file mode 100644
index 00000000..b1d38ecb
--- /dev/null
+++ b/morph/staging002-config.nix
@@ -0,0 +1,8 @@
+{ "interface" = "eno1";
+  "publicIPv4" = "69.36.183.24";
+  "prefixLength" = 24;
+  "gateway" = "69.36.183.1";
+  "gatewayInterface" = "eno1";
+  "grubDeviceID" = "wwn-0x5000c500936410b9";
+  "rootPublicKey" = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIN4GenAY/YLGuf1WoMXyyVa3S9i4JLQ0AG+pt7nvcLlQ exarkun@baryon";
+}
diff --git a/morph/staging002-hardware.nix b/morph/staging002-hardware.nix
new file mode 100644
index 00000000..f0d8c290
--- /dev/null
+++ b/morph/staging002-hardware.nix
@@ -0,0 +1,37 @@
+# Do not modify this file!  It was generated by ‘nixos-generate-config’
+# and may be overwritten by future invocations.  Please make changes
+# to /etc/nixos/configuration.nix instead.
+{ config, lib, pkgs, ... }:
+
+{
+  imports =
+    [ <nixpkgs/nixos/modules/installer/scan/not-detected.nix>
+    ];
+
+  boot.initrd.availableKernelModules = [ "ahci" "xhci_pci" "ehci_pci" "megaraid_sas" "usbhid" "sd_mod" ];
+  boot.initrd.kernelModules = [ ];
+  boot.kernelModules = [ "kvm-intel" ];
+  boot.extraModulePackages = [ ];
+
+  fileSystems."/" =
+    { device = "/dev/disk/by-uuid/ccabaa39-d888-467e-b8d9-75b5790a91aa";
+      fsType = "ext4";
+    };
+
+  fileSystems."/boot" =
+    { device = "/dev/disk/by-uuid/849c8696-a7e6-42d2-810d-15326d9f9ff6";
+      fsType = "ext4";
+    };
+
+  fileSystems."/storage" =
+    { device = "/dev/disk/by-uuid/2745cbf3-5a63-491d-ab92-6dfd4da1b504";
+      fsType = "ext4";
+    };
+
+  swapDevices =
+    [ { device = "/dev/disk/by-uuid/c6f09c9a-572a-4b0f-b792-412cb5c749d4"; }
+    ];
+
+  nix.maxJobs = lib.mkDefault 32;
+  powerManagement.cpuFreqGovernor = lib.mkDefault "powersave";
+}
diff --git a/morph/staging002.nix b/morph/staging002.nix
new file mode 100644
index 00000000..443c127d
--- /dev/null
+++ b/morph/staging002.nix
@@ -0,0 +1,17 @@
+{ config, pkgs, ... }:
+{ imports =
+    [ # Include the results of the hardware scan.
+      ./staging002-hardware.nix
+      # Configure it as a system operated by 100TB.
+      # Instance details are read from <hostName>.config.json
+      ../nixos/modules/100tb.nix
+    ];
+
+  "100tb".config = import ./staging002-config.nix;
+
+  # This value determines the NixOS release with which your system is to be
+  # compatible, in order to avoid breaking some software such as database
+  # servers. You should change this only after NixOS release notes say you
+  # should.
+  system.stateVersion = "19.03"; # Did you read the comment?
+}
diff --git a/nixos/modules/100tb.nix b/nixos/modules/100tb.nix
new file mode 100644
index 00000000..9fd2a93a
--- /dev/null
+++ b/nixos/modules/100tb.nix
@@ -0,0 +1,82 @@
+# A NixOS module which configures a system that is hosted by 100TB.
+{ pkgs, lib, config, ... }:
+let
+  cfg = config."100tb".config;
+  options = {
+    interface = lib.mkOption
+    { type = lib.types.str;
+      example = lib.literalExample "eno0";
+      description = "The name of the network interface on which to configure a static address.";
+
+    };
+    publicIPv4 = lib.mkOption
+    { type = lib.types.str;
+      example = lib.literalExample "192.0.2.0";
+      description = "The IPv4 address to statically assign to `interface`.";
+    };
+    prefixLength = lib.mkOption
+    { type = lib.types.int;
+      example = lib.literalExample 24;
+      description = "The statically configured network's prefix length.";
+    };
+    gateway = lib.mkOption
+    { type = lib.types.str;
+      example = lib.literalExample "192.0.2.1";
+      description = "The statically configured address of the network gateway.";
+    };
+    gatewayInterface = lib.mkOption
+    { type = lib.types.str;
+      example = lib.literalExample "eno0";
+      description = "The name of the network interface for the default route.";
+      default = cfg.interface;
+    };
+    grubDeviceID = lib.mkOption
+    { type = lib.types.str;
+      example = lib.literalExample "wwn-0x5000c500936410b9";
+      description = "The ID of the disk on which to install grub.";
+    };
+    rootPublicKey = lib.mkOption
+    { type = lib.types.str;
+      example = lib.literalExample "ssh-ed25519 AAAA... username@host";
+      description = "The public key to install for the root user.";
+    };
+  };
+in {
+  options =
+  { "100tb".config = lib.mkOption
+    { type = lib.types.submodule { inherit options; };
+      description = "Host-specific configuration relevant to a 100TB system.";
+    };
+  };
+
+  config =
+  { boot.loader.timeout = 1;
+    boot.loader.grub.enable = true;
+    boot.loader.grub.version = 2;
+    boot.loader.grub.device = "/dev/disk/by-id/${cfg.grubDeviceID}";
+
+    # Let me in to do subsequent configuration.
+    networking.firewall.enable = false;
+    services.openssh.enable = true;
+
+    users.users.root.openssh.authorizedKeys.keys = [
+      cfg.rootPublicKey
+    ];
+
+    # Provide the static network configuration.
+    networking.dhcpcd.enable = false;
+    networking.interfaces = {
+      "${cfg.interface}".ipv4.addresses = [
+        { address = cfg.publicIPv4; inherit (cfg) prefixLength; }
+      ];
+    };
+    networking.defaultGateway = {
+      address = cfg.gateway;
+      interface = cfg.gatewayInterface;
+    };
+    networking.nameservers = [
+      "4.2.2.1"
+      "8.8.8.8"
+    ];
+  };
+}
-- 
GitLab