Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 6 additions & 6 deletions flake.lock

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

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

outputs =
{ self, nixpkgs, ... }:
Expand Down
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
237 changes: 126 additions & 111 deletions tests/bcachefs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,125 +2,140 @@
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 = {
boot = {
kernelPackages = pkgs.linuxPackages_testing;
};
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:]]+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 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'");
# @todo Verify format arguments.

# @todo Verify format arguments.
# Verify mount options from configuration.
machine.succeed("""
findmnt -J \
| jq -e ' \
.filesystems[] \
| select(.target == "/") \
| .options \
| split(",") \
| contains(["verbose", "compression=lz4", "background_compression=lz4"]) \
'
""");

# Verify mount options from configuration.
machine.succeed("""
findmnt --json \
| jq -e ' \
.filesystems[] \
| select(.target == "/") \
| .options \
| split(",") \
| contains(["verbose", "compression=lz4", "background_compression=lz4"]) \
'
""");
machine.succeed("""
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"]) \
'
""");
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
'';
}