Skip to content

Commit 1f07dfb

Browse files
committed
Fix #1045
1 parent 17d08c6 commit 1f07dfb

File tree

4 files changed

+144
-124
lines changed

4 files changed

+144
-124
lines changed

flake.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
# FIXME: in future we don't want lock here to give precedence to a USB live-installer's registry,
55
# but garnix currently does not allow this.
66
#inputs.nixpkgs.url = "nixpkgs";
7-
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
7+
# @todo This needs to be reverted once https://github.com/NixOS/nixpkgs/pull/414391 is merged.
8+
inputs.nixpkgs.url = "github:chetgurevitch/nixpkgs/6f3ced85c7355e9711a5457d825d5f3e80a1bdf4";
9+
# inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
810

911
outputs =
1012
{ self, nixpkgs, ... }:

lib/types/bcachefs_filesystem.nix

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,10 @@
194194
${lib.optionalString (
195195
config.passwordFile != null
196196
) ''bcachefs unlock -k session "/dev/disk/by-uuid/${config.uuid}" < "${config.passwordFile}";''}
197-
bcachefs mount \
197+
mount \
198+
-t bcachefs \
198199
-o "${lib.concatStringsSep "," (lib.unique ([ "X-mount.mkdir" ] ++ config.mountOptions))}" \
199-
UUID="${config.uuid}" \
200+
"/dev/disk/by-uuid/${config.uuid}" \
200201
"$MNTPOINT";
201202
trap 'umount "$MNTPOINT"; rm -rf "$MNTPOINT"; rm -rf "$TEMPDIR";' EXIT;
202203
SUBVOL_ABS_PATH="$MNTPOINT/${subvolume.name}";
@@ -230,7 +231,8 @@
230231
${lib.optionalString (
231232
config.passwordFile != null
232233
) ''bcachefs unlock -k session "/dev/disk/by-uuid/${config.uuid}" < "${config.passwordFile}";''}
233-
bcachefs mount \
234+
mount \
235+
-t bcachefs \
234236
-o "${
235237
lib.concatStringsSep "," (
236238
lib.unique (
@@ -242,7 +244,7 @@
242244
)
243245
)
244246
}" \
245-
UUID="${config.uuid}" \
247+
"/dev/disk/by-uuid/${config.uuid}" \
246248
"${rootMountPoint}${subvolume.mountpoint}";
247249
fi;
248250
'';
@@ -261,9 +263,10 @@
261263
${lib.optionalString (
262264
config.passwordFile != null
263265
) ''bcachefs unlock -k session "/dev/disk/by-uuid/${config.uuid}" < "${config.passwordFile}";''}
264-
bcachefs mount \
266+
mount \
267+
-t bcachefs \
265268
-o "${lib.concatStringsSep "," (lib.unique ([ "X-mount.mkdir" ] ++ config.mountOptions))}" \
266-
UUID="${config.uuid}" \
269+
"/dev/disk/by-uuid/${config.uuid}" \
267270
"${rootMountPoint}${config.mountpoint}";
268271
fi;
269272
'';

tests/bcachefs.nix

