support zfs over legacy fs

This commit is contained in:
lassulus 2022-08-26 12:50:52 +02:00
parent 722dde361c
commit 9bb4aec964
3 changed files with 65 additions and 13 deletions

View File

@ -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;

View File

@ -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";
}
];
};
};
}

12
tests/zfs-over-legacy.nix Normal file
View File

@ -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");
'';
}