Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update default nixos kexec image to 24.05 #328

Merged
merged 3 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

# used for testing
disko = { url = "github:nix-community/disko/master"; inputs.nixpkgs.follows = "nixpkgs"; };
nixos-stable.url = "github:NixOS/nixpkgs/nixos-23.11";
nixos-stable.url = "github:NixOS/nixpkgs/nixos-24.05";
nixos-images.url = "github:nix-community/nixos-images";
nixos-images.inputs.nixos-unstable.follows = "nixpkgs";
nixos-images.inputs.nixos-2311.follows = "nixos-stable";
nixos-images.inputs.nixos-stable.follows = "nixos-stable";

# used for development
treefmt-nix = { url = "github:numtide/treefmt-nix"; inputs.nixpkgs.follows = "nixpkgs"; };
Expand Down
2 changes: 1 addition & 1 deletion src/nixos-anywhere.sh
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ if [[ ${is_kexec-n} == "n" ]] && [[ ${is_installer-n} == "n" ]]; then
if [[ $kexec_url == "" ]]; then
case "${is_arch-unknown}" in
x86_64 | aarch64)
kexec_url="https://github.com/nix-community/nixos-images/releases/download/nixos-23.11/nixos-kexec-installer-noninteractive-${is_arch}-linux.tar.gz"
kexec_url="https://github.com/nix-community/nixos-images/releases/download/nixos-24.05/nixos-kexec-installer-noninteractive-${is_arch}-linux.tar.gz"
;;
*)
abort "Unsupported architecture: ${is_arch}. Our default kexec images only support x86_64 and aarch64 cpus. Checkout https://github.com/nix-community/nixos-anywhere/#using-your-own-kexec-image for more information."
Expand Down
2 changes: 1 addition & 1 deletion tests/flake-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
kexec-installer = "${inputs'.nixos-images.packages.kexec-installer-nixos-unstable-noninteractive}/nixos-kexec-installer-noninteractive-${system}.tar.gz";
};
testInputsStable = testInputsUnstable // {
kexec-installer = "${inputs'.nixos-images.packages.kexec-installer-nixos-2311-noninteractive}/nixos-kexec-installer-noninteractive-${system}.tar.gz";
kexec-installer = "${inputs'.nixos-images.packages.kexec-installer-nixos-stable-noninteractive}/nixos-kexec-installer-noninteractive-${system}.tar.gz";
};
in
{
Expand Down
93 changes: 53 additions & 40 deletions tests/from-nixos-build-on-remote.nix
Original file line number Diff line number Diff line change
@@ -1,43 +1,56 @@
(import ./lib/test-base.nix) {
name = "from-nixos-build-on-remote";
nodes = {
installer = ./modules/installer.nix;
installed = {
services.openssh.enable = true;
virtualisation.memorySize = 1512;
(import ./lib/test-base.nix) (
{ pkgs, ... }:
{
name = "from-nixos-build-on-remote";
nodes = {
installer = ./modules/installer.nix;
installed = {
services.openssh.enable = true;
virtualisation.memorySize = 1512;

users.users.root.openssh.authorizedKeys.keyFiles = [ ./modules/ssh-keys/ssh.pub ];
users.users.root.openssh.authorizedKeys.keyFiles = [ ./modules/ssh-keys/ssh.pub ];
};
};
};
testScript = ''
def create_test_machine(oldmachine=None, args={}): # taken from <nixpkgs/nixos/tests/installer.nix>
machine = create_machine({
"qemuFlags":
'-cpu max -m 1024 -virtfs local,path=/nix/store,security_model=none,mount_tag=nix-store,'
f' -drive file={oldmachine.state_dir}/installed.qcow2,id=drive1,if=none,index=1,werror=report'
f' -device virtio-blk-pci,drive=drive1',
} | args)
driver.machines.append(machine)
return machine
start_all()
testScript = ''
def create_test_machine(
oldmachine=None, **kwargs
): # taken from <nixpkgs/nixos/tests/installer.nix>
start_command = [
"${pkgs.qemu_test}/bin/qemu-kvm",
"-cpu",
"max",
"-m",
"1024",
"-virtfs",
"local,path=/nix/store,security_model=none,mount_tag=nix-store",
"-drive",
f"file={oldmachine.state_dir}/installed.qcow2,id=drive1,if=none,index=1,werror=report",
"-device",
"virtio-blk-pci,drive=drive1",
]
machine = create_machine(start_command=" ".join(start_command), **kwargs)
driver.machines.append(machine)
return machine
start_all()

installer.succeed("""
nixos-anywhere \
-i /root/.ssh/install_key \
--debug \
--build-on-remote \
--kexec /etc/nixos-anywhere/kexec-installer \
--store-paths /etc/nixos-anywhere/disko /etc/nixos-anywhere/system-to-install \
root@installed >&2
""")
try:
installed.shutdown()
except BrokenPipeError:
# qemu has already exited
pass
new_machine = create_test_machine(oldmachine=installed, args={ "name": "after_install" })
new_machine.start()
hostname = new_machine.succeed("hostname").strip()
assert "nixos-anywhere" == hostname, f"'nixos-anywhere' != '{hostname}'"
'';
}
installer.succeed("""
nixos-anywhere \
-i /root/.ssh/install_key \
--debug \
--build-on-remote \
--kexec /etc/nixos-anywhere/kexec-installer \
--store-paths /etc/nixos-anywhere/disko /etc/nixos-anywhere/system-to-install \
root@installed >&2
""")
try:
installed.shutdown()
except BrokenPipeError:
# qemu has already exited
pass
new_machine = create_test_machine(oldmachine=installed, name="after_install")
new_machine.start()
hostname = new_machine.succeed("hostname").strip()
assert "nixos-anywhere" == hostname, f"'nixos-anywhere' != '{hostname}'"
'';
}
)
117 changes: 65 additions & 52 deletions tests/from-nixos.nix
Original file line number Diff line number Diff line change
@@ -1,54 +1,67 @@
(import ./lib/test-base.nix) {
name = "from-nixos";
nodes = {
installer = ./modules/installer.nix;
installed = {
services.openssh.enable = true;
virtualisation.memorySize = 1512;
(import ./lib/test-base.nix) (
{ pkgs, ... }:
{
name = "from-nixos";
nodes = {
installer = ./modules/installer.nix;
installed = {
services.openssh.enable = true;
virtualisation.memorySize = 1512;

users.users.root.openssh.authorizedKeys.keyFiles = [ ./modules/ssh-keys/ssh.pub ];
users.users.root.openssh.authorizedKeys.keyFiles = [ ./modules/ssh-keys/ssh.pub ];
};
};
};
testScript = ''
def create_test_machine(oldmachine=None, args={}): # taken from <nixpkgs/nixos/tests/installer.nix>
machine = create_machine({
"qemuFlags":
'-cpu max -m 1024 -virtfs local,path=/nix/store,security_model=none,mount_tag=nix-store,'
f' -drive file={oldmachine.state_dir}/installed.qcow2,id=drive1,if=none,index=1,werror=report'
f' -device virtio-blk-pci,drive=drive1',
} | args)
driver.machines.append(machine)
return machine
start_all()
installer.succeed("mkdir -p /tmp/extra-files/var/lib/secrets")
installer.succeed("echo value > /tmp/extra-files/var/lib/secrets/key")
ssh_key_path = "/etc/ssh/ssh_host_ed25519_key.pub"
ssh_key_output = installer.wait_until_succeeds(f"""
ssh -i /root/.ssh/install_key -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no \
root@installed cat {ssh_key_path}
""")
installer.succeed("""
nixos-anywhere \
-i /root/.ssh/install_key \
--debug \
--kexec /etc/nixos-anywhere/kexec-installer \
--extra-files /tmp/extra-files \
--store-paths /etc/nixos-anywhere/disko /etc/nixos-anywhere/system-to-install \
--copy-host-keys \
root@installed >&2
""")
try:
installed.shutdown()
except BrokenPipeError:
# qemu has already exited
pass
new_machine = create_test_machine(oldmachine=installed, args={ "name": "after_install" })
new_machine.start()
hostname = new_machine.succeed("hostname").strip()
assert "nixos-anywhere" == hostname, f"'nixos-anywhere' != '{hostname}'"
content = new_machine.succeed("cat /var/lib/secrets/key").strip()
assert "value" == content, f"secret does not have expected value: {content}"
ssh_key_content = new_machine.succeed(f"cat {ssh_key_path}").strip()
assert ssh_key_content in ssh_key_output, "SSH host identity changed"
'';
}
testScript = ''
def create_test_machine(
oldmachine=None, **kwargs
): # taken from <nixpkgs/nixos/tests/installer.nix>
start_command = [
"${pkgs.qemu_test}/bin/qemu-kvm",
"-cpu",
"max",
"-m",
"1024",
"-virtfs",
"local,path=/nix/store,security_model=none,mount_tag=nix-store",
"-drive",
f"file={oldmachine.state_dir}/installed.qcow2,id=drive1,if=none,index=1,werror=report",
"-device",
"virtio-blk-pci,drive=drive1",
]
machine = create_machine(start_command=" ".join(start_command), **kwargs)
driver.machines.append(machine)
return machine
start_all()
installer.succeed("mkdir -p /tmp/extra-files/var/lib/secrets")
installer.succeed("echo value > /tmp/extra-files/var/lib/secrets/key")
ssh_key_path = "/etc/ssh/ssh_host_ed25519_key.pub"
ssh_key_output = installer.wait_until_succeeds(f"""
ssh -i /root/.ssh/install_key -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no \
root@installed cat {ssh_key_path}
""")
installer.succeed("""
nixos-anywhere \
-i /root/.ssh/install_key \
--debug \
--kexec /etc/nixos-anywhere/kexec-installer \
--extra-files /tmp/extra-files \
--store-paths /etc/nixos-anywhere/disko /etc/nixos-anywhere/system-to-install \
--copy-host-keys \
root@installed >&2
""")
try:
installed.shutdown()
except BrokenPipeError:
# qemu has already exited
pass
new_machine = create_test_machine(oldmachine=installed, name="after_install")
new_machine.start()
hostname = new_machine.succeed("hostname").strip()
assert "nixos-anywhere" == hostname, f"'nixos-anywhere' != '{hostname}'"
content = new_machine.succeed("cat /var/lib/secrets/key").strip()
assert "value" == content, f"secret does not have expected value: {content}"
ssh_key_content = new_machine.succeed(f"cat {ssh_key_path}").strip()
assert ssh_key_content in ssh_key_output, "SSH host identity changed"
'';
}
)
Loading
Loading