From 403186440c93f52878768bca4602f35e3cafbc5b Mon Sep 17 00:00:00 2001 From: a-kenji Date: Wed, 6 May 2026 21:17:40 +0200 Subject: [PATCH] lib/types/bcachefs_filesystem: tolerate already-unlocked filesystem --- lib/types/bcachefs_filesystem.nix | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/types/bcachefs_filesystem.nix b/lib/types/bcachefs_filesystem.nix index 8a45367..232f9e1 100644 --- a/lib/types/bcachefs_filesystem.nix +++ b/lib/types/bcachefs_filesystem.nix @@ -191,9 +191,11 @@ ( TEMPDIR="$(mktemp -d)"; MNTPOINT="$(mktemp -d)"; - ${lib.optionalString ( - config.passwordFile != null - ) ''bcachefs unlock -k session "/dev/disk/by-uuid/${config.uuid}" < "${config.passwordFile}";''} + ${lib.optionalString (config.passwordFile != null) '' + if ! bcachefs unlock -k session "/dev/disk/by-uuid/${config.uuid}" < "${config.passwordFile}"; then + test -d "/sys/fs/bcachefs/${config.uuid}"; + fi; + ''} mount \ -t bcachefs \ -o "${lib.concatStringsSep "," (lib.unique ([ "X-mount.mkdir" ] ++ config.mountOptions))}" \ @@ -228,9 +230,11 @@ # @todo Figure out why the "X-mount.mkdir" option here doesn't seem to work, # necessitating running `mkdir` here. mkdir -p "${rootMountPoint}${subvolume.mountpoint}"; - ${lib.optionalString ( - config.passwordFile != null - ) ''bcachefs unlock -k session "/dev/disk/by-uuid/${config.uuid}" < "${config.passwordFile}";''} + ${lib.optionalString (config.passwordFile != null) '' + if ! bcachefs unlock -k session "/dev/disk/by-uuid/${config.uuid}" < "${config.passwordFile}"; then + test -d "/sys/fs/bcachefs/${config.uuid}"; + fi; + ''} mount \ -t bcachefs \ -o "${ @@ -260,9 +264,11 @@ # @todo Figure out why the "X-mount.mkdir" option here doesn't seem to work, # necessitating running `mkdir` here. mkdir -p "${rootMountPoint}${config.mountpoint}"; - ${lib.optionalString ( - config.passwordFile != null - ) ''bcachefs unlock -k session "/dev/disk/by-uuid/${config.uuid}" < "${config.passwordFile}";''} + ${lib.optionalString (config.passwordFile != null) '' + if ! bcachefs unlock -k session "/dev/disk/by-uuid/${config.uuid}" < "${config.passwordFile}"; then + test -d "/sys/fs/bcachefs/${config.uuid}"; + fi; + ''} mount \ -t bcachefs \ -o "${lib.concatStringsSep "," (lib.unique ([ "X-mount.mkdir" ] ++ config.mountOptions))}" \