about summary refs log tree commit diff
path: root/nixos/modules/installer
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2022-02-21 17:41:34 +0100
committerlassulus <lassulus@lassul.us>2022-04-13 13:25:22 +0200
commit366c8be2add24ecfb14ddc8452189358c9cb1439 (patch)
tree9df49fae8cf1d39e8b7a32f2c22f7539ee3dc452 /nixos/modules/installer
parent1730f14d79a80800c38125f5d61a55f531f10af2 (diff)
downloadnixlib-366c8be2add24ecfb14ddc8452189358c9cb1439.tar
nixlib-366c8be2add24ecfb14ddc8452189358c9cb1439.tar.gz
nixlib-366c8be2add24ecfb14ddc8452189358c9cb1439.tar.bz2
nixlib-366c8be2add24ecfb14ddc8452189358c9cb1439.tar.lz
nixlib-366c8be2add24ecfb14ddc8452189358c9cb1439.tar.xz
nixlib-366c8be2add24ecfb14ddc8452189358c9cb1439.tar.zst
nixlib-366c8be2add24ecfb14ddc8452189358c9cb1439.zip
nixos/installer: add kexec-boot
This module exposes a config.system.build.kexecBoot attribute,
which returns a directory with kernel, initrd and a shell script
running the necessary kexec commands.

It's meant to be scp'ed to a machine with working ssh and kexec binary
installed.

This is useful for (cloud) providers where you can't boot a custom image, but
get some Debian or Ubuntu installation.
Diffstat (limited to 'nixos/modules/installer')
-rw-r--r--nixos/modules/installer/kexec/kexec-boot.nix50
1 files changed, 50 insertions, 0 deletions
diff --git a/nixos/modules/installer/kexec/kexec-boot.nix b/nixos/modules/installer/kexec/kexec-boot.nix
new file mode 100644
index 000000000000..c2f1a64a36a0
--- /dev/null
+++ b/nixos/modules/installer/kexec/kexec-boot.nix
@@ -0,0 +1,50 @@
+# This module exposes a config.system.build.kexecBoot attribute,
+# which returns a directory with kernel, initrd and a shell script
+# running the necessary kexec commands.
+
+# It's meant to be scp'ed to a machine with working ssh and kexec binary
+# installed.
+
+# This is useful for (cloud) providers where you can't boot a custom image, but
+# get some Debian or Ubuntu installation.
+
+{ pkgs
+, modulesPath
+, config
+, ...
+}:
+{
+  imports = [
+    (modulesPath + "/installer/netboot/netboot-minimal.nix")
+  ];
+
+  config = {
+    system.build.kexecBoot =
+      let
+        kexecScript = pkgs.writeScript "kexec-boot" ''
+          #!/usr/bin/env bash
+          if ! kexec -v >/dev/null 2>&1; then
+            echo "kexec not found: please install kexec-tools" 2>&1
+            exit 1
+          fi
+          kexec --load ./bzImage \
+            --initrd=./initrd.gz \
+            --command-line "init=${config.system.build.toplevel}/init ${toString config.boot.kernelParams}"
+          kexec -e
+        ''; in
+      pkgs.linkFarm "kexec-tree" [
+        {
+          name = "initrd.gz";
+          path = "${config.system.build.netbootRamdisk}/initrd";
+        }
+        {
+          name = "bzImage";
+          path = "${config.system.build.kernel}/bzImage";
+        }
+        {
+          name = "kexec-boot";
+          path = kexecScript;
+        }
+      ];
+  };
+}