Skip to content

Commit 590de6c

Browse files
committed
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.
1 parent 17d08c6 commit 590de6c

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

lib/types/nodev.nix

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,20 @@
4646
};
4747
_mount = diskoLib.mkMountOption {
4848
inherit config options;
49-
default = lib.optionalAttrs (config.mountpoint != null) {
50-
fs.${config.mountpoint} = ''
51-
if ! findmnt ${config.fsType} "${rootMountPoint}${config.mountpoint}" > /dev/null 2>&1; then
52-
mount -t ${config.fsType} "${config.device}" "${rootMountPoint}${config.mountpoint}" \
53-
${lib.concatMapStringsSep " " (opt: "-o ${opt}") config.mountOptions} \
54-
-o X-mount.mkdir
55-
fi
56-
'';
57-
};
49+
default =
50+
let
51+
isBindMount = builtins.elem "bind" config.mountOptions;
52+
device = if isBindMount then "${rootMountPoint}${config.device}" else config.device;
53+
in
54+
lib.optionalAttrs (config.mountpoint != null) {
55+
fs.${config.mountpoint} = ''
56+
if ! findmnt ${config.fsType} "${rootMountPoint}${config.mountpoint}" > /dev/null 2>&1; then
57+
mount -t ${config.fsType} "${device}" "${rootMountPoint}${config.mountpoint}" \
58+
${lib.concatMapStringsSep " " (opt: "-o ${opt}") config.mountOptions} \
59+
-o X-mount.mkdir
60+
fi
61+
'';
62+
};
5863
};
5964
_unmount = diskoLib.mkUnmountOption {
6065
inherit config options;

0 commit comments

Comments
 (0)