zpool: add option to mount zpool not at /

This commit is contained in:
Sandro Jäckel 2023-04-20 23:42:18 +02:00
parent e10586ab84
commit e78e5b1da7
No known key found for this signature in database
GPG key ID: 3AF5A43A3EECC2E5

View file

@ -37,6 +37,17 @@
default = [ "defaults" ]; default = [ "defaults" ];
description = "Options to pass to mount"; description = "Options to pass to mount";
}; };
mountRoot = lib.mkOption {
type = lib.types.str;
default = "/";
example = "/mnt";
description = ''
The root location where the zpool should be mounted.
Note:
Leaving this at the default "/" might break your live system.
'';
};
datasets = lib.mkOption { datasets = lib.mkOption {
type = lib.types.attrsOf (diskoLib.subType { inherit (subTypes) zfs_fs zfs_volume; }); type = lib.types.attrsOf (diskoLib.subType { inherit (subTypes) zfs_fs zfs_volume; });
# type = lib.types.attrsOf subTypes.zfs_fs; # type = lib.types.attrsOf subTypes.zfs_fs;
@ -55,7 +66,7 @@
default = _: '' default = _: ''
readarray -t zfs_devices < <(cat "$disko_devices_dir"/zfs_${config.name}) readarray -t zfs_devices < <(cat "$disko_devices_dir"/zfs_${config.name})
zpool create ${config.name} \ zpool create ${config.name} \
${config.mode} \ -R ${config.mountRoot} ${config.mode} \
${lib.concatStringsSep " " (lib.mapAttrsToList (n: v: "-o ${n}=${v}") config.options)} \ ${lib.concatStringsSep " " (lib.mapAttrsToList (n: v: "-o ${n}=${v}") config.options)} \
${lib.concatStringsSep " " (lib.mapAttrsToList (n: v: "-O ${n}=${v}") config.rootFsOptions)} \ ${lib.concatStringsSep " " (lib.mapAttrsToList (n: v: "-O ${n}=${v}") config.rootFsOptions)} \
"''${zfs_devices[@]}" "''${zfs_devices[@]}"
@ -70,7 +81,8 @@
in in
{ {
dev = '' dev = ''
zpool list '${config.name}' >/dev/null 2>/dev/null || zpool import '${config.name}' zpool list '${config.name}' >/dev/null 2>/dev/null || \
zpool import -R ${config.mountRoot} '${config.name}'
${lib.concatMapStrings (x: x.dev or "") (lib.attrValues datasetMounts)} ${lib.concatMapStrings (x: x.dev or "") (lib.attrValues datasetMounts)}
''; '';
fs = (datasetMounts.fs or {}) // lib.optionalAttrs (config.mountpoint != null) { fs = (datasetMounts.fs or {}) // lib.optionalAttrs (config.mountpoint != null) {