Skip to content

Commit 6fe546d

Browse files
committed
Fix #1045
1 parent e86a890 commit 6fe546d

File tree

4 files changed

+152
-127
lines changed

4 files changed

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

0 commit comments

Comments
 (0)