Lines changed: 126 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -2,125 +2,140 @@
22
pkgs ? import <nixpkgs> { },
33
diskoLib ? pkgs.callPackage ../lib { },
44
}:
5-
diskoLib.testLib.makeDiskoTest {
6-
inherit pkgs;
7-
name = "bcachefs";
8-
disko-config = ../example/bcachefs.nix;
9-
enableOCR = true;
10-
bootCommands = ''
11-
machine.wait_for_text("enter passphrase for /");
12-
machine.send_chars("secretsecret\n");
13-
machine.wait_for_text("enter passphrase for /home");
14-
machine.send_chars("secretsecret\n");
15-
machine.wait_for_text("enter passphrase for /nix");
16-
machine.send_chars("secretsecret\n");
17-
'';
18-
extraSystemConfig = {
19-
environment.systemPackages = [
20-
pkgs.jq
21-
];
22-
};
23-
extraTestScript = ''
24-
# Print debug information.
25-
machine.succeed("ls -la /subvolumes >&2");
26-
machine.succeed("lsblk >&2");
27-
machine.succeed("lsblk -f >&2");
28-
machine.succeed("mount >&2");
29-
machine.succeed("bcachefs show-super /dev/vda2 >&2");
30-
machine.succeed("bcachefs show-super /dev/vdd1 >&2");
31-
machine.succeed("findmnt --json >&2");
5+
let
6+
diskoTest = diskoLib.testLib.makeDiskoTest {
7+
inherit pkgs;
8+
name = "bcachefs";
9+
disko-config = ../example/bcachefs.nix;
10+
enableOCR = true;
11+
bootCommands = ''
12+
machine.wait_for_text("enter passphrase for /");
13+
machine.send_chars("secretsecret\n");
14+
machine.wait_for_text("enter passphrase for /home");
15+
machine.send_chars("secretsecret\n");
16+
machine.wait_for_text("enter passphrase for /nix");
17+
machine.send_chars("secretsecret\n");
18+
'';
19+
extraInstallerConfig = {
20+
boot = {
21+
kernelPackages = pkgs.linuxPackages_testing;
22+
};
23+
environment.systemPackages = [
24+
pkgs.bcachefs-tools
25+
];
26+
};
27+
extraSystemConfig = {
28+
environment.systemPackages = [
29+
pkgs.jq
30+
];
31+
};
32+
extraTestScript = ''
33+
# Print debug information.
34+
machine.succeed("uname -a >&2");
35+
machine.succeed("ls -la / >&2");
36+
machine.succeed("lsblk >&2");
37+
machine.succeed("lsblk -f >&2");
38+
machine.succeed("mount >&2");
39+
machine.succeed("bcachefs show-super /dev/vda2 >&2");
40+
machine.succeed("bcachefs show-super /dev/vdd1 >&2");
41+
machine.succeed("findmnt -J >&2");
3242
33-
# Verify subvolume structure.
34-
machine.succeed("test -d /subvolumes/root");
35-
machine.succeed("test -d /subvolumes/home");
36-
machine.succeed("test -d /subvolumes/home/user");
37-
machine.succeed("test -d /subvolumes/nix");
38-
machine.succeed("test -d /subvolumes/test");
39-
machine.fail("test -d /subvolumes/non-existent");
43+
# Verify existence of mountpoints.
44+
machine.succeed("mountpoint /");
45+
machine.succeed("mountpoint /home");
46+
machine.succeed("mountpoint /nix");
47+
machine.succeed("mountpoint /home/Documents");
48+
machine.fail("mountpoint /non-existent");
4049
41-
# Verify existence of mountpoints.
42-
machine.succeed("mountpoint /");
43-
machine.succeed("mountpoint /home");
44-
machine.succeed("mountpoint /nix");
45-
machine.succeed("mountpoint /home/Documents");
46-
machine.fail("mountpoint /non-existent");
50+
# Verify device membership and labels.
51+
machine.succeed("bcachefs show-super /dev/vda2 | grep 'Devices:' | grep -q '3'");
52+
machine.succeed("bcachefs show-super /dev/vdd1 | grep 'Devices:' | grep -q '1'");
53+
machine.succeed("bcachefs show-super /dev/vda2 | grep -qE '^[[:space:]]+Label:[[:space:]]+vdb2[[:space:]]\([[:digit:]]+\)'");
54+
machine.succeed("bcachefs show-super /dev/vda2 | grep -qE '^[[:space:]]+Label:[[:space:]]+vdc1[[:space:]]\([[:digit:]]+\)'");
55+
machine.succeed("bcachefs show-super /dev/vda2 | grep -qE '^[[:space:]]+Label:[[:space:]]+vdd1[[:space:]]\([[:digit:]]+\)'");
56+
machine.succeed("bcachefs show-super /dev/vdd1 | grep -qE '^[[:space:]]+Label:[[:space:]]+vde1[[:space:]]\([[:digit:]]+\)'");
57+
machine.fail("bcachefs show-super /dev/vda2 | grep 'Label:' | grep -q 'non-existent'");
4758
48-
# Verify device membership and labels.
49-
machine.succeed("bcachefs show-super /dev/vda2 | grep 'Devices:' | grep -q '3'");
50-
machine.succeed("bcachefs show-super /dev/vdd1 | grep 'Devices:' | grep -q '1'");
51-
machine.succeed("bcachefs show-super /dev/vda2 | grep -qE '^[[:space:]]+Label:[[:space:]]+vdb2[[:space:]]\([[:digit:]]+\)'");
52-
machine.succeed("bcachefs show-super /dev/vda2 | grep -qE '^[[:space:]]+Label:[[:space:]]+vdc1[[:space:]]\([[:digit:]]+\)'");
53-
machine.succeed("bcachefs show-super /dev/vda2 | grep -qE '^[[:space:]]+Label:[[:space:]]+vdd1[[:space:]]\([[:digit:]]+\)'");
54-
machine.succeed("bcachefs show-super /dev/vdd1 | grep -qE '^[[:space:]]+Label:[[:space:]]+vde1[[:space:]]\([[:digit:]]+\)'");
55-
machine.fail("bcachefs show-super /dev/vda2 | grep 'Label:' | grep -q 'non-existent'");
59+
# @todo Verify format arguments.
5660
57-
# @todo Verify format arguments.
61+
# Verify mount options from configuration.
62+
machine.succeed("""
63+
findmnt -J \
64+
| jq -e ' \
65+
.filesystems[] \
66+
| select(.target == "/") \
67+
| .options \
68+
| split(",") \
69+
| contains(["verbose", "compression=lz4", "background_compression=lz4"]) \
70+
'
71+
""");
5872
59-
# Verify mount options from configuration.
60-
machine.succeed("""
61-
findmnt --json \
62-
| jq -e ' \
63-
.filesystems[] \
64-
| select(.target == "/") \
65-
| .options \
66-
| split(",") \
67-
| contains(["verbose", "compression=lz4", "background_compression=lz4"]) \
68-
'
69-
""");
73+
machine.succeed("""
74+
findmnt -J \
75+
| jq -e ' \
76+
.filesystems[] \
77+
| .. \
78+
| select(.target? == "/home/Documents") \
79+
| .options \
80+
| split(",") \
81+
| contains(["verbose"]) \
82+
'
83+
""");
7084
71-
machine.succeed("""
72-
findmnt --json \
73-
| jq -e ' \
74-
.filesystems[] \
75-
| .. \
76-
| select(.target? == "/home/Documents") \
77-
| .options \
78-
| split(",") \
79-
| contains(["verbose"]) \
80-
'
81-
""");
85+
machine.fail("""
86+
findmnt -J \
87+
| jq -e ' \
88+
.filesystems[] \
89+
| select(.target == "/") \
90+
| .options \
91+
| split(",") \
92+
| contains(["non-existent"]) \
93+
'
94+
""");
8295
83-
machine.fail("""
84-
findmnt --json \
85-
| jq -e ' \
86-
.filesystems[] \
87-
| select(.target == "/") \
88-
| .options \
89-
| split(",") \
90-
| contains(["non-existent"]) \
91-
'
92-
""");
96+
# Verify device composition of filesystems.
97+
machine.succeed("""
98+
findmnt -J \
99+
| jq -e ' \
100+
.filesystems[] \
101+
| select(.target == "/") \
102+
| .source \
103+
| contains("/dev/vda2") \
104+
and contains("/dev/vdb1") \
105+
and contains("/dev/vdc1") \
106+
and contains("[/subvolumes/root]") \
107+
'
108+
""");
93109
94-
# Verify device composition of filesystems.
95-
machine.succeed("""
96-
findmnt --json \
97-
| jq -e ' \
98-
.filesystems[] \
99-
| select(.target == "/") \
100-
| .source | split(":") \
101-
| contains(["/dev/vda2", "/dev/vdb1", "/dev/vdc1"]) \
102-
'
103-
""");
110+
machine.succeed("""
111+
findmnt -J \
112+
| jq -e ' \
113+
.filesystems[] \
114+
| .. \
115+
| select(.target? == "/home/Documents") \
116+
| .source \
117+
| contains("/dev/vdd1") \
118+
'
119+
""");
104120
105-
machine.succeed("""
106-
findmnt --json \
107-
| jq -e ' \
108-
.filesystems[] \
109-
| .. \
110-
| select(.target? == "/home/Documents") \
111-
| .source \
112-
| contains("/dev/disk/by-uuid/64e50034-ebe2-eaf8-1f93-cf56266a8d86") \
113-
'
114-
""");
115-
116-
machine.fail("""
117-
findmnt --json \
118-
| jq -e ' \
119-
.filesystems[] \
120-
| select(.target == "/") \
121-
| .source | split(":") \
122-
| contains(["/dev/non-existent"]) \
123-
'
124-
""");
121+
machine.fail("""
122+
findmnt -J \
123+
| jq -e ' \
124+
.filesystems[] \
125+
| select(.target == "/") \
126+
| .source \
127+
| contains(["/dev/non-existent"]) \
128+
'
129+
""");
130+
'';
131+
};
132+
in
133+
pkgs.lib.attrsets.recursiveUpdate diskoTest {
134+
nodes.machine.boot.initrd.extraUtilsCommands = ''
135+
${diskoTest.nodes.machine.boot.initrd.extraUtilsCommands}
136+
# Copy tools for bcachefs
137+
copy_bin_and_libs ${pkgs.lib.getOutput "mount" pkgs.util-linux}/bin/mount
138+
copy_bin_and_libs ${pkgs.bcachefs-tools}/bin/bcachefs
139+
copy_bin_and_libs ${pkgs.bcachefs-tools}/bin/mount.bcachefs
125140
'';
126141
}

0 commit comments

Comments
 (0)