Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions example/bcachefs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,6 @@
relies_on_external_subvolume = {
type = "bcachefs_filesystem";
mountpoint = "/home/Documents";
extraFormatArgs = [
"--compression=lz4"
"--background_compression=lz4"
];
mountOptions = [
"verbose"
];
uuid = "64e50034-ebe2-eaf8-1f93-cf56266a8d86";
};
};
Expand Down
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 9 additions & 6 deletions lib/types/bcachefs_filesystem.nix
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,10 @@
${lib.optionalString (
config.passwordFile != null
) ''bcachefs unlock -k session "/dev/disk/by-uuid/${config.uuid}" < "${config.passwordFile}";''}
bcachefs mount \
mount \
-t bcachefs \
-o "${lib.concatStringsSep "," (lib.unique ([ "X-mount.mkdir" ] ++ config.mountOptions))}" \
UUID="${config.uuid}" \
"/dev/disk/by-uuid/${config.uuid}" \
"$MNTPOINT";
trap 'umount "$MNTPOINT"; rm -rf "$MNTPOINT"; rm -rf "$TEMPDIR";' EXIT;
SUBVOL_ABS_PATH="$MNTPOINT/${subvolume.name}";
Expand Down Expand Up @@ -230,7 +231,8 @@
${lib.optionalString (
config.passwordFile != null
) ''bcachefs unlock -k session "/dev/disk/by-uuid/${config.uuid}" < "${config.passwordFile}";''}
bcachefs mount \
mount \
-t bcachefs \
-o "${
lib.concatStringsSep "," (
lib.unique (
Expand All @@ -242,7 +244,7 @@
)
)
}" \
UUID="${config.uuid}" \
"/dev/disk/by-uuid/${config.uuid}" \
"${rootMountPoint}${subvolume.mountpoint}";
fi;
'';
Expand All @@ -261,9 +263,10 @@
${lib.optionalString (
config.passwordFile != null
) ''bcachefs unlock -k session "/dev/disk/by-uuid/${config.uuid}" < "${config.passwordFile}";''}
bcachefs mount \
mount \
-t bcachefs \
-o "${lib.concatStringsSep "," (lib.unique ([ "X-mount.mkdir" ] ++ config.mountOptions))}" \
UUID="${config.uuid}" \
"/dev/disk/by-uuid/${config.uuid}" \
"${rootMountPoint}${config.mountpoint}";
fi;
'';
Expand Down
252 changes: 141 additions & 111 deletions tests/bcachefs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,125 +2,155 @@
pkgs ? import <nixpkgs> { },
diskoLib ? pkgs.callPackage ../lib { },
}:
diskoLib.testLib.makeDiskoTest {
inherit pkgs;
name = "bcachefs";
disko-config = ../example/bcachefs.nix;
enableOCR = true;
bootCommands = ''
machine.wait_for_text("enter passphrase for /");
machine.send_chars("secretsecret\n");
machine.wait_for_text("enter passphrase for /home");
machine.send_chars("secretsecret\n");
machine.wait_for_text("enter passphrase for /nix");
machine.send_chars("secretsecret\n");
'';
extraSystemConfig = {
environment.systemPackages = [
pkgs.jq
];
};
extraTestScript = ''
# Print debug information.
machine.succeed("ls -la /subvolumes >&2");
machine.succeed("lsblk >&2");
machine.succeed("lsblk -f >&2");
machine.succeed("mount >&2");
machine.succeed("bcachefs show-super /dev/vda2 >&2");
machine.succeed("bcachefs show-super /dev/vdd1 >&2");
machine.succeed("findmnt --json >&2");
let
diskoTest = diskoLib.testLib.makeDiskoTest {
inherit pkgs;
name = "bcachefs";
disko-config = ../example/bcachefs.nix;
enableOCR = true;
bootCommands = ''
machine.wait_for_text("enter passphrase for /");
machine.send_chars("secretsecret\n");
machine.wait_for_text("enter passphrase for /home");
machine.send_chars("secretsecret\n");
machine.wait_for_text("enter passphrase for /nix");
machine.send_chars("secretsecret\n");
'';
extraInstallerConfig = { config, ... }: {
boot = {
kernelPackages = pkgs.linuxPackages_testing;
extraModulePackages = [
(config.boot.kernelPackages.callPackage pkgs.bcachefs-tools.kernelModule {})
];
# Can also use the following instead of the above,
# which doesn't necessitate passing in `config`,
# so `{ config, ... }: ` can be removed:
# supportedFilesystems = [ "bcachefs" ];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Enzime @Mic92 Thoughts on this? I'm not sure which one to use.

};
environment.systemPackages = [
pkgs.bcachefs-tools
];
};
extraSystemConfig = {
environment.systemPackages = [
pkgs.jq
];
};
extraTestScript = ''
# Print debug information.
machine.succeed("uname -a >&2");
machine.succeed("ls -la / >&2");
machine.succeed("lsblk >&2");
machine.succeed("lsblk -f >&2");
machine.succeed("mount >&2");
machine.succeed("bcachefs show-super /dev/vda2 >&2");
machine.succeed("bcachefs show-super /dev/vdd1 >&2");
machine.succeed("findmnt -J >&2");
# Verify subvolume structure.
machine.succeed("test -d /subvolumes/root");
machine.succeed("test -d /subvolumes/home");
machine.succeed("test -d /subvolumes/home/user");
machine.succeed("test -d /subvolumes/nix");
machine.succeed("test -d /subvolumes/test");
machine.fail("test -d /subvolumes/non-existent");
# Verify existence of mountpoints.
machine.succeed("mountpoint /");
machine.succeed("mountpoint /home");
machine.succeed("mountpoint /nix");
machine.succeed("mountpoint /home/Documents");
machine.fail("mountpoint /non-existent");
# Verify existence of mountpoints.
machine.succeed("mountpoint /");
machine.succeed("mountpoint /home");
machine.succeed("mountpoint /nix");
machine.succeed("mountpoint /home/Documents");
machine.fail("mountpoint /non-existent");
# Verify device membership and labels.
machine.succeed("bcachefs show-super /dev/vda2 | grep 'Devices:' | grep -q '3'");
machine.succeed("bcachefs show-super /dev/vdd1 | grep 'Devices:' | grep -q '1'");
machine.succeed("bcachefs show-super /dev/vda2 | grep -qE '^[[:space:]]*Label:[[:space:]]+group_a\.vdb2'");
machine.succeed("bcachefs show-super /dev/vda2 | grep -qE '^[[:space:]]*Label:[[:space:]]+group_a\.vdc1'");
machine.succeed("bcachefs show-super /dev/vda2 | grep -qE '^[[:space:]]*Label:[[:space:]]+group_b\.vdd1'");
machine.succeed("bcachefs show-super /dev/vdd1 | grep -qE '^[[:space:]]*Label:[[:space:]]+group_a\.vde1'");
machine.fail("bcachefs show-super /dev/vda2 | grep 'Label:' | grep -q 'non-existent'");
# Verify device membership and labels.
machine.succeed("bcachefs show-super /dev/vda2 | grep 'Devices:' | grep -q '3'");
machine.succeed("bcachefs show-super /dev/vdd1 | grep 'Devices:' | grep -q '1'");
machine.succeed("bcachefs show-super /dev/vda2 | grep -qE '^[[:space:]]+Label:[[:space:]]+vdb2[[:space:]]\([[:digit:]]+\)'");
machine.succeed("bcachefs show-super /dev/vda2 | grep -qE '^[[:space:]]+Label:[[:space:]]+vdc1[[:space:]]\([[:digit:]]+\)'");
machine.succeed("bcachefs show-super /dev/vda2 | grep -qE '^[[:space:]]+Label:[[:space:]]+vdd1[[:space:]]\([[:digit:]]+\)'");
machine.succeed("bcachefs show-super /dev/vdd1 | grep -qE '^[[:space:]]+Label:[[:space:]]+vde1[[:space:]]\([[:digit:]]+\)'");
machine.fail("bcachefs show-super /dev/vda2 | grep 'Label:' | grep -q 'non-existent'");
# Verify format arguments.
# Test that lza4 compression and background_compression options were set for vda2.
machine.succeed("bcachefs show-super /dev/vda2 | grep -qE '^[[:space:]]*compression:[[:space:]]+lz4'");
machine.succeed("bcachefs show-super /dev/vda2 | grep -qE '^[[:space:]]*background_compression:[[:space:]]+lz4'");
# Test that no compression option was set for vdd1.
machine.succeed("bcachefs show-super /dev/vdd1 | grep -qE '^[[:space:]]*compression:[[:space:]]+none'");
# @todo Verify format arguments.
# Verify mount options from configuration.
# Test that verbose option was set for "/".
machine.succeed("""
findmnt -J \
| jq -e ' \
.filesystems[] \
| select(.target == "/") \
| .options \
| split(",") \
| contains(["verbose"]) \
'
""");
# Verify mount options from configuration.
machine.succeed("""
findmnt --json \
| jq -e ' \
.filesystems[] \
| select(.target == "/") \
| .options \
| split(",") \
| contains(["verbose", "compression=lz4", "background_compression=lz4"]) \
'
""");
# Test that verbose option was not set for "/home/Documents".
machine.fail("""
findmnt -J \
| jq -e ' \
.filesystems[] \
| .. \
| select(.target? == "/home/Documents") \
| .options \
| split(",") \
| contains(["verbose"]) \
'
""");
machine.succeed("""
findmnt --json \
| jq -e ' \
.filesystems[] \
| .. \
| select(.target? == "/home/Documents") \
| .options \
| split(",") \
| contains(["verbose"]) \
'
""");
# Test that non-existent option was not set for "/".
machine.fail("""
findmnt -J \
| jq -e ' \
.filesystems[] \
| select(.target == "/") \
| .options \
| split(",") \
| contains(["non-existent"]) \
'
""");
machine.fail("""
findmnt --json \
| jq -e ' \
.filesystems[] \
| select(.target == "/") \
| .options \
| split(",") \
| contains(["non-existent"]) \
'
""");
# Verify device composition of filesystems.
machine.succeed("""
findmnt -J \
| jq -e ' \
.filesystems[] \
| select(.target == "/") \
| .source \
| contains("/dev/vda2") \
and contains("/dev/vdb1") \
and contains("/dev/vdc1") \
and contains("[/subvolumes/root]") \
'
""");
# Verify device composition of filesystems.
machine.succeed("""
findmnt --json \
| jq -e ' \
.filesystems[] \
| select(.target == "/") \
| .source | split(":") \
| contains(["/dev/vda2", "/dev/vdb1", "/dev/vdc1"]) \
'
""");
machine.succeed("""
findmnt -J \
| jq -e ' \
.filesystems[] \
| .. \
| select(.target? == "/home/Documents") \
| .source \
| contains("/dev/vdd1") \
'
""");
machine.succeed("""
findmnt --json \
| jq -e ' \
.filesystems[] \
| .. \
| select(.target? == "/home/Documents") \
| .source \
| contains("/dev/disk/by-uuid/64e50034-ebe2-eaf8-1f93-cf56266a8d86") \
'
""");
machine.fail("""
findmnt --json \
| jq -e ' \
.filesystems[] \
| select(.target == "/") \
| .source | split(":") \
| contains(["/dev/non-existent"]) \
'
""");
machine.fail("""
findmnt -J \
| jq -e ' \
.filesystems[] \
| select(.target == "/") \
| .source \
| contains(["/dev/non-existent"]) \
'
""");
'';
};
in
pkgs.lib.attrsets.recursiveUpdate diskoTest {
nodes.machine.boot.initrd.extraUtilsCommands = ''
${diskoTest.nodes.machine.boot.initrd.extraUtilsCommands}
# Copy tools for bcachefs
copy_bin_and_libs ${pkgs.lib.getOutput "mount" pkgs.util-linux}/bin/mount
copy_bin_and_libs ${pkgs.bcachefs-tools}/bin/bcachefs
copy_bin_and_libs ${pkgs.bcachefs-tools}/bin/mount.bcachefs
'';
}