Skip to content

Commit

Permalink
Merge pull request #144 from nix-community/machine-id
Browse files Browse the repository at this point in the history
also copy machine-id into installer
  • Loading branch information
mergify[bot] authored Nov 22, 2023
2 parents 6531732 + bebc30e commit fc53130
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions nix/installer.nix
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,8 @@
fi
install -m 400 ssh/ssh_host_* /mnt-root/etc/ssh
cp *.json /mnt-root/root/network/
if [[ -f machine-id ]]; then
cp machine-id /mnt-root/etc/machine-id
fi
'';
}
2 changes: 2 additions & 0 deletions nix/kexec-installer/kexec-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ done
"$SCRIPT_DIR/ip" -4 --json route > routes-v4.json
"$SCRIPT_DIR/ip" -6 --json route > routes-v6.json

[ -f /etc/machine-id ] && cp /etc/machine-id machine-id

find . | cpio -o -H newc | gzip -9 >> "$SCRIPT_DIR/initrd"

if ! "$SCRIPT_DIR/kexec" --load "$SCRIPT_DIR/bzImage" \
Expand Down
6 changes: 5 additions & 1 deletion nix/kexec-installer/test.nix
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ makeTest' {
node1.succeed("ip -6 route >&2")
node1.succeed("networkctl status eth0 >&2")
def ssh(cmd: list[str], check: bool = True, stdout: Optional[int] = None) -> subprocess.CompletedProcess:
def ssh(cmd: list[str], check: bool = True, stdout: Optional[int] = None) -> subprocess.CompletedProcess[str]:
ssh_cmd = [
"${pkgs.openssh}/bin/ssh",
"-o", "StrictHostKeyChecking=no",
Expand All @@ -128,6 +128,7 @@ makeTest' {
# Kexec node1 to the toplevel of node2 via the kexec-boot script
node1.succeed('touch /run/foo')
old_machine_id = node1.succeed("cat /etc/machine-id").strip()
node1.fail('parted --version >&2')
node1.succeed('tar -xf ${kexecTarball}/nixos-kexec-installer-noninteractive-${pkgs.system}.tar.gz -C /root')
node1.succeed('/root/kexec/ip -V >&2')
Expand All @@ -153,6 +154,9 @@ makeTest' {
print(ssh(["ip", "-6", "route"]))
print(ssh(["networkctl", "status"]))
new_machine_id = ssh(["cat", "/etc/machine-id"], stdout=subprocess.PIPE).stdout.strip()
assert old_machine_id == new_machine_id, f"{old_machine_id} != {new_machine_id}, machine-id changed"
assert ssh(["ls", "-la", "/run/foo"], check=False).returncode != 0, "kexeced node1 still has /run/foo"
print(ssh(["parted", "--version"]))
host = ssh(["hostname"], stdout=subprocess.PIPE).stdout.strip()
Expand Down

0 comments on commit fc53130

Please sign in to comment.