2022-09-04 14:57:14 +02:00
|
|
|
{ config, lib, modulesPath, pkgs, ... }:
|
2022-11-25 10:08:39 +01:00
|
|
|
let
|
2023-05-15 14:54:05 +02:00
|
|
|
restore-network = pkgs.writers.writePython3 "restore-network" { flakeIgnore = [ "E501" ]; }
|
|
|
|
./restore_routes.py;
|
2022-12-01 16:11:43 +01:00
|
|
|
|
|
|
|
# does not link with iptables enabled
|
|
|
|
iprouteStatic = pkgs.pkgsStatic.iproute2.override { iptables = null; };
|
2023-05-15 14:54:05 +02:00
|
|
|
in
|
|
|
|
{
|
2022-09-04 14:57:14 +02:00
|
|
|
imports = [
|
|
|
|
(modulesPath + "/installer/netboot/netboot-minimal.nix")
|
2023-05-15 14:54:05 +02:00
|
|
|
../installer.nix
|
2024-04-16 12:23:50 +02:00
|
|
|
../networkd.nix
|
|
|
|
../serial.nix
|
|
|
|
../restore-remote-access.nix
|
2022-09-04 14:57:14 +02:00
|
|
|
];
|
2023-05-07 21:06:12 +02:00
|
|
|
options = {
|
|
|
|
system.kexec-installer.name = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
default = "nixos-kexec-installer";
|
|
|
|
description = ''
|
|
|
|
The variant of the kexec installer to use.
|
|
|
|
'';
|
2022-11-27 19:56:24 +01:00
|
|
|
};
|
2023-05-07 21:06:12 +02:00
|
|
|
};
|
2022-11-25 09:58:23 +01:00
|
|
|
|
2023-05-07 21:06:12 +02:00
|
|
|
config = {
|
|
|
|
# This is a variant of the upstream kexecScript that also allows embedding
|
|
|
|
# a ssh key.
|
2023-05-15 14:54:05 +02:00
|
|
|
system.build.kexecRun = pkgs.runCommand "kexec-run" { } ''
|
2023-05-07 21:06:12 +02:00
|
|
|
install -D -m 0755 ${./kexec-run.sh} $out
|
|
|
|
|
|
|
|
sed -i \
|
|
|
|
-e 's|@init@|${config.system.build.toplevel}/init|' \
|
|
|
|
-e 's|@kernelParams@|${lib.escapeShellArgs config.boot.kernelParams}|' \
|
|
|
|
$out
|
|
|
|
|
|
|
|
${pkgs.shellcheck}/bin/shellcheck $out
|
|
|
|
'';
|
|
|
|
|
2023-05-15 14:54:05 +02:00
|
|
|
system.build.kexecTarball = pkgs.runCommand "kexec-tarball" { } ''
|
2023-05-07 21:06:12 +02:00
|
|
|
mkdir kexec $out
|
|
|
|
cp "${config.system.build.netbootRamdisk}/initrd" kexec/initrd
|
|
|
|
cp "${config.system.build.kernel}/${config.system.boot.loader.kernelFile}" kexec/bzImage
|
|
|
|
cp "${config.system.build.kexecRun}" kexec/run
|
|
|
|
cp "${pkgs.pkgsStatic.kexec-tools}/bin/kexec" kexec/kexec
|
|
|
|
cp "${iprouteStatic}/bin/ip" kexec/ip
|
2023-05-15 12:04:37 +02:00
|
|
|
${lib.optionalString (pkgs.hostPlatform == pkgs.buildPlatform) ''
|
|
|
|
kexec/ip -V
|
|
|
|
kexec/kexec --version
|
|
|
|
''}
|
2023-05-07 21:06:12 +02:00
|
|
|
tar -czvf $out/${config.system.kexec-installer.name}-${pkgs.stdenv.hostPlatform.system}.tar.gz kexec
|
|
|
|
'';
|
|
|
|
|
|
|
|
# for detection if we are on kexec
|
|
|
|
environment.etc.is_kexec.text = "true";
|
|
|
|
|
|
|
|
systemd.services.restore-network = {
|
|
|
|
before = [ "network-pre.target" ];
|
|
|
|
wants = [ "network-pre.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
|
|
|
RemainAfterExit = true;
|
|
|
|
ExecStart = [
|
|
|
|
"${restore-network} /root/network/addrs.json /root/network/routes-v4.json /root/network/routes-v6.json /etc/systemd/network"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
unitConfig.ConditionPathExists = [
|
|
|
|
"/root/network/addrs.json"
|
|
|
|
"/root/network/routes-v4.json"
|
|
|
|
"/root/network/routes-v6.json"
|
2023-01-05 11:04:16 +01:00
|
|
|
];
|
|
|
|
};
|
2023-05-07 21:06:12 +02:00
|
|
|
};
|
2022-09-04 14:57:14 +02:00
|
|
|
}
|