tangled
alpha
login
or
join now
pyrox.dev
/
nixpkgs
0
fork
atom
lol
0
fork
atom
overview
issues
pulls
pipelines
nixos/tests/appliance-repart-image: init
nikstur
2 years ago
87ecda9a
ec8d30cc
+117
2 changed files
expand all
collapse all
unified
split
nixos
tests
all-tests.nix
appliance-repart-image.nix
+1
nixos/tests/all-tests.nix
···
112
112
anuko-time-tracker = handleTest ./anuko-time-tracker.nix {};
113
113
apcupsd = handleTest ./apcupsd.nix {};
114
114
apfs = runTest ./apfs.nix;
115
115
+
appliance-repart-image = runTest ./appliance-repart-image.nix;
115
116
apparmor = handleTest ./apparmor.nix {};
116
117
atd = handleTest ./atd.nix {};
117
118
atop = handleTest ./atop.nix {};
+116
nixos/tests/appliance-repart-image.nix
···
1
1
+
# Tests building and running a GUID Partition Table (GPT) appliance image.
2
2
+
# "Appliance" here means that the image does not contain the normal NixOS
3
3
+
# infrastructure of a system profile and cannot be re-built via
4
4
+
# `nixos-rebuild`.
5
5
+
6
6
+
{ lib, ... }:
7
7
+
8
8
+
let
9
9
+
rootPartitionLabel = "root";
10
10
+
11
11
+
bootLoaderConfigPath = "/loader/entries/nixos.conf";
12
12
+
kernelPath = "/EFI/nixos/kernel.efi";
13
13
+
initrdPath = "/EFI/nixos/initrd.efi";
14
14
+
in
15
15
+
{
16
16
+
name = "appliance-gpt-image";
17
17
+
18
18
+
meta.maintainers = with lib.maintainers; [ nikstur ];
19
19
+
20
20
+
nodes.machine = { config, lib, pkgs, ... }: {
21
21
+
22
22
+
imports = [ ../modules/image/repart.nix ];
23
23
+
24
24
+
virtualisation.directBoot.enable = false;
25
25
+
virtualisation.mountHostNixStore = false;
26
26
+
virtualisation.useEFIBoot = true;
27
27
+
28
28
+
# Disable boot loaders because we install one "manually".
29
29
+
# TODO(raitobezarius): revisit this when #244907 lands
30
30
+
boot.loader.grub.enable = false;
31
31
+
32
32
+
virtualisation.fileSystems = lib.mkForce {
33
33
+
"/" = {
34
34
+
device = "/dev/disk/by-partlabel/${rootPartitionLabel}";
35
35
+
fsType = "ext4";
36
36
+
};
37
37
+
};
38
38
+
39
39
+
image.repart = {
40
40
+
name = "appliance-gpt-image";
41
41
+
partitions = {
42
42
+
"esp" = {
43
43
+
contents =
44
44
+
let
45
45
+
efiArch = config.nixpkgs.hostPlatform.efiArch;
46
46
+
in
47
47
+
{
48
48
+
"/EFI/BOOT/BOOT${lib.toUpper efiArch}.EFI".source =
49
49
+
"${pkgs.systemd}/lib/systemd/boot/efi/systemd-boot${efiArch}.efi";
50
50
+
51
51
+
# TODO: create an abstraction for Boot Loader Specification (BLS) entries.
52
52
+
"${bootLoaderConfigPath}".source = pkgs.writeText "nixos.conf" ''
53
53
+
title NixOS
54
54
+
linux ${kernelPath}
55
55
+
initrd ${initrdPath}
56
56
+
options init=${config.system.build.toplevel}/init ${toString config.boot.kernelParams}
57
57
+
'';
58
58
+
59
59
+
"${kernelPath}".source =
60
60
+
"${config.boot.kernelPackages.kernel}/${config.system.boot.loader.kernelFile}";
61
61
+
62
62
+
"${initrdPath}".source =
63
63
+
"${config.system.build.initialRamdisk}/${config.system.boot.loader.initrdFile}";
64
64
+
};
65
65
+
repartConfig = {
66
66
+
Type = "esp";
67
67
+
Format = "vfat";
68
68
+
# Minimize = "guess" seems to not work very vell for vfat
69
69
+
# partitons. It's better to set a sensible default instead. The
70
70
+
# aarch64 kernel seems to generally be a little bigger than the
71
71
+
# x86_64 kernel. To stay on the safe side, leave some more slack
72
72
+
# for every platform other than x86_64.
73
73
+
SizeMinBytes = if config.nixpkgs.hostPlatform.isx86_64 then "64M" else "96M";
74
74
+
};
75
75
+
};
76
76
+
"root" = {
77
77
+
storePaths = [ config.system.build.toplevel ];
78
78
+
repartConfig = {
79
79
+
Type = "root";
80
80
+
Format = config.fileSystems."/".fsType;
81
81
+
Label = rootPartitionLabel;
82
82
+
Minimize = "guess";
83
83
+
};
84
84
+
};
85
85
+
};
86
86
+
};
87
87
+
};
88
88
+
89
89
+
testScript = { nodes, ... }: ''
90
90
+
import os
91
91
+
import subprocess
92
92
+
import tempfile
93
93
+
94
94
+
tmp_disk_image = tempfile.NamedTemporaryFile()
95
95
+
96
96
+
subprocess.run([
97
97
+
"${nodes.machine.virtualisation.qemu.package}/bin/qemu-img",
98
98
+
"create",
99
99
+
"-f",
100
100
+
"qcow2",
101
101
+
"-b",
102
102
+
"${nodes.machine.system.build.image}/image.raw",
103
103
+
"-F",
104
104
+
"raw",
105
105
+
tmp_disk_image.name,
106
106
+
])
107
107
+
108
108
+
# Set NIX_DISK_IMAGE so that the qemu script finds the right disk image.
109
109
+
os.environ['NIX_DISK_IMAGE'] = tmp_disk_image.name
110
110
+
111
111
+
bootctl_status = machine.succeed("bootctl status")
112
112
+
assert "${bootLoaderConfigPath}" in bootctl_status
113
113
+
assert "${kernelPath}" in bootctl_status
114
114
+
assert "${initrdPath}" in bootctl_status
115
115
+
'';
116
116
+
}