From e78e5b1da74969f7244bec70e8582bb3eba96d86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Thu, 20 Apr 2023 23:42:18 +0200 Subject: [PATCH] zpool: add option to mount zpool not at / --- types/zpool.nix | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/types/zpool.nix b/types/zpool.nix index 4c70bd6..b415bd5 100644 --- a/types/zpool.nix +++ b/types/zpool.nix @@ -37,6 +37,17 @@ default = [ "defaults" ]; 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 { type = lib.types.attrsOf (diskoLib.subType { inherit (subTypes) zfs_fs zfs_volume; }); # type = lib.types.attrsOf subTypes.zfs_fs; @@ -55,7 +66,7 @@ default = _: '' readarray -t zfs_devices < <(cat "$disko_devices_dir"/zfs_${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.rootFsOptions)} \ "''${zfs_devices[@]}" @@ -70,7 +81,8 @@ in { 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)} ''; fs = (datasetMounts.fs or {}) // lib.optionalAttrs (config.mountpoint != null) {