Skip to content

Commit b1fb050

Browse files
bcachefs-unlock: respect x-systemd mount options (#419473)
2 parents 2e7bce1 + 814bbef commit b1fb050

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

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

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

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

44+
- The systemd initrd will now respect `x-systemd.wants` and `x-systemd.requires` for reliably unlocking multi-disk bcachefs volumes.
45+
4446
- 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.
4547

4648
- `gramps` has been updated to 6.0.0

nixos/modules/tasks/filesystems/bcachefs.nix

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,19 +93,35 @@ 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+
mkMountUnit = path: "${utils.escapeSystemdPath path}.mount";
101+
normalizeUnits =
102+
unit:
103+
if lib.hasPrefix "/dev/" unit then
104+
mkDeviceUnit unit
105+
else if lib.hasPrefix "/" unit then
106+
mkMountUnit unit
107+
else
108+
unit;
109+
requiredUnits = map normalizeUnits (extractProperty "x-systemd.requires" fs.options);
110+
wantedUnits = map normalizeUnits (extractProperty "x-systemd.wants" fs.options);
97111
in
98112
{
99113
name = "unlock-bcachefs-${utils.escapeSystemdPath fs.mountPoint}";
100114
value = {
101115
description = "Unlock bcachefs for ${fs.mountPoint}";
102116
requiredBy = [ mountUnit ];
103-
after = [ deviceUnit ];
117+
after = [ deviceUnit ] ++ requiredUnits ++ wantedUnits;
104118
before = [
105119
mountUnit
106120
"shutdown.target"
107121
];
108122
bindsTo = [ deviceUnit ];
123+
requires = requiredUnits;
124+
wants = wantedUnits;
109125
conflicts = [ "shutdown.target" ];
110126
unitConfig.DefaultDependencies = false;
111127
serviceConfig = {

0 commit comments

Comments
 (0)