about summary refs log tree commit diff
path: root/ops
diff options
context:
space:
mode:
Diffstat (limited to 'ops')
-rw-r--r--ops/nixos/all-systems.nix14
-rw-r--r--ops/nixos/default.nix36
-rw-r--r--ops/nixos/whitby/default.nix6
3 files changed, 49 insertions, 7 deletions
diff --git a/ops/nixos/all-systems.nix b/ops/nixos/all-systems.nix
new file mode 100644
index 000000000000..ba63de2f2dd5
--- /dev/null
+++ b/ops/nixos/all-systems.nix
@@ -0,0 +1,14 @@
+{ depot, ... }:
+
+(with depot.ops.nixos; [
+  whitby
+]) ++
+
+(with depot.users.tazjin.nixos; [
+  camden
+  frog
+]) ++
+
+(with depot.users.glittershark.system.system; [
+  chupacabra
+])
diff --git a/ops/nixos/default.nix b/ops/nixos/default.nix
index a0d7630d00e0..40431a79afaf 100644
--- a/ops/nixos/default.nix
+++ b/ops/nixos/default.nix
@@ -6,8 +6,40 @@
 #
 # TODO(tazjin): Find a more elegant solution for the whole module
 # situation.
-{ ... }@args:
+{ lib, pkgs, depot, ... }@args:
 
-{
+let
+  inherit (lib) findFirst isAttrs;
+in
+
+rec {
   whitby = import ./whitby/default.nix args;
+
+  # System installation
+
+  allSystems = import ./all-systems.nix args;
+
+  nixosFor = configuration: depot.third_party.nixos {
+    inherit configuration;
+  };
+
+  findSystem = hostname:
+    (findFirst
+      (system: system.config.networking.hostName == hostname)
+      (throw "${hostname} is not a known NixOS host")
+      (map nixosFor allSystems));
+
+  rebuild-system = pkgs.writeShellScriptBin "rebuild-system" ''
+    set -ue
+    if [[ $EUID -ne 0 ]]; then
+      echo "Oh no! Only root is allowed to rebuild the system!" >&2
+      exit 1
+    fi
+
+    echo "Rebuilding NixOS for $HOSTNAME"
+    system=$(nix-build -E "((import ${toString depot.depotPath} {}).ops.nixos.findSystem \"$HOSTNAME\").system" --no-out-link --show-trace)
+
+    nix-env -p /nix/var/nix/profiles/system --set $system
+    $system/bin/switch-to-configuration switch
+  '';
 }
diff --git a/ops/nixos/whitby/default.nix b/ops/nixos/whitby/default.nix
index 73066d6b9cad..b1055ddd2ee1 100644
--- a/ops/nixos/whitby/default.nix
+++ b/ops/nixos/whitby/default.nix
@@ -12,11 +12,7 @@ let
     mkdir -p $out/bin
     ln -s ${depot.ops.besadii}/bin/besadii $out/bin/post-command
   '';
-
-  systemForConfig = configuration: (depot.third_party.nixos {
-    inherit configuration;
-  }).system;
-in systemForConfig {
+in {
   inherit depot;
   imports = [
     "${depot.depotPath}/ops/nixos/depot.nix"