kexec-host.nix 2.08 KB
Newer Older
Matthias Adamczyk's avatar
Matthias Adamczyk committed
1
2
3
4
{ lib, pkgs, config, modulesPath, ... }:

{
  imports = [
Matthias Adamczyk's avatar
Fix CI    
Matthias Adamczyk committed
5
    (modulesPath + "/installer/netboot/netboot.nix")
Matthias Adamczyk's avatar
Matthias Adamczyk committed
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
    ../common
  ];

  boot.loader.grub.enable = false;
  systemd.services.sshd.wantedBy = lib.mkForce [ "multi-user.target" ];
  networking.hostName = "kexec";

  boot.kernelPackages = lib.mkForce pkgs.linuxPackages;

  services.nginx.enable = lib.mkForce false;
  security.acme.certs = lib.mkForce {};

  #networking.usePredictableInterfaceNames = false;
  #networking.interfaces.eth0.ipv4.addresses = [
  #  { address = "..."; prefixLength = ...; }
  #];
  #networking.interfaces.eth0.ipv6.addresses = [
  #  { address = "..."; prefixLength = ...; }
  #];
  #networking.defaultGateway6 = { address = "fe80::1"; interface = "eth0"; };
  #networking.defaultGateway = { address = "..."; interface = "eth0"; };
  #networking.nameservers = [
  #  "2606:4700:4700::1111"
  #  "2606:4700:4700::1001"
  #  "1.1.1.1"
  #  "1.0.0.1"
  #];

  system.build = rec {
    image = pkgs.runCommand "image" { buildInputs = [ pkgs.nukeReferences ]; } ''
      mkdir $out
      cp ${config.system.build.kernel}/bzImage $out/kernel
      cp ${config.system.build.netbootRamdisk}/initrd $out/initrd
      echo "init=${builtins.unsafeDiscardStringContext config.system.build.toplevel}/init ${toString config.boot.kernelParams}" > $out/cmdline
      nuke-refs $out/kernel
    '';
    kexec_script = pkgs.writeTextFile {
      executable = true;
      name = "kexec-nixos";
      text = ''
        #!${pkgs.stdenv.shell}
        export PATH=${pkgs.kexectools}/bin:${pkgs.cpio}/bin:$PATH
        set -xe
        kexec -l ${image}/kernel --initrd=${image}/initrd --append="init=${builtins.unsafeDiscardStringContext config.system.build.toplevel}/init ${toString config.boot.kernelParams}"
        sync
        echo "executing kernel, filesystems will be improperly umounted"
        kexec -e
      '';
    };
  };
  system.build.kexec_tarball = pkgs.callPackage (modulesPath + "/../lib/make-system-tarball.nix") {
    storeContents = [
      { object = config.system.build.kexec_script; symlink = "/kexec_nixos"; }
    ];
    contents = [];
  };
}