Skip to content

Commit c0a9cc6

Browse files
Merge staging-next into staging
2 parents 782c936 + e08c3a8 commit c0a9cc6

64 files changed

Lines changed: 855 additions & 862 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

nixos/maintainers/scripts/ec2/amazon-image.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ in
6666
"qcow2"
6767
"vpc"
6868
];
69-
default = "vpc";
69+
default = "raw";
7070
description = "The image format to output";
7171
};
7272
};

nixos/modules/image/repart-verity-store.nix

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,20 @@ in
8989
};
9090
};
9191

92+
fileSystems."/nix/store" = lib.mkDefault {
93+
device = "/usr/nix/store";
94+
fsType = "none";
95+
options = [ "bind" ];
96+
};
97+
9298
image.repart.partitions = {
9399
# dm-verity hash partition
94100
${cfg.partitionIds.store-verity}.repartConfig = {
95101
Type = lib.mkDefault partitionTypes.usr-verity;
96102
Verity = "hash";
97103
VerityMatchKey = lib.mkDefault verityMatchKey;
98104
Label = lib.mkDefault "store-verity";
105+
Minimize = lib.mkDefault "best";
99106
};
100107
# dm-verity data partition that contains the nix store
101108
${cfg.partitionIds.store} = {
@@ -106,23 +113,29 @@ in
106113
Format = lib.mkDefault "erofs";
107114
VerityMatchKey = lib.mkDefault verityMatchKey;
108115
Label = lib.mkDefault "store";
116+
Minimize = lib.mkDefault "best";
109117
};
110118
};
111119

112120
};
113121

114122
system.build = {
123+
finalImage = lib.warn "system.build.finalImage has been renamed to system.build.image" config.system.build.image;
115124

116125
# intermediate system image without ESP
117126
intermediateImage =
118-
(config.system.build.image.override {
127+
(config.image.repart.image.override {
119128
# always disable compression for the intermediate image
120129
compression.enable = false;
121130
}).overrideAttrs
122131
(
123132
_: previousAttrs: {
124133
# make it easier to identify the intermediate image in build logs
125-
pname = "${previousAttrs.pname}-intermediate";
134+
name =
135+
if previousAttrs ? pname then
136+
"${previousAttrs.pname}-${previousAttrs.version}-intermediate"
137+
else
138+
"${previousAttrs.name}-intermediate";
126139

127140
# do not prepare the ESP, this is done in the final image
128141
systemdRepartFlags = previousAttrs.systemdRepartFlags ++ [ "--defer-partitions=esp" ];
@@ -162,8 +175,8 @@ in
162175
);
163176

164177
# final system image that is created from the intermediate image by injecting the UKI from above
165-
finalImage =
166-
(config.system.build.image.override {
178+
image = lib.mkOverride 99 (
179+
(config.image.repart.image.override {
167180
# continue building with existing intermediate image
168181
createEmpty = false;
169182
}).overrideAttrs
@@ -216,7 +229,8 @@ in
216229
rm -v repart-output_orig.json
217230
'';
218231
}
219-
);
232+
)
233+
);
220234
};
221235
};
222236

nixos/modules/image/repart.nix

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,15 @@ in
282282
'';
283283
};
284284

285+
image = lib.mkOption {
286+
type = lib.types.package;
287+
internal = true;
288+
readOnly = true;
289+
description = ''
290+
The image built by this module. Used as the default for `system.build.image`.
291+
'';
292+
};
293+
285294
assertions = lib.mkOption {
286295
type = options.assertions.type;
287296
default = [ ];
@@ -356,6 +365,37 @@ in
356365

357366
finalPartitions = lib.mapAttrs addClosure cfg.partitions;
358367

368+
image =
369+
let
370+
fileSystems = lib.filter (f: f != null) (
371+
lib.mapAttrsToList (_n: v: v.repartConfig.Format or null) cfg.partitions
372+
);
373+
374+
format = pkgs.formats.ini { listsAsDuplicateKeys = true; };
375+
376+
definitionsDirectory = utils.systemdUtils.lib.definitions "repart.d" format (
377+
lib.mapAttrs (_n: v: { Partition = v.repartConfig; }) cfg.finalPartitions
378+
);
379+
380+
mkfsEnv = mkfsOptionsToEnv cfg.mkfsOptions;
381+
val = pkgs.callPackage ./repart-image.nix {
382+
systemd = cfg.package;
383+
inherit (config.image) baseName;
384+
inherit (cfg)
385+
name
386+
version
387+
compression
388+
split
389+
seed
390+
imageSize
391+
sectorSize
392+
finalPartitions
393+
;
394+
inherit fileSystems definitionsDirectory mkfsEnv;
395+
};
396+
in
397+
lib.asserts.checkAssertWarn cfg.assertions cfg.warnings val;
398+
359399
assertions = lib.mapAttrsToList (
360400
fileName: partitionConfig:
361401
let
@@ -401,36 +441,7 @@ in
401441
);
402442
};
403443

