Skip to content

Commit d6d6c38

Browse files
committed
Fix #1045
1 parent e86a890 commit d6d6c38

File tree

4 files changed

+153
-127
lines changed

4 files changed

+153
-127
lines changed

example/bcachefs.nix

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,6 @@
135135
relies_on_external_subvolume = {
136136
type = "bcachefs_filesystem";
137137
mountpoint = "/home/Documents";
138-
extraFormatArgs = [
139-
"--compression=lz4"
140-
"--background_compression=lz4"
141-
];
142-
mountOptions = [
143-
"verbose"
144-
];
145138
uuid = "64e50034-ebe2-eaf8-1f93-cf56266a8d86";
146139
};
147140
};

flake.lock

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

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: 141 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -2,125 +2,155 @@
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 = { config, ... }: {
20+
boot = {
21+
kernelPackages = pkgs.linuxPackages_testing;
22+
extraModulePackages = [
23+
(config.boot.kernelPackages.callPackage pkgs.bcachefs-tools.kernelModule {})
24+
];
25+
# Can also use the following instead of the above,
26+
# which doesn't necessitate passing in `config`,
27+
# so `{ config, ... }: ` can be removed:
28+
# supportedFilesystems = [ "bcachefs" ];
29+
};
30+
environment.systemPackages = [
31+
pkgs.bcachefs-tools
32+
];
33+
};
34+
extraSystemConfig = {
35+
environment.systemPackages = [
36+
pkgs.jq
37+
];
38+
};
39+
extraTestScript = ''
40+
# Print debug information.
41+
machine.succeed("uname -a >&2");
42+
machine.succeed("ls -la / >&2");
43+
machine.succeed("lsblk >&2");
44+
machine.succeed("lsblk -f >&2");
45+
machine.succeed("mount >&2");
46+
machine.succeed("bcachefs show-super /dev/vda2 >&2");
47+
machine.succeed("bcachefs show-super /dev/vdd1 >&2");
48+
machine.succeed("findmnt -J >&2");
3249
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");
50+
# Verify existence of mountpoints.
51+
machine.succeed("mountpoint /");
52+
machine.succeed("mountpoint /home");
53+
machine.succeed("mountpoint /nix");
54+
machine.succeed("mountpoint /home/Documents");
55+
machine.fail("mountpoint /non-existent");
4056
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");
57+
# Verify device membership and labels.
58+
machine.succeed("bcachefs show-super /dev/vda2 | grep 'Devices:' | grep -q '3'");
59+
machine.succeed("bcachefs show-super /dev/vdd1 | grep 'Devices:' | grep -q '1'");
60+
machine.succeed("bcachefs show-super /dev/vda2 | grep -qE '^[[:space:]]*Label:[[:space:]]+group_a\.vdb2'");
61+
machine.succeed("bcachefs show-super /dev/vda2 | grep -qE '^[[:space:]]*Label:[[:space:]]+group_a\.vdc1'");
62+
machine.succeed("bcachefs show-super /dev/vda2 | grep -qE '^[[:space:]]*Label:[[:space:]]+group_b\.vdd1'");
63+
machine.succeed("bcachefs show-super /dev/vdd1 | grep -qE '^[[:space:]]*Label:[[:space:]]+group_a\.vde1'");
64+
machine.fail("bcachefs show-super /dev/vda2 | grep 'Label:' | grep -q 'non-existent'");
4765
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'");
66+
# Verify format arguments.
67+
# Test that lza4 compression and background_compression options were set for vda2.
68+
machine.succeed("bcachefs show-super /dev/vda2 | grep -qE '^[[:space:]]*compression:[[:space:]]+lz4'");
69+
machine.succeed("bcachefs show-super /dev/vda2 | grep -qE '^[[:space:]]*background_compression:[[:space:]]+lz4'");
70+
# Test that no compression option was set for vdd1.
71+
machine.succeed("bcachefs show-super /dev/vdd1 | grep -qE '^[[:space:]]*compression:[[:space:]]+none'");
5672
57-
# @todo Verify format arguments.
73+
# Verify mount options from configuration.
74+
# Test that verbose option was set for "/".
75+
machine.succeed("""
76+
findmnt -J \
77+
| jq -e ' \
78+
.filesystems[] \
79+
| select(.target == "/") \
80+
| .options \
81+
| split(",") \
82+
| contains(["verbose"]) \
83+
'
84+
""");
5885
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-
""");
86+
# Test that verbose option was not set for "/home/Documents".
87+
machine.fail("""
88+
findmnt -J \
89+
| jq -e ' \
90+
.filesystems[] \
91+
| .. \
92+
| select(.target? == "/home/Documents") \
93+
| .options \
94+
| split(",") \
95+
| contains(["verbose"]) \
96+
'
97+
""");
7098
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-
""");
99+
# Test that non-existent option was not set for "/".
100+
machine.fail("""
101+
findmnt -J \
102+
| jq -e ' \
103+
.filesystems[] \
104+
| select(.target == "/") \
105+
| .options \
106+
| split(",") \
107+
| contains(["non-existent"]) \
108+
'
109+
""");
82110
83-
machine.fail("""
84-
findmnt --json \
85-
| jq -e ' \
86-
.filesystems[] \
87-
| select(.target == "/") \
88-
| .options \
89-
| split(",") \
90-
| contains(["non-existent"]) \
91-
'
92-
""");
111+
# Verify device composition of filesystems.
112+
machine.succeed("""
113+
findmnt -J \
114+
| jq -e ' \
115+
.filesystems[] \
116+
| select(.target == "/") \
117+
| .source \
118+
| contains("/dev/vda2") \
119+
and contains("/dev/vdb1") \
120+
and contains("/dev/vdc1") \
121+
and contains("[/subvolumes/root]") \
122+
'
123+
""");
93124
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-
""");
125+
machine.succeed("""
126+
findmnt -J \
127+
| jq -e ' \
128+
.filesystems[] \
129+
| .. \
130+
| select(.target? == "/home/Documents") \
131+
| .source \
132+
| contains("/dev/vdd1") \
133+
'
134+
""");
104135
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-
""");
136+
machine.fail("""
137+
findmnt -J \
138+
| jq -e ' \
139+
.filesystems[] \
140+
| select(.target == "/") \
141+
| .source \
142+
| contains(["/dev/non-existent"]) \
143+
'
144+
""");
145+
'';
146+
};
147+
in
148+
pkgs.lib.attrsets.recursiveUpdate diskoTest {
149+
nodes.machine.boot.initrd.extraUtilsCommands = ''
150+
${diskoTest.nodes.machine.boot.initrd.extraUtilsCommands}
151+
# Copy tools for bcachefs
152+
copy_bin_and_libs ${pkgs.lib.getOutput "mount" pkgs.util-linux}/bin/mount
153+
copy_bin_and_libs ${pkgs.bcachefs-tools}/bin/bcachefs
154+
copy_bin_and_libs ${pkgs.bcachefs-tools}/bin/mount.bcachefs
125155
'';
126156
}

0 commit comments

Comments
 (0)