From 590de6c248a61dbbb317ea42dd1e7e418a3f3430 Mon Sep 17 00:00:00 2001 From: Francesco Zanini Date: Fri, 6 Jun 2025 15:22:13 +0200 Subject: [PATCH] Better handling of bind mounts in make-disk-image The device of the bind mounts is incorrectly taken verbatim while making the image. The root hierarchy is mounted at `config.rootMountDir` (`/mnt` by default) during the process, and this commit prepends that path to the `device` in these cases. --- lib/types/nodev.nix | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/lib/types/nodev.nix b/lib/types/nodev.nix index f0d3c503..55845c84 100644 --- a/lib/types/nodev.nix +++ b/lib/types/nodev.nix @@ -46,15 +46,20 @@ }; _mount = diskoLib.mkMountOption { inherit config options; - default = lib.optionalAttrs (config.mountpoint != null) { - fs.${config.mountpoint} = '' - if ! findmnt ${config.fsType} "${rootMountPoint}${config.mountpoint}" > /dev/null 2>&1; then - mount -t ${config.fsType} "${config.device}" "${rootMountPoint}${config.mountpoint}" \ - ${lib.concatMapStringsSep " " (opt: "-o ${opt}") config.mountOptions} \ - -o X-mount.mkdir - fi - ''; - }; + default = + let + isBindMount = builtins.elem "bind" config.mountOptions; + device = if isBindMount then "${rootMountPoint}${config.device}" else config.device; + in + lib.optionalAttrs (config.mountpoint != null) { + fs.${config.mountpoint} = '' + if ! findmnt ${config.fsType} "${rootMountPoint}${config.mountpoint}" > /dev/null 2>&1; then + mount -t ${config.fsType} "${device}" "${rootMountPoint}${config.mountpoint}" \ + ${lib.concatMapStringsSep " " (opt: "-o ${opt}") config.mountOptions} \ + -o X-mount.mkdir + fi + ''; + }; }; _unmount = diskoLib.mkUnmountOption { inherit config options;