diff --git a/example/bcachefs.nix b/example/bcachefs.nix index 023822b5..2cef63a6 100644 --- a/example/bcachefs.nix +++ b/example/bcachefs.nix @@ -82,7 +82,7 @@ content = { type = "gpt"; partitions = { - vdd1 = { + vde1 = { size = "100%"; content = { type = "bcachefs"; @@ -93,6 +93,16 @@ }; }; }; + + vdf = { + device = "/dev/vdf"; + type = "disk"; + content = { + type = "bcachefs"; + label = ""; + filesystem = "empty_label"; + }; + }; }; bcachefs_filesystems = { @@ -137,6 +147,12 @@ mountpoint = "/home/Documents"; uuid = "64e50034-ebe2-eaf8-1f93-cf56266a8d86"; }; + + # Example bcachefs filesystem without a label + empty_label = { + type = "bcachefs_filesystem"; + mountpoint = "/empty_label"; + }; }; }; } diff --git a/lib/types/bcachefs.nix b/lib/types/bcachefs.nix index a1e00a15..5dd89e8e 100644 --- a/lib/types/bcachefs.nix +++ b/lib/types/bcachefs.nix @@ -66,7 +66,7 @@ default = '' # Write device arguments to temporary directory for bcachefs_filesystem. { - printf '%s\n' '--label=${config.label}'; + ${lib.optionalString (config.label != "") ''printf '%s\n' '--label=${config.label}';''} ${lib.concatMapStrings (args: ''printf '%s\n' '${args}';'') config.extraFormatArgs} printf '%s\n' '${config.device}'; } >> "$disko_devices_dir/bcachefs-${lib.escapeShellArg config.filesystem}"; diff --git a/tests/bcachefs.nix b/tests/bcachefs.nix index 84cd8d23..0da40451 100644 --- a/tests/bcachefs.nix +++ b/tests/bcachefs.nix @@ -48,6 +48,7 @@ diskoLib.testLib.makeDiskoTest { machine.succeed("mountpoint /home"); machine.succeed("mountpoint /nix"); machine.succeed("mountpoint /home/Documents"); + machine.succeed("mountpoint /empty_label") machine.fail("mountpoint /non-existent"); # Verify device membership and labels. @@ -56,9 +57,15 @@ diskoLib.testLib.makeDiskoTest { 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'"); + + ## !Warning! device /dev/vde1 in the example config shows up as /dev/vdd1 here machine.succeed("bcachefs show-super /dev/vdd1 | grep -qE '^[[:space:]]*Label:[[:space:]]+group_a\.vde1'"); + ## !Warning! device /dev/vdf is the example config shows up as /dev/vde here + machine.succeed("bcachefs show-super /dev/vde | grep -qE '^Label:[[:space:]]+\(none\)'"); + 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'");