404-
system.build.image =
405-
let
406-
fileSystems = lib.filter (f: f != null) (
407-
lib.mapAttrsToList (_n: v: v.repartConfig.Format or null) cfg.partitions
408-
);
409-
410-
format = pkgs.formats.ini { listsAsDuplicateKeys = true; };
411-
412-
definitionsDirectory = utils.systemdUtils.lib.definitions "repart.d" format (
413-
lib.mapAttrs (_n: v: { Partition = v.repartConfig; }) cfg.finalPartitions
414-
);
415-
416-
mkfsEnv = mkfsOptionsToEnv cfg.mkfsOptions;
417-
val = pkgs.callPackage ./repart-image.nix {
418-
systemd = cfg.package;
419-
inherit (config.image) baseName;
420-
inherit (cfg)
421-
name
422-
version
423-
compression
424-
split
425-
seed
426-
imageSize
427-
sectorSize
428-
finalPartitions
429-
;
430-
inherit fileSystems definitionsDirectory mkfsEnv;
431-
};
432-
in
433-
lib.asserts.checkAssertWarn cfg.assertions cfg.warnings val;
444+
system.build.image = cfg.image;
434445
};
435446

436447
meta.maintainers = with lib.maintainers; [

nixos/modules/services/databases/mysql.nix

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ let
99
cfg = config.services.mysql;
1010

1111
isMariaDB = lib.getName cfg.package == lib.getName pkgs.mariadb;
12-
isOracle = lib.getName cfg.package == lib.getName pkgs.mysql84;
13-
# Oracle MySQL has supported "notify" service type since 8.0
14-
hasNotify = isMariaDB || (isOracle && lib.versionAtLeast cfg.package.version "8.0");
1512

1613
mysqldOptions = "--user=${cfg.user} --datadir=${cfg.dataDir} --basedir=${cfg.package}";
1714

@@ -576,15 +573,6 @@ in
576573
superUser = if isMariaDB then cfg.user else "root";
577574
in
578575
''
579-
${lib.optionalString (!hasNotify) ''
580-
# Wait until the MySQL server is available for use
581-
while [ ! -e /run/mysqld/mysqld.sock ]
582-
do
583-
echo "MySQL daemon not yet started. Waiting for 1 second..."
584-
sleep 1
585-
done
586-
''}
587-
588576
${lib.optionalString isMariaDB ''
589577
# If MariaDB is used in an Galera cluster, we have to check if the sync is done,
590578
# or it will fail to init the database while joining, so we get in an broken non recoverable state
@@ -689,7 +677,7 @@ in
689677

690678
serviceConfig = lib.mkMerge [
691679
{
692-
Type = if hasNotify then "notify" else "simple";
680+
Type = "notify";
693681
Restart = "on-abnormal";
694682
RestartSec = "5s";
695683

nixos/modules/system/boot/luksroot.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ let
214214
215215
# and try reading it from /dev/console with a timeout
216216
IFS= read -t 1 -r passphrase
217-
if [ -n "$passphrase" ]; then
217+
if [ $? = 0 ]; then
218218
${
219219
if luks.reusePassphrases then
220220
''
@@ -232,7 +232,7 @@ let
232232
fi
233233
done
234234
echo -n "Verifying passphrase for ${dev.device}..."
235-
echo -n "$passphrase" | ${csopen} --key-file=-
235+
echo "$passphrase" | ${csopen}
236236
if [ $? == 0 ]; then
237237
echo " - success"
238238
${

nixos/tests/appliance-repart-image-verity-store.nix

Lines changed: 54 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,20 @@
1010
willibutz
1111
];
1212

13-
nodes.machine =
14-
{
15-
config,
16-
lib,
17-
pkgs,
18-
...
19-
}:
13+
defaults =
14+
{ config, lib, ... }:
2015
let
2116
inherit (config.image.repart.verityStore) partitionIds;
2217
in
2318
{
2419
imports = [ ../modules/image/repart.nix ];
2520

26-
virtualisation.fileSystems = lib.mkVMOverride {
21+
virtualisation.fileSystems = lib.mkVMOverride { };
22+
fileSystems = {
2723
"/" = {
2824
fsType = "tmpfs";
2925
options = [ "mode=0755" ];
3026
};
31-
32-
# bind-mount the store
33-
"/nix/store" = {
34-
device = "/usr/nix/store";
35-
fsType = "none";
36-
options = [ "bind" ];
37-
};
3827
};
3928

4029
image.repart = {
@@ -55,12 +44,6 @@
5544
SizeMinBytes = if config.nixpkgs.hostPlatform.isx86_64 then "64M" else "96M";
5645
};
5746
};
58-
${partitionIds.store-verity}.repartConfig = {
59-
Minimize = "best";
60-
};
61-
${partitionIds.store}.repartConfig = {
62-
Minimize = "best";
63-
};
6447
};
6548
};
6649

@@ -75,50 +58,71 @@
7558
initrd.systemd.enable = true;
7659
};
7760

78-
system.image = {
79-
id = "nixos-appliance";
80-
version = "1";
81-
};
61+
system.image.id = "nixos-appliance";
8262

8363
# don't create /usr/bin/env
8464
# this would require some extra work on read-only /usr
8565
# and it is not a strict necessity
8666
system.activationScripts.usrbinenv = lib.mkForce "";
8767
};
8868

69+
nodes.machine = {
70+
system.image.version = "1";
71+
};
72+
73+
nodes.without-version = { };
74+
8975
testScript =
9076
{ nodes, ... }: # python
9177
''
9278
import os
9379
import subprocess
9480
import tempfile
9581
96-
tmp_disk_image = tempfile.NamedTemporaryFile()
97-
98-
subprocess.run([
82+
def create_disk_image(qemu_img, backing_file):
83+
tmp = tempfile.NamedTemporaryFile()
84+
subprocess.run([
85+
qemu_img,
86+
"create",
87+
"-f",
88+
"qcow2",
89+
"-b",
90+
backing_file,
91+
"-F",
92+
"raw",
93+
tmp.name,
94+
], check=True)
95+
return tmp
96+
97+
def run_verity_tests(machine):
98+
with subtest("Running with volatile root"):
99+
machine.succeed("findmnt --kernel --type tmpfs /")
100+
101+
with subtest("/nix/store is backed by dm-verity protected fs"):
102+
verity_info = machine.succeed("dmsetup info --target verity usr")
103+
assert "ACTIVE" in verity_info, f"unexpected verity info: {verity_info}"
104+
105+
backing_device = machine.succeed("df --output=source /nix/store | tail -n1").strip()
106+
assert "/dev/mapper/usr" == backing_device, f"unexpected backing device: {backing_device}"
107+
108+
tmp_disk_machine = create_disk_image(
99109
"${nodes.machine.virtualisation.qemu.package}/bin/qemu-img",
100-
"create",
101-
"-f",
102-
"qcow2",
103-
"-b",
104-
"${nodes.machine.system.build.finalImage}/${nodes.machine.image.repart.imageFile}",
105-
"-F",
106-
"raw",
107-
tmp_disk_image.name,
108-
])
109-
110-
os.environ['NIX_DISK_IMAGE'] = tmp_disk_image.name
111-
110+
"${nodes.machine.system.build.image}/${nodes.machine.image.filePath}",
111+
)
112+
os.environ['NIX_DISK_IMAGE'] = tmp_disk_machine.name
112113
machine.wait_for_unit("default.target")
113-
114-
with subtest("Running with volatile root"):
115-
machine.succeed("findmnt --kernel --type tmpfs /")
116-
117-
with subtest("/nix/store is backed by dm-verity protected fs"):
118-
verity_info = machine.succeed("dmsetup info --target verity usr")
119-
assert "ACTIVE" in verity_info,f"unexpected verity info: {verity_info}"
120-
121-
backing_device = machine.succeed("df --output=source /nix/store | tail -n1").strip()
122-
assert "/dev/mapper/usr" == backing_device,"unexpected backing device: {backing_device}"
114+
run_verity_tests(machine)
115+
with subtest("Image version is set"):
116+
machine.succeed("grep IMAGE_VERSION=1 /etc/os-release")
117+
118+
tmp_disk_without_version = create_disk_image(
119+
"${nodes."without-version".virtualisation.qemu.package}/bin/qemu-img",
120+
"${nodes."without-version".system.build.image}/${nodes."without-version".image.filePath}",
121+
)
122+
os.environ['NIX_DISK_IMAGE'] = tmp_disk_without_version.name
123+
without_version.wait_for_unit("default.target")
124+
run_verity_tests(without_version)
125+
with subtest("Image version is not set"):
126+
without_version.succeed('grep IMAGE_VERSION="" /etc/os-release')
123127
'';
124128
}

nixos/tests/appliance-repart-image.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ in
109109
"-f",
110110
"qcow2",
111111
"-b",
112-
"${nodes.machine.system.build.image}/${nodes.machine.image.repart.imageFile}",
112+
"${nodes.machine.system.build.image}/${nodes.machine.image.filePath}",
113113
"-F",
114114
"raw",
115115
tmp_disk_image.name,

0 commit comments

Comments
 (0)