Skip to content

Commit ca0c35d

Browse files
committed
bcachefs-unlock: respect x-systemd mount options
This will allow unlocking to take place *after* all of the devices have been probed, as indicated by the x-systemd.wants and x-systemd.requires options. This allows for multi-device bcachefs volumes to be reliably unlocked.
1 parent 55c28aa commit ca0c35d

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

doc/release-notes/rl-2511.section.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737

3838
- Added `rewriteURL` attribute to the nixpkgs `config`, to allow for rewriting the URLs downloaded by `fetchurl`.
3939

40+
- The systemd initrd will now respect `x-systemd.wants` and `x-systemd.requires` for reliably unlocking multi-disk bcachefs volumes.
41+
4042
- New hardening flags, `strictflexarrays1` and `strictflexarrays3` were made available, corresponding to the gcc/clang options `-fstrict-flex-arrays=1` and `-fstrict-flex-arrays=3` respectively.
4143

4244
- `gramps` has been updated to 6.0.0

nixos/modules/tasks/filesystems/bcachefs.nix

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,19 +93,27 @@ let
9393
let
9494
mountUnit = "${utils.escapeSystemdPath (prefix + (lib.removeSuffix "/" fs.mountPoint))}.mount";
9595
device = firstDevice fs;
96-
deviceUnit = "${utils.escapeSystemdPath device}.device";
96+
mkDeviceUnit = device: "${utils.escapeSystemdPath device}.device";
97+
deviceUnit = mkDeviceUnit device;
98+
extractProperty =
99+
prop: options: (map (lib.removePrefix "${prop}=") (builtins.filter (lib.hasPrefix prop) options));
100+
normalizeUnits = unit: if lib.hasPrefix "/" unit then mkDeviceUnit unit else unit;
101+
requiredUnits = map normalizeUnits (extractProperty "x-systemd.requires" fs.options);
102+
wantedUnits = map normalizeUnits (extractProperty "x-systemd.wants" fs.options);
97103
in
98104
{
99105
name = "unlock-bcachefs-${utils.escapeSystemdPath fs.mountPoint}";
100106
value = {
101107
description = "Unlock bcachefs for ${fs.mountPoint}";
102108
requiredBy = [ mountUnit ];
103-
after = [ deviceUnit ];
109+
after = [ deviceUnit ] ++ requiredUnits ++ wantedUnits;
104110
before = [
105111
mountUnit
106112
"shutdown.target"
107113
];
108114
bindsTo = [ deviceUnit ];
115+
requires = requiredUnits;
116+
wants = wantedUnits;
109117
conflicts = [ "shutdown.target" ];
110118
unitConfig.DefaultDependencies = false;
111119
serviceConfig = {

0 commit comments

Comments
 (0)