add unmount feature

This commit is contained in:
Jörg Thalheim committed 2024-11-29 14:44:15 +01:00
1 parent 341482e2f4
commit aa006252c8
21 files changed
+247 -4

No files matched your search

+28
View File
@@ -199,6 +199,34 @@ in
};
};
};
_unmount = diskoLib.mkUnmountOption {
inherit config options;
default =
let
subvolMounts = lib.concatMapAttrs
(_: subvol:
lib.optionalAttrs
(subvol.mountpoint != null)
{
${subvol.mountpoint} = ''
if findmnt "${config.device}" "${rootMountPoint}${subvol.mountpoint}" > /dev/null 2>&1; then
umount "${rootMountPoint}${subvol.mountpoint}"
fi
'';
}
)
config.subvolumes;
in
{
fs = subvolMounts // lib.optionalAttrs (config.mountpoint != null) {
${config.mountpoint} = ''
if findmnt "${config.device}" "${rootMountPoint}${config.mountpoint}" > /dev/null 2>&1; then
umount "${rootMountPoint}${config.mountpoint}"
fi
'';
};
};
};
_config = lib.mkOption {
internal = true;
readOnly = true;
+4
View File
@@ -49,6 +49,10 @@
inherit config options;
default = lib.optionalAttrs (config.content != null) config.content._mount;
};
_unmount = diskoLib.mkUnmountOption {
inherit config options;
default = lib.optionalAttrs (config.content != null) config.content._unmount;
};
_config = lib.mkOption {
internal = true;
readOnly = true;
+10
View File
@@ -64,6 +64,16 @@
'';
};
};
_unmount = diskoLib.mkUnmountOption {
inherit config options;
default = lib.optionalAttrs (config.mountpoint != null) {
fs.${config.mountpoint} = ''
if findmnt "${config.device}" "${rootMountPoint}${config.mountpoint}" >/dev/null 2>&1; then
umount "${rootMountPoint}${config.mountpoint}"
fi
'';
};
};
_config = lib.mkOption {
internal = true;
readOnly = true;
+16 -1
View File
@@ -45,7 +45,7 @@ in
defaultText = ''
if the parent is an mdadm device:
/dev/disk/by-id/md-name-any:''${config._parent.name}-part''${toString partition.config._index}
otherwise:
/dev/disk/by-partlabel/''${diskoLib.hexEscapeUdevSymlink partition.config.label}
'';
@@ -249,6 +249,21 @@ in
fs = partMounts.fs or { };
};
};
_unmount = diskoLib.mkUnmountOption {
inherit config options;
default =
let
partMounts = lib.foldr lib.recursiveUpdate { } (map
(partition:
lib.optionalAttrs (partition.content != null) partition.content._unmount
)
(lib.attrValues config.partitions));
in
{
dev = partMounts.dev or "";
fs = partMounts.fs or { };
};
};
_config = lib.mkOption {
internal = true;
readOnly = true;
+15
View File
@@ -170,6 +170,21 @@ in
fs = lib.optionalAttrs (config.content != null) contentMount.fs or { };
};
};
_unmount = diskoLib.mkUnmountOption {
inherit config options;
default =
let
contentUnmount = config.content._unmount;
in
{
dev = ''
${lib.optionalString (config.content != null) contentUnmount.dev or ""}
if cryptsetup status "${config.name}" >/dev/null 2>/dev/null; then
cryptsetup close "${config.name}"
fi
'';
};
};
_config = lib.mkOption {
internal = true;
readOnly = true;
+4
View File
@@ -41,6 +41,10 @@
inherit config options;
default = { };
};
_unmount = diskoLib.mkUnmountOption {
inherit config options;
default = { };
};
_config = lib.mkOption {
internal = true;
readOnly = true;
+17
View File
@@ -127,6 +127,23 @@ in
fs = lvMounts.fs or { };
};
};
_unmount = diskoLib.mkUnmountOption {
inherit config options;
default =
let
lvMounts = diskoLib.deepMergeMap
(lv:
lib.optionalAttrs (lv.content != null) lv.content._unmount
)
(lib.attrValues config.lvs);
in {
dev = ''
${lib.concatMapStrings (x: x.dev or "") (lib.attrValues lvMounts)}
vgchange -a n
'';
fs = lvMounts.fs or { };
};
};
_config = lib.mkOption {
internal = true;
readOnly = true;
+14
View File
@@ -58,6 +58,20 @@
lib.optionalAttrs (config.content != null) config.content._mount;
# TODO we probably need to assemble the mdadm somehow
};
_unmount = diskoLib.mkUnmountOption {
inherit config options;
default = let
content = lib.optionalAttrs (config.content != null) config.content._unmount;
in {
fs = content.fs;
dev = ''
${content.dev or ""}
if [ -e "/dev/md/${config.name}" ]; then
mdadm --stop "/dev/md/${config.name}"
fi
'';
};
};
_config = lib.mkOption {
internal = true;
readOnly = true;
+4
View File
@@ -39,6 +39,10 @@
inherit config options;
default = { };
};
_unmount = diskoLib.mkUnmountOption {
inherit config options;
default = { };
};
_config = lib.mkOption {
internal = true;
readOnly = true;
+10
View File
@@ -49,6 +49,16 @@
'';
};
};
_unmount = diskoLib.mkUnmountOption {
inherit config options;
default = lib.optionalAttrs (config.mountpoint != null) {
fs.${config.mountpoint} = ''
if findmnt ${config.fsType} "${rootMountPoint}${config.mountpoint}" > /dev/null 2>&1; then
umount "${rootMountPoint}${config.mountpoint}"
fi
'';
};
};
_config = lib.mkOption {
internal = true;
readOnly = true;
+10
View File
@@ -95,6 +95,16 @@
'';
};
};
_unmount = diskoLib.mkUnmountOption {
inherit config options;
default = lib.optionalAttrs (!config.randomEncryption) {
fs.${config.device} = ''
if swapon --show | grep -q "^$(readlink -f "${config.device}") "; then
swapoff "${config.device}"
fi
'';
};
};
_config = lib.mkOption {
internal = true;
readOnly = true;
+15
View File
@@ -137,6 +137,21 @@
fs = partMounts.fs or { };
};
};
_unmount = diskoLib.mkUnmountOption {
inherit config options;
default =
let
partMounts = lib.foldr lib.recursiveUpdate { } (map
(partition:
lib.optionalAttrs (partition.content != null) partition.content._unmount
)
config.partitions);
in
{
dev = partMounts.dev or "";
fs = partMounts.fs or { };
};
};
_config = lib.mkOption {
internal = true;
readOnly = true;
+4
View File
@@ -38,6 +38,10 @@
inherit config options;
default = { };
};
_unmount = diskoLib.mkUnmountOption {
inherit config options;
default = { };
};
_config = lib.mkOption {
internal = true;
readOnly = true;
+12
View File
@@ -114,6 +114,18 @@
};
};
_unmount = diskoLib.mkUnmountOption {
inherit config options;
default =
lib.optionalAttrs (config.options.mountpoint or "" != "none" && config.options.canmount or "" != "off") {
fs.${config.mountpoint} = ''
if findmnt ${config._name} "${rootMountPoint}${config.mountpoint}" >/dev/null 2>&1; then
umount "${rootMountPoint}${config.mountpoint}"
fi
'';
};
};
_config = lib.mkOption {
internal = true;
readOnly = true;
+5
View File
@@ -64,6 +64,11 @@
default =
lib.optionalAttrs (config.content != null) config.content._mount;
};
_unmount = diskoLib.mkUnmountOption {
inherit config options;
default =
lib.optionalAttrs (config.content != null) config.content._unmount;
};
_config = lib.mkOption {
internal = true;
readOnly = true;
+17
View File
@@ -310,6 +310,23 @@ in
fs = datasetMounts.fs or { };
};
};
_unmount = diskoLib.mkUnmountOption {
inherit config options;
default =
let
datasetUnmounts = diskoLib.deepMergeMap (dataset: dataset._unmount) (lib.attrValues config.datasets);
in
{
dev = ''
${lib.concatMapStrings (x: x.dev or "") (lib.attrValues datasetUnmounts)}
if zpool list "${config.name}" >/dev/null 2>/dev/null; then
zpool export "${config.name}"
fi
'';
fs = datasetUnmounts.fs or { };
};
};
_config = lib.mkOption {
internal = true;
readOnly = true;