2022-11-30 19:55:57 +03:00
|
|
|
{ system ? builtins.currentSystem,
|
|
|
|
config ? {},
|
|
|
|
pkgs ? import ../.. { inherit system config; }
|
|
|
|
}:
|
|
|
|
|
|
|
|
with import ../lib/testing-python.nix { inherit system pkgs; };
|
|
|
|
with pkgs.lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
baseline = {
|
|
|
|
virtualisation.useBootLoader = true;
|
|
|
|
};
|
|
|
|
grub = {
|
|
|
|
boot.loader.grub.enable = true;
|
|
|
|
};
|
|
|
|
systemd-boot = {
|
|
|
|
boot.loader.systemd-boot.enable = true;
|
|
|
|
};
|
|
|
|
uefi = {
|
|
|
|
virtualisation.useEFIBoot = true;
|
|
|
|
boot.loader.efi.canTouchEfiVariables = true;
|
2022-12-17 04:13:45 +03:00
|
|
|
boot.loader.grub.efiSupport = true;
|
2022-11-30 19:55:57 +03:00
|
|
|
environment.systemPackages = [ pkgs.efibootmgr ];
|
|
|
|
};
|
|
|
|
standard = {
|
|
|
|
boot.bootspec.enable = true;
|
|
|
|
|
|
|
|
imports = [
|
|
|
|
baseline
|
|
|
|
systemd-boot
|
|
|
|
uefi
|
|
|
|
];
|
|
|
|
};
|
|
|
|
in
|
|
|
|
{
|
|
|
|
basic = makeTest {
|
|
|
|
name = "systemd-boot-with-bootspec";
|
|
|
|
meta.maintainers = with pkgs.lib.maintainers; [ raitobezarius ];
|
|
|
|
|
|
|
|
nodes.machine = standard;
|
|
|
|
|
|
|
|
testScript = ''
|
|
|
|
machine.start()
|
|
|
|
machine.wait_for_unit("multi-user.target")
|
|
|
|
|
2022-12-22 01:03:40 +03:00
|
|
|
machine.succeed("test -e /run/current-system/boot.json")
|
2022-11-30 19:55:57 +03:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
grub = makeTest {
|
|
|
|
name = "grub-with-bootspec";
|
|
|
|
meta.maintainers = with pkgs.lib.maintainers; [ raitobezarius ];
|
|
|
|
|
|
|
|
nodes.machine = {
|
|
|
|
boot.bootspec.enable = true;
|
|
|
|
|
|
|
|
imports = [
|
|
|
|
baseline
|
|
|
|
grub
|
|
|
|
uefi
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
testScript = ''
|
|
|
|
machine.start()
|
|
|
|
machine.wait_for_unit("multi-user.target")
|
|
|
|
|
2022-12-22 01:03:40 +03:00
|
|
|
machine.succeed("test -e /run/current-system/boot.json")
|
2022-11-30 19:55:57 +03:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
legacy-boot = makeTest {
|
|
|
|
name = "legacy-boot-with-bootspec";
|
|
|
|
meta.maintainers = with pkgs.lib.maintainers; [ raitobezarius ];
|
|
|
|
|
|
|
|
nodes.machine = {
|
|
|
|
boot.bootspec.enable = true;
|
|
|
|
|
|
|
|
imports = [
|
|
|
|
baseline
|
|
|
|
grub
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
testScript = ''
|
|
|
|
machine.start()
|
|
|
|
machine.wait_for_unit("multi-user.target")
|
|
|
|
|
2022-12-22 01:03:40 +03:00
|
|
|
machine.succeed("test -e /run/current-system/boot.json")
|
2022-11-30 19:55:57 +03:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2022-12-22 01:28:21 +03:00
|
|
|
# Check that initrd create corresponding entries in bootspec.
|
|
|
|
initrd = makeTest {
|
|
|
|
name = "bootspec-with-initrd";
|
|
|
|
meta.maintainers = with pkgs.lib.maintainers; [ raitobezarius ];
|
|
|
|
|
|
|
|
nodes.machine = {
|
|
|
|
imports = [ standard ];
|
|
|
|
environment.systemPackages = [ pkgs.jq ];
|
|
|
|
# It's probably the case, but we want to make it explicit here.
|
|
|
|
boot.initrd.enable = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
testScript = ''
|
|
|
|
import json
|
|
|
|
|
|
|
|
machine.start()
|
|
|
|
machine.wait_for_unit("multi-user.target")
|
|
|
|
|
2023-03-26 02:44:41 +03:00
|
|
|
machine.succeed("test -e /run/current-system/boot.json")
|
2022-12-22 01:28:21 +03:00
|
|
|
|
2023-03-18 22:42:09 +03:00
|
|
|
bootspec = json.loads(machine.succeed("jq -r '.\"org.nixos.bootspec.v1\"' /run/current-system/boot.json"))
|
2022-12-22 01:28:21 +03:00
|
|
|
|
|
|
|
assert all(key in bootspec for key in ('initrd', 'initrdSecrets')), "Bootspec should contain initrd or initrdSecrets field when initrd is enabled"
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2022-11-30 19:55:57 +03:00
|
|
|
# Check that specialisations create corresponding entries in bootspec.
|
|
|
|
specialisation = makeTest {
|
|
|
|
name = "bootspec-with-specialisation";
|
|
|
|
meta.maintainers = with pkgs.lib.maintainers; [ raitobezarius ];
|
|
|
|
|
|
|
|
nodes.machine = {
|
|
|
|
imports = [ standard ];
|
|
|
|
environment.systemPackages = [ pkgs.jq ];
|
|
|
|
specialisation.something.configuration = {};
|
|
|
|
};
|
|
|
|
|
|
|
|
testScript = ''
|
|
|
|
import json
|
|
|
|
|
|
|
|
machine.start()
|
|
|
|
machine.wait_for_unit("multi-user.target")
|
|
|
|
|
2022-12-22 01:03:40 +03:00
|
|
|
machine.succeed("test -e /run/current-system/boot.json")
|
|
|
|
machine.succeed("test -e /run/current-system/specialisation/something/boot.json")
|
2022-11-30 19:55:57 +03:00
|
|
|
|
2023-03-18 22:42:09 +03:00
|
|
|
sp_in_parent = json.loads(machine.succeed("jq -r '.\"org.nixos.specialisation.v1\".something' /run/current-system/boot.json"))
|
2022-12-22 01:03:40 +03:00
|
|
|
sp_in_fs = json.loads(machine.succeed("cat /run/current-system/specialisation/something/boot.json"))
|
2022-11-30 19:55:57 +03:00
|
|
|
|
2023-03-18 22:42:09 +03:00
|
|
|
assert sp_in_parent['org.nixos.bootspec.v1'] == sp_in_fs['org.nixos.bootspec.v1'], "Bootspecs of the same specialisation are different!"
|
2022-11-30 19:55:57 +03:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
# Check that extensions are propagated.
|
|
|
|
extensions = makeTest {
|
|
|
|
name = "bootspec-with-extensions";
|
|
|
|
meta.maintainers = with pkgs.lib.maintainers; [ raitobezarius ];
|
|
|
|
|
|
|
|
nodes.machine = { config, ... }: {
|
|
|
|
imports = [ standard ];
|
|
|
|
environment.systemPackages = [ pkgs.jq ];
|
|
|
|
boot.bootspec.extensions = {
|
2023-03-18 22:42:09 +03:00
|
|
|
"org.nix-tests.product" = {
|
|
|
|
osRelease = config.environment.etc."os-release".source;
|
|
|
|
};
|
2022-11-30 19:55:57 +03:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
testScript = ''
|
|
|
|
machine.start()
|
|
|
|
machine.wait_for_unit("multi-user.target")
|
|
|
|
|
|
|
|
current_os_release = machine.succeed("cat /etc/os-release")
|
2023-03-18 22:42:09 +03:00
|
|
|
bootspec_os_release = machine.succeed("cat $(jq -r '.\"org.nix-tests.product\".osRelease' /run/current-system/boot.json)")
|
2022-11-30 19:55:57 +03:00
|
|
|
|
|
|
|
assert current_os_release == bootspec_os_release, "Filename referenced by extension has unexpected contents"
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|