summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlassulus <lassulus@lassul.us>2022-08-26 12:50:52 +0200
committerlassulus <lassulus@lassul.us>2022-08-26 12:55:50 +0200
commit9bb4aec9640cbc30e241c267158e506278862b5e (patch)
treec6057a3d362e06742073b35d4c11db7ee9a0a820
parent722dde361ca51864fd9b3b6b9a78875e436fbc24 (diff)
support zfs over legacy fs
-rw-r--r--default.nix24
-rw-r--r--example/zfs-over-legacy.nix42
-rw-r--r--tests/zfs-over-legacy.nix12
3 files changed, 65 insertions, 13 deletions
diff --git a/default.nix b/default.nix
index 1865d69..51b70f5 100644
--- a/default.nix
+++ b/default.nix
@@ -179,7 +179,7 @@ let
create.zpool = q: x: ''
zpool create ${q.name} \
- ${lib.optionalString (!isNull x.mode || x.mode != "stripe") x.mode} \
+ ${lib.optionalString (!isNull (x.mode or null) && x.mode != "stripe") x.mode} \
${lib.optionalString (isAttrs x.options or null) (concatStringsSep " " (mapAttrsToList (n: v: "-o ${n}=${v}") x.options))} \
${lib.optionalString (isAttrs x.rootFsOptions or null) (concatStringsSep " " (mapAttrsToList (n: v: "-O ${n}=${v}") x.rootFsOptions))} \
''${ZFSDEVICES_${q.name}}
@@ -192,11 +192,20 @@ let
mount.filesystem = q: x: {
fs.${x.mountpoint} = ''
if ! findmnt ${q.device} "/mnt${x.mountpoint}" > /dev/null 2>&1; then
- mount ${q.device} "/mnt${x.mountpoint}" -o X-mount.mkdir
+ mount ${q.device} "/mnt${x.mountpoint}" \
+ -o X-mount.mkdir \
+ ${lib.optionalString (isList x.mountOptions or null) (concatStringsSep " " x.mountOptions)}
fi
'';
};
+ mount.zfs_filesystem = q: x:
+ optionalAttrs ((x.options.mountpoint or "") != "none")
+ (mount.filesystem (q // { device = q.dataset; }) (x // { mountOptions = [
+ (lib.optionalString ((x.options.mountpoint or "") != "legacy") "-o zfsutil")
+ "-t zfs"
+ ]; }));
+
mount.btrfs = mount.filesystem;
mount.devices = q: x:
@@ -285,17 +294,6 @@ let
'';
};
- mount.zfs_filesystem = q: x: {
- zfs.${q.mountpoint} = lib.optionalString ((x.options.mountpoint or "") != "none") ''
- if ! findmnt '${q.dataset}' /mnt${q.mountpoint} > /dev/null 2>&1; then
- mount \
- ${lib.optionalString ((x.options.mountpoint or "") != "legacy") "-o zfsutil"} \
- -t zfs ${q.dataset} /mnt${q.mountpoint} \
- -o X-mount.mkdir
- fi
- '';
- };
-
mount.zfs_volume = q: x:
mount-f { device = "/dev/zvol/${q.dataset}"; } x.content;
diff --git a/example/zfs-over-legacy.nix b/example/zfs-over-legacy.nix
new file mode 100644
index 0000000..8f5a8bc
--- /dev/null
+++ b/example/zfs-over-legacy.nix
@@ -0,0 +1,42 @@
+{
+ type = "devices";
+ content = {
+ vdb = {
+ type = "table";
+ format = "gpt";
+ partitions = [
+ {
+ type = "partition";
+ # leave space for the grub aka BIOS boot
+ start = "0%";
+ end = "100%";
+ part-type = "primary";
+ bootable = true;
+ content = {
+ type = "filesystem";
+ format = "ext4";
+ mountpoint = "/";
+ };
+ }
+ ];
+ };
+ vdc = {
+ type = "zfs";
+ pool = "zroot";
+ };
+ zroot = {
+ type = "zpool";
+ mountpoint = "/";
+
+ datasets = [
+ {
+ type = "zfs_filesystem";
+ name = "zfs_fs";
+ mountpoint = "/zfs_fs";
+ options."com.sun:auto-snapshot" = "true";
+ }
+ ];
+ };
+ };
+}
+
diff --git a/tests/zfs-over-legacy.nix b/tests/zfs-over-legacy.nix
new file mode 100644
index 0000000..13f86a9
--- /dev/null
+++ b/tests/zfs-over-legacy.nix
@@ -0,0 +1,12 @@
+{ pkgs ? (import <nixpkgs> { })
+, makeDiskoTest ? (pkgs.callPackage ./lib.nix { }).makeDiskoTest
+}:
+makeDiskoTest {
+ disko-config = import ../example/zfs-over-legacy.nix;
+ extraTestScript = ''
+ machine.succeed("test -e /mnt/zfs_fs");
+ machine.succeed("mountpoint /mnt");
+ machine.succeed("mountpoint /mnt/zfs_fs");
+ '';
+}
+