Skip to content

Commit e84c5e2

Browse files
committed
pass env as initrd addition
1 parent 824fb1e commit e84c5e2

1 file changed

Lines changed: 16 additions & 10 deletions

File tree

os/installer/kexec.nix

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
(import ./config.nix args)
1313
];
1414

15-
boot.initrd.compressor = "xz";
15+
boot.initrd.compressor = "cat";
1616

1717
# https://github.com/nix-community/nixos-images/blob/main/nix/kexec-installer/module.nix#L50
1818
system.build.kexecInstallerTarball = pkgs.runCommand "kexec-tarball" { } ''
@@ -21,7 +21,10 @@
2121
cp "${config.system.build.kernel}/${config.system.boot.loader.kernelFile}" xnodeos/bzImage
2222
cp "${config.system.build.kexecScript}" xnodeos/install
2323
cp "${pkgs.pkgsStatic.kexec-tools}/bin/kexec" xnodeos/kexec
24+
cp "${pkgs.pkgsStatic.coreutils}/bin/mkdir" xnodeos/mkdir
25+
cp "${pkgs.pkgsStatic.findutils}/bin/find" xnodeos/find
2426
cp "${pkgs.pkgsStatic.iproute2.override { iptables = null; }}/bin/ip" xnodeos/ip
27+
cp "${pkgs.pkgsStatic.cpio}/bin/cpio" xnodeos/cpio
2528
tar -czvf $out/xnodeos-kexec-installer-${pkgs.stdenv.hostPlatform.system}.tar.gz xnodeos
2629
'';
2730

@@ -31,22 +34,26 @@
3134
pkgs.writeScript "kexec-boot" ''
3235
#!/usr/bin/env bash
3336
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
3837
38+
''${SCRIPT_DIR}/mkdir xnode-config
39+
40+
NETWORK_CONFIG="{ \"address\": $(''${SCRIPT_DIR}/ip -j address show), \"route\": $(''${SCRIPT_DIR}/ip -j route show) }"
41+
cat << EOF > xnode-config/env
3942
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}"
4043
EOF
41-
)"
44+
45+
''${SCRIPT_DIR}/find ./xnode-config -print | ''${SCRIPT_DIR}/cpio -H newc -o -O ./initrd --append
46+
47+
''${SCRIPT_DIR}/kexec --load ''${SCRIPT_DIR}/bzImage \
48+
--initrd=''${SCRIPT_DIR}/initrd \
49+
--command-line "init=${config.system.build.toplevel}/init ${toString config.boot.kernelParams}"
4250
''${SCRIPT_DIR}/kexec -e
4351
''
4452
);
4553

4654
systemd.services.install-xnodeos.script = lib.mkBefore ''
4755
# Extract environmental variables
48-
sed '2q;d' /proc/cmdline > /tmp/xnode-env
49-
source /tmp/xnode-env
56+
source /xnode-config/env
5057
'';
5158

5259
systemd.services.apply-network-config = {
@@ -66,8 +73,7 @@
6673
];
6774
script = ''
6875
# Extract environmental variables
69-
sed '2q;d' /proc/cmdline > /tmp/xnode-env
70-
source /tmp/xnode-env
76+
source /xnode-config/env
7177
7278
if [[ $NETWORK_CONFIG ]]; then
7379
interfaces=$(echo "$NETWORK_CONFIG" | jq -c '.address.[]')

0 commit comments

Comments
 (0)