|
12 | 12 | (import ./config.nix args) |
13 | 13 | ]; |
14 | 14 |
|
15 | | - boot.initrd.compressor = "xz"; |
| 15 | + boot.initrd.compressor = "cat"; |
16 | 16 |
|
17 | 17 | # https://github.com/nix-community/nixos-images/blob/main/nix/kexec-installer/module.nix#L50 |
18 | 18 | system.build.kexecInstallerTarball = pkgs.runCommand "kexec-tarball" { } '' |
19 | 19 | mkdir xnodeos $out |
20 | | - cp "${config.system.build.netbootRamdisk}/initrd" xnodeos/initrd |
| 20 | + cp "${config.system.build.netbootRamdisk}/initrd" xnodeos/initrd-base |
21 | 21 | cp "${config.system.build.kernel}/${config.system.boot.loader.kernelFile}" xnodeos/bzImage |
22 | 22 | cp "${config.system.build.kexecScript}" xnodeos/install |
23 | 23 | cp "${pkgs.pkgsStatic.kexec-tools}/bin/kexec" xnodeos/kexec |
| 24 | + cp "${pkgs.pkgsStatic.coreutils}/bin/cp" xnodeos/cp |
| 25 | + cp "${pkgs.pkgsStatic.coreutils}/bin/mkdir" xnodeos/mkdir |
| 26 | + cp "${pkgs.pkgsStatic.findutils}/bin/find" xnodeos/find |
24 | 27 | cp "${pkgs.pkgsStatic.iproute2.override { iptables = null; }}/bin/ip" xnodeos/ip |
| 28 | + cp "${pkgs.pkgsStatic.cpio}/bin/cpio" xnodeos/cpio |
25 | 29 | tar -czvf $out/xnodeos-kexec-installer-${pkgs.stdenv.hostPlatform.system}.tar.gz xnodeos |
26 | 30 | ''; |
27 | 31 |
|
|
31 | 35 | pkgs.writeScript "kexec-boot" '' |
32 | 36 | #!/usr/bin/env bash |
33 | 37 | SCRIPT_DIR=$( cd -- "$( dirname -- "''${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) |
34 | | - NETWORK_CONFIG="{ \"address\": $(''${SCRIPT_DIR}/ip -j address show), \"route\": $(''${SCRIPT_DIR}/ip -j route show) }" |
35 | | - ''${SCRIPT_DIR}/kexec --load ''${SCRIPT_DIR}/bzImage \ |
36 | | - --initrd=''${SCRIPT_DIR}/initrd \ |
37 | | - --command-line "init=${config.system.build.toplevel}/init ${toString config.boot.kernelParams} && $(cat << EOF |
| 38 | + cd ''${SCRIPT_DIR} |
38 | 39 |
|
| 40 | + ./mkdir -p ./xnode-config |
| 41 | +
|
| 42 | + NETWORK_CONFIG=$(echo "{ \"address\": $(./ip --json address show), \"route\": $(./ip --json route show) }" | sed 's/"/\\"/g') |
| 43 | + cat << EOF > ./xnode-config/env |
39 | 44 | export XNODE_OWNER="''${XNODE_OWNER}" && export DOMAIN="''${DOMAIN}" && export ACME_EMAIL="''${ACME_EMAIL}" && export USER_PASSWD="''${USER_PASSWD}" && export ENCRYPTED="''${ENCRYPTED}" && export NETWORK_CONFIG="''${NETWORK_CONFIG}" && export INITIAL_CONFIG="''${INITIAL_CONFIG}" |
40 | 45 | EOF |
41 | | - )" |
42 | | - ''${SCRIPT_DIR}/kexec -e |
| 46 | +
|
| 47 | + cp ./initrd-base ./initrd |
| 48 | + ./find ./xnode-config | ./cpio --format newc --create >> ./initrd |
| 49 | +
|
| 50 | + ./kexec --load ./bzImage \ |
| 51 | + --initrd=./initrd \ |
| 52 | + --command-line "init=${config.system.build.toplevel}/init ${toString config.boot.kernelParams}" |
| 53 | + ./kexec -e |
43 | 54 | '' |
44 | 55 | ); |
45 | 56 |
|
| 57 | + boot.initrd.systemd.enable = true; |
| 58 | + boot.initrd.systemd.services.restore-config-from-initrd = { |
| 59 | + unitConfig = { |
| 60 | + DefaultDependencies = false; |
| 61 | + RequiresMountsFor = "/sysroot /dev"; |
| 62 | + }; |
| 63 | + wantedBy = [ "initrd.target" ]; |
| 64 | + requiredBy = [ "rw-etc.service" ]; |
| 65 | + before = [ "rw-etc.service" ]; |
| 66 | + serviceConfig.Type = "oneshot"; |
| 67 | + script = '' |
| 68 | + cp -r xnode-config /sysroot |
| 69 | + ''; |
| 70 | + }; |
| 71 | + |
46 | 72 | systemd.services.install-xnodeos.script = lib.mkBefore '' |
47 | 73 | # Extract environmental variables |
48 | | - sed '2q;d' /proc/cmdline > /tmp/xnode-env |
49 | | - source /tmp/xnode-env |
| 74 | + source /xnode-config/env |
50 | 75 | ''; |
51 | 76 |
|
52 | 77 | systemd.services.apply-network-config = { |
|
66 | 91 | ]; |
67 | 92 | script = '' |
68 | 93 | # Extract environmental variables |
69 | | - sed '2q;d' /proc/cmdline > /tmp/xnode-env |
70 | | - source /tmp/xnode-env |
| 94 | + source /xnode-config/env |
71 | 95 |
|
72 | 96 | if [[ $NETWORK_CONFIG ]]; then |
73 | 97 | interfaces=$(echo "$NETWORK_CONFIG" | jq -c '.address.[]') |
|
0 commit comments