cluster: refactor nix machinery to fit //ops

This is a chonky refactor that get rids of the previous cluster-centric
defs-* plain nix file setup.

Now, nodes are configured individually in plain nixos modules, and are
provided a view of all other nodes in the 'machines' attribute. Cluster
logic is moved into modules which inspect this array to find other nodes
within the same cluster.

Kubernetes options are not fully clusterified yet (ie., they are still
hardcode to only provide the 'k0' cluster) but that can be fixed later.
The Ceph machinery is a good example of how that can be done.

The new NixOS configs are zero-diff against prod. While this is done
mostly by keeping the logic, we had to keep a few newly discovered
'bugs' around by adding some temporary options which keeps things as they
are. These will be removed in a future CL, then introducing a diff (but
no functional changes, hopefully).

We also remove the nix eval from clustercfg as it was not used anymore
(basically since we refactored certs at some point).

Change-Id: Id79772a96249b0e6344046f96f9c2cb481c4e1f4
Reviewed-on: https://gerrit.hackerspace.pl/c/hscloud/+/1322
Reviewed-by: informatic <informatic@hackerspace.pl>
diff --git a/ops/machines.nix b/ops/machines.nix
index 7dd1232..208279e 100644
--- a/ops/machines.nix
+++ b/ops/machines.nix
@@ -60,23 +60,6 @@
     sha256 = "0p7df7yzi35kblxr5ks0rxxp9cfh269g88xpj60sdhdjvfnn6cp7";
   }) {};
 
-  # Stopgap measure to import //cluster/nix machine definitions into new
-  # //ops/ infrastructure.
-  #
-  # TODO(q3k): inject defs-cluster-k0.nix / defs-machines.nix content via
-  # nixos options instead of having module definitions loading it themselves,
-  # deduplicate list of machines below with defs-machines.nix somehow.
-  clusterMachineConfig = name: [({ config, pkgs, ...}: {
-    # The hostname is used by //cluster/nix machinery to load the appropriate
-    # config from defs-machines into defs-cluster-k0.
-    networking.hostName = name;
-    imports = [
-      ../cluster/nix/modules/base.nix
-      ../cluster/nix/modules/kubernetes.nix
-      ../cluster/nix/modules/ceph.nix
-    ];
-  })];
-
   # mkMachine builds NixOS modules into a NixOS derivation.
   # It:
   #  1) injects passthru.hscloud.provision which deploys that configuration
@@ -85,7 +68,7 @@
   #     of the hscloud readTree object. It will contain whatever nixpkgs
   #     checkout this file has been invoked with, ie. will not be 'mixed in'
   #     with the pkgs argument.
-  mkMachine = pkgs: paths: pkgs.nixos ({ config, pkgs, ... }: {
+  mkMachine = machines: pkgs: paths: pkgs.nixos ({ config, pkgs, ... }: {
     imports = paths;
 
     config = let
@@ -139,20 +122,32 @@
 
       # TODO(q3k): this should be named hscloud, but that seems to not work. Debug and rename.
       _module.args.workspace = hscloud;
+      _module.args.machines = machines;
     };
   });
-in {
-  "bc01n01.hswaw.net"  = mkMachine nixpkgsCluster (clusterMachineConfig "bc01n01");
-  "bc01n02.hswaw.net"  = mkMachine nixpkgsCluster (clusterMachineConfig "bc01n02");
-  "dcr01s22.hswaw.net" = mkMachine nixpkgsCluster (clusterMachineConfig "dcr01s22");
-  "dcr01s24.hswaw.net" = mkMachine nixpkgsCluster (clusterMachineConfig "dcr01s24");
 
-  "edge01.waw.bgp.wtf" = mkMachine nixpkgsBgpwtf [
-    ../bgpwtf/machines/edge01.waw.bgp.wtf.nix
-    ../bgpwtf/machines/edge01.waw.bgp.wtf-hardware.nix
+  mkClusterMachine = machines: path: mkMachine machines nixpkgsCluster [
+    ../cluster/machines/modules/base.nix
+    ../cluster/machines/modules/kube-controlplane.nix
+    ../cluster/machines/modules/kube-dataplane.nix
+    ../cluster/machines/modules/ceph.nix
+    path
   ];
 
-  "customs.hackerspace.pl" = mkMachine pkgs [
-    ../hswaw/machines/customs.hackerspace.pl/configuration.nix
-  ];
-}
+  machines = self: {
+    "bc01n01.hswaw.net" = mkClusterMachine self ../cluster/machines/bc01n01.hswaw.net.nix;
+    "bc01n02.hswaw.net" = mkClusterMachine self ../cluster/machines/bc01n02.hswaw.net.nix;
+    "dcr01s22.hswaw.net" = mkClusterMachine self ../cluster/machines/dcr01s22.hswaw.net.nix;
+    "dcr01s24.hswaw.net" = mkClusterMachine self ../cluster/machines/dcr01s24.hswaw.net.nix;
+
+    "edge01.waw.bgp.wtf" = mkMachine self nixpkgsBgpwtf [
+      ../bgpwtf/machines/edge01.waw.bgp.wtf.nix
+      ../bgpwtf/machines/edge01.waw.bgp.wtf-hardware.nix
+    ];
+
+    "customs.hackerspace.pl" = mkMachine self pkgs [
+      ../hswaw/machines/customs.hackerspace.pl/configuration.nix
+    ];
+  };
+
+in pkgs.lib.fix machines