From 1237ac36db1a457ae561134d191d2924a9ce5ffc Mon Sep 17 00:00:00 2001 From: lassulus Date: Thu, 25 Aug 2022 13:13:20 +0200 Subject: fix mdadm mounting, move test to mdadm test --- default.nix | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'default.nix') diff --git a/default.nix b/default.nix index d20b67e..567324c 100644 --- a/default.nix +++ b/default.nix @@ -137,7 +137,7 @@ let }; mount.devices = q: x: let - z = foldl' recursiveUpdate {} (mapAttrsToList (name: mount-f { device = "/dev/${name}"; }) x.content); + z = foldl' recursiveUpdate {} (mapAttrsToList (name: mount-f { device = "/dev/${name}"; inherit name; }) x.content); # attrValues returns values sorted by name. This is important, because it # ensures that "/" is processed before "/foo" etc. in '' @@ -168,8 +168,9 @@ let mount.noop = q: x: {}; + mount.mdadm = q: x: + mount-f { device = "/dev/md/${q.name}"; } x.content; # TODO maybe we need to do something here? - mount.mdadm = mount.noop; mount.mdraid = mount.noop; mount.partition = q: x: -- cgit v1.2.3 From dd99e29edc994056d5f700e24a75406115e98dff Mon Sep 17 00:00:00 2001 From: lassulus Date: Thu, 25 Aug 2022 13:14:07 +0200 Subject: fix cryptsetup luksOpen idempotency, add luks-lvm test --- default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'default.nix') diff --git a/default.nix b/default.nix index 567324c..39e455a 100644 --- a/default.nix +++ b/default.nix @@ -151,7 +151,7 @@ let recursiveUpdate (mount-f { device = "/dev/mapper/${x.name}"; } x.content) {luks.${q.device} = '' - cryptsetup luksOpen ${q.device} ${x.name} ${if builtins.hasAttr "keyfile" x then "--key-file " + x.keyfile else ""} + cryptsetup status ${x.name} >/dev/null 2>/dev/null || cryptsetup luksOpen ${q.device} ${x.name} ${if builtins.hasAttr "keyfile" x then "--key-file " + x.keyfile else ""} '';} ); -- cgit v1.2.3 From 83fb8f661eb574f32fad1d51bbebd0c36595db01 Mon Sep 17 00:00:00 2001 From: lassulus Date: Thu, 25 Aug 2022 15:08:26 +0200 Subject: add zfs support/test/example --- default.nix | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 62 insertions(+), 3 deletions(-) (limited to 'default.nix') diff --git a/default.nix b/default.nix index 39e455a..4a9a033 100644 --- a/default.nix +++ b/default.nix @@ -38,6 +38,13 @@ let }; }; + config.zfs_filesystem = q: x: { + fileSystems.${x.mountpoint} = { + device = q.device; + fsType = "zfs"; + }; + }; + config.devices = q: x: foldl' recursiveUpdate {} (mapAttrsToList (name: config-f { device = "/dev/${name}"; }) x.content); @@ -67,8 +74,8 @@ let ''; create.devices = q: x: let - raid-devices = lib.filterAttrs (_: dev: dev.type == "mdadm") x.content; - other-devices = lib.filterAttrs (_: dev: dev.type != "mdadm") x.content; + raid-devices = lib.filterAttrs (_: dev: dev.type == "mdadm" || dev.type == "zpool") x.content; + other-devices = lib.filterAttrs (_: dev: dev.type != "mdadm" && dev.type != "zpool") x.content; in '' ${concatStrings (mapAttrsToList (name: create-f { device = "/dev/${name}"; }) other-devices)} ${concatStrings (mapAttrsToList (name: create-f { device = "/dev/${name}"; name = name; }) raid-devices)} @@ -125,6 +132,32 @@ let ${concatStrings (imap (index: create-f (q // { inherit index; })) x.partitions)} ''; + create.zfs = q: x: '' + ZFSDEVICES_${x.pool}="''${ZFSDEVICES_${x.pool}:-}${q.device} " + ''; + + create.zfs_filesystem = q: x: '' + zfs create ${q.pool}/${x.name} \ + ${lib.optionalString (isAttrs x.options or null) (concatStringsSep " " (mapAttrsToList (n: v: "-o ${n}=${v}") x.options))} + ''; + + create.zfs_volume = q: x: '' + zfs create ${q.pool}/${x.name} \ + -V ${x.size} \ + ${lib.optionalString (isAttrs x.options or null) (concatStringsSep " " (mapAttrsToList (n: v: "-o ${n}=${v}") x.options))} + udevadm trigger --subsystem-match=block; udevadm settle + ${create-f { device = "/dev/zvol/${q.pool}/${x.name}"; } x.content} + ''; + + create.zpool = q: x: '' + zpool create ${q.name} \ + ${lib.optionalString (!isNull x.mode || 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}} + ${concatMapStrings (create-f (q // { pool = q.name; })) x.datasets} + ''; + mount-f = q: x: mount.${x.type} q x; @@ -144,6 +177,8 @@ let ${optionalString (hasAttr "table" z) (concatStringsSep "\n" (attrValues z.table))} ${optionalString (hasAttr "luks" z) (concatStringsSep "\n" (attrValues z.luks))} ${optionalString (hasAttr "lvm" z) (concatStringsSep "\n" (attrValues z.lvm))} + ${optionalString (hasAttr "zpool" z) (concatStringsSep "\n" (attrValues z.zpool))} + ${optionalString (hasAttr "zfs" z) (concatStringsSep "\n" (attrValues z.zfs))} ${optionalString (hasAttr "fs" z) (concatStringsSep "\n" (attrValues z.fs))} ''; @@ -170,7 +205,6 @@ let mount.mdadm = q: x: mount-f { device = "/dev/md/${q.name}"; } x.content; - # TODO maybe we need to do something here? mount.mdraid = mount.noop; mount.partition = q: x: @@ -181,6 +215,31 @@ let (foldl' recursiveUpdate {} (imap (index: mount-f (q // { inherit index; device = helper.device-id q.device; })) x.partitions)) {table.${q.device} = helper.find-device q.device;} ); + + mount.zfs = mount.noop; + + mount.zpool = q: x: ( + recursiveUpdate + (foldl' recursiveUpdate {} (map (mount-f (q // { pool = q.name; })) x.datasets)) + {zpool.${q.device} = '' + zpool list '${q.name}' >/dev/null 2>/dev/null || zpool import '${q.name}' + '';} + ); + + mount.zfs_filesystem = q: x: { + zfs.${x.mountpoint} = '' + if ! findmnt '${q.pool}/${x.name}' /mnt${x.mountpoint} > /dev/null 2>&1; then + mount \ + ${lib.optionalString ((x.options.mountpoint or "") != "legacy") "-o zfsutil"} \ + -t zfs ${q.pool}/${x.name} /mnt${x.mountpoint} \ + -o X-mount.mkdir + fi + ''; + }; + + mount.zfs_volume = q: x: + mount-f { device = "/dev/zvol/${q.pool}/${x.name}"; } x.content; + in { config = config-f {}; create = cfg: '' -- cgit v1.2.3 From dadc49133042834dada6eafc98dcb1f7f2c5e43b Mon Sep 17 00:00:00 2001 From: lassulus Date: Thu, 25 Aug 2022 18:36:56 +0200 Subject: add lvm raid --- default.nix | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) (limited to 'default.nix') diff --git a/default.nix b/default.nix index 4a9a033..19333fc 100644 --- a/default.nix +++ b/default.nix @@ -52,10 +52,10 @@ let boot.initrd.luks.devices.${x.name}.device = q.device; } // config-f { device = "/dev/mapper/${x.name}"; } x.content; - config.lv = q: x: - config-f { device = "/dev/mapper/${q.vgname}-${q.name}"; } x.content; + config.lvm_lv = q: x: + config-f { device = "/dev/${q.vgname}/${q.name}"; } x.content; - config.lvm = q: x: + config.lvm_vg = q: x: foldl' recursiveUpdate {} (mapAttrsToList (name: config-f { inherit name; vgname = x.name; }) x.lvs); config.noop = q: x: {}; @@ -74,8 +74,8 @@ let ''; create.devices = q: x: let - raid-devices = lib.filterAttrs (_: dev: dev.type == "mdadm" || dev.type == "zpool") x.content; - other-devices = lib.filterAttrs (_: dev: dev.type != "mdadm" && dev.type != "zpool") x.content; + raid-devices = lib.filterAttrs (_: dev: dev.type == "mdadm" || dev.type == "zpool" || dev.type == "lvm_vg") x.content; + other-devices = lib.filterAttrs (_: dev: dev.type != "mdadm" && dev.type != "zpool" && dev.type != "lvm_vg") x.content; in '' ${concatStrings (mapAttrsToList (name: create-f { device = "/dev/${name}"; }) other-devices)} ${concatStrings (mapAttrsToList (name: create-f { device = "/dev/${name}"; name = name; }) raid-devices)} @@ -98,15 +98,24 @@ let ${create-f { device = "/dev/mapper/${x.name}"; } x.content} ''; - create.lv = q: x: '' - lvcreate ${if hasInfix "%" x.size then "-l" else "-L"} ${x.size} -n ${q.name} ${q.vgname} - ${create-f { device = "/dev/mapper/${q.vgname}-${q.name}"; } x.content} + create.lvm_pv = q: x: '' + pvcreate ${q.device} + LVMDEVICES_${x.vg}="''${LVMDEVICES_${x.vg}:-}${q.device} " ''; - create.lvm = q: x: '' - pvcreate ${q.device} - vgcreate ${x.name} ${q.device} - ${concatStrings (mapAttrsToList (name: create-f { inherit name; vgname = x.name; }) x.lvs)} + create.lvm_lv = q: x: '' + lvcreate \ + ${if hasInfix "%" x.size then "-l" else "-L"} ${x.size} \ + -n ${q.name} \ + ${lib.optionalString (!isNull x.lvm_type or null) "--type=${x.lvm_type}"} \ + ${lib.optionalString (!isNull x.extraArgs or null) x.extraArgs} \ + ${q.vgname} + ${create-f { device = "/dev/${q.vgname}/${q.name}"; } x.content} + ''; + + create.lvm_vg = q: x: '' + vgcreate ${q.name} $LVMDEVICES_${q.name} + ${concatStrings (mapAttrsToList (name: create-f { inherit name; vgname = q.name; }) x.lvs)} ''; create.noop = q: x: ""; @@ -190,17 +199,19 @@ let '';} ); - mount.lv = q: x: - mount-f { device = "/dev/mapper/${q.vgname}-${q.name}"; } x.content; + mount.lvm_lv = q: x: + mount-f { device = "/dev/${q.vgname}/${q.name}"; } x.content; - mount.lvm = q: x: ( + mount.lvm_vg = q: x: ( recursiveUpdate - (foldl' recursiveUpdate {} (mapAttrsToList (name: mount-f { inherit name; vgname = x.name; }) x.lvs)) + (foldl' recursiveUpdate {} (mapAttrsToList (name: mount-f { inherit name; vgname = q.name; }) x.lvs)) {lvm.${q.device} = '' vgchange -a y '';} ); + mount.lvm_pv = mount.noop; + mount.noop = q: x: {}; mount.mdadm = q: x: -- cgit v1.2.3 From 81e704b638a8a7158bd9106b7fd592fb982d1864 Mon Sep 17 00:00:00 2001 From: lassulus Date: Thu, 25 Aug 2022 21:46:17 +0200 Subject: add btrfs subvolumes --- default.nix | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'default.nix') diff --git a/default.nix b/default.nix index 19333fc..c6ec47c 100644 --- a/default.nix +++ b/default.nix @@ -69,6 +69,18 @@ let create-f = q: x: create.${x.type} q x; + create.btrfs = q: x: '' + mkfs.btrfs ${q.device} + ${lib.optionalString (!isNull x.subvolumes or null) '' + MNTPOINT=$(mktemp -d) + ( + mount ${q.device} "$MNTPOINT" + trap 'umount $MNTPOINT; rm -rf $MNTPOINT' EXIT + ${concatMapStringsSep "\n" (subvolume: "btrfs subvolume create \"$MNTPOINT\"/${subvolume}") x.subvolumes} + ) + ''} + ''; + create.filesystem = q: x: '' mkfs.${x.format} ${q.device} ''; @@ -178,6 +190,8 @@ let ''; }; + mount.btrfs = mount.filesystem; + mount.devices = q: x: let z = foldl' recursiveUpdate {} (mapAttrsToList (name: mount-f { device = "/dev/${name}"; inherit name; }) x.content); # attrValues returns values sorted by name. This is important, because it -- cgit v1.2.3 From e4836108d51a4339983c0f88fb4e995e4109bb21 Mon Sep 17 00:00:00 2001 From: lassulus Date: Thu, 25 Aug 2022 21:46:48 +0200 Subject: create.filesystem: support extraArgs --- default.nix | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'default.nix') diff --git a/default.nix b/default.nix index c6ec47c..d98e8d6 100644 --- a/default.nix +++ b/default.nix @@ -82,7 +82,9 @@ let ''; create.filesystem = q: x: '' - mkfs.${x.format} ${q.device} + mkfs.${x.format} \ + ${lib.optionalString (!isNull x.extraArgs or null) x.extraArgs} \ + ${q.device} ''; create.devices = q: x: let -- cgit v1.2.3 From 69f1337980756fe4ac001cadce7760e7b06c75da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Fri, 26 Aug 2022 08:41:58 +0200 Subject: fix inconsistent indentation with nixpkgs-fmt --- default.nix | 160 +++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 87 insertions(+), 73 deletions(-) (limited to 'default.nix') diff --git a/default.nix b/default.nix index d98e8d6..ac84345 100644 --- a/default.nix +++ b/default.nix @@ -4,12 +4,13 @@ with builtins; let - helper.find-device = device: let - environment = helper.device-id device; - in + helper.find-device = device: + let + environment = helper.device-id device; + in # DEVICE points already to /dev/disk, so we don't handle it via /dev/disk/by-path if hasPrefix "/dev/disk" device then - "${environment}='${device}'" + "${environment}='${device}'" else '' ${environment}=$(for x in $(find /dev/disk/{by-path,by-id}/); do dev=$x @@ -46,7 +47,7 @@ let }; config.devices = q: x: - foldl' recursiveUpdate {} (mapAttrsToList (name: config-f { device = "/dev/${name}"; }) x.content); + foldl' recursiveUpdate { } (mapAttrsToList (name: config-f { device = "/dev/${name}"; }) x.content); config.luks = q: x: { boot.initrd.luks.devices.${x.name}.device = q.device; @@ -56,15 +57,15 @@ let config-f { device = "/dev/${q.vgname}/${q.name}"; } x.content; config.lvm_vg = q: x: - foldl' recursiveUpdate {} (mapAttrsToList (name: config-f { inherit name; vgname = x.name; }) x.lvs); + foldl' recursiveUpdate { } (mapAttrsToList (name: config-f { inherit name; vgname = x.name; }) x.lvs); - config.noop = q: x: {}; + config.noop = q: x: { }; config.partition = q: x: config-f { device = q.device + toString q.index; } x.content; config.table = q: x: - foldl' recursiveUpdate {} (imap (index: config-f (q // { inherit index; })) x.partitions); + foldl' recursiveUpdate { } (imap (index: config-f (q // { inherit index; })) x.partitions); create-f = q: x: create.${x.type} q x; @@ -87,13 +88,15 @@ let ${q.device} ''; - create.devices = q: x: let - raid-devices = lib.filterAttrs (_: dev: dev.type == "mdadm" || dev.type == "zpool" || dev.type == "lvm_vg") x.content; - other-devices = lib.filterAttrs (_: dev: dev.type != "mdadm" && dev.type != "zpool" && dev.type != "lvm_vg") x.content; - in '' - ${concatStrings (mapAttrsToList (name: create-f { device = "/dev/${name}"; }) other-devices)} - ${concatStrings (mapAttrsToList (name: create-f { device = "/dev/${name}"; name = name; }) raid-devices)} - ''; + create.devices = q: x: + let + raid-devices = lib.filterAttrs (_: dev: dev.type == "mdadm" || dev.type == "zpool" || dev.type == "lvm_vg") x.content; + other-devices = lib.filterAttrs (_: dev: dev.type != "mdadm" && dev.type != "zpool" && dev.type != "lvm_vg") x.content; + in + '' + ${concatStrings (mapAttrsToList (name: create-f { device = "/dev/${name}"; }) other-devices)} + ${concatStrings (mapAttrsToList (name: create-f { device = "/dev/${name}"; name = name; }) raid-devices)} + ''; create.mdraid = q: x: '' RAIDDEVICES_N_${x.name}=$((''${RAIDDEVICES_N_${x.name}:-0}+1)) @@ -134,20 +137,22 @@ let create.noop = q: x: ""; - create.partition = q: x: let - env = helper.device-id q.device; - in '' - parted -s "''${${env}}" mkpart ${x.part-type} ${x.fs-type or ""} ${x.start} ${x.end} - # ensure /dev/disk/by-path/..-partN exists before continuing - udevadm trigger --subsystem-match=block; udevadm settle - ${optionalString (x.bootable or false) '' - parted -s "''${${env}}" set ${toString q.index} boot on - ''} - ${concatMapStringsSep "" (flag: '' - parted -s "''${${env}}" set ${toString q.index} ${flag} on - '') (x.flags or [])} - ${create-f { device = "\"\${${env}}\"-part" + toString q.index; } x.content} - ''; + create.partition = q: x: + let + env = helper.device-id q.device; + in + '' + parted -s "''${${env}}" mkpart ${x.part-type} ${x.fs-type or ""} ${x.start} ${x.end} + # ensure /dev/disk/by-path/..-partN exists before continuing + udevadm trigger --subsystem-match=block; udevadm settle + ${optionalString (x.bootable or false) '' + parted -s "''${${env}}" set ${toString q.index} boot on + ''} + ${concatMapStringsSep "" (flag: '' + parted -s "''${${env}}" set ${toString q.index} ${flag} on + '') (x.flags or [])} + ${create-f { device = "\"\${${env}}\"-part" + toString q.index; } x.content} + ''; create.table = q: x: '' ${helper.find-device q.device} @@ -185,34 +190,38 @@ let mount-f = q: x: mount.${x.type} q x; 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 - fi - ''; - }; + 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 + fi + ''; + }; mount.btrfs = mount.filesystem; - mount.devices = q: x: let - z = foldl' recursiveUpdate {} (mapAttrsToList (name: mount-f { device = "/dev/${name}"; inherit name; }) x.content); - # attrValues returns values sorted by name. This is important, because it - # ensures that "/" is processed before "/foo" etc. - in '' - ${optionalString (hasAttr "table" z) (concatStringsSep "\n" (attrValues z.table))} - ${optionalString (hasAttr "luks" z) (concatStringsSep "\n" (attrValues z.luks))} - ${optionalString (hasAttr "lvm" z) (concatStringsSep "\n" (attrValues z.lvm))} - ${optionalString (hasAttr "zpool" z) (concatStringsSep "\n" (attrValues z.zpool))} - ${optionalString (hasAttr "zfs" z) (concatStringsSep "\n" (attrValues z.zfs))} - ${optionalString (hasAttr "fs" z) (concatStringsSep "\n" (attrValues z.fs))} - ''; + mount.devices = q: x: + let + z = foldl' recursiveUpdate { } (mapAttrsToList (name: mount-f { device = "/dev/${name}"; inherit name; }) x.content); + # attrValues returns values sorted by name. This is important, because it + # ensures that "/" is processed before "/foo" etc. + in + '' + ${optionalString (hasAttr "table" z) (concatStringsSep "\n" (attrValues z.table))} + ${optionalString (hasAttr "luks" z) (concatStringsSep "\n" (attrValues z.luks))} + ${optionalString (hasAttr "lvm" z) (concatStringsSep "\n" (attrValues z.lvm))} + ${optionalString (hasAttr "zpool" z) (concatStringsSep "\n" (attrValues z.zpool))} + ${optionalString (hasAttr "zfs" z) (concatStringsSep "\n" (attrValues z.zfs))} + ${optionalString (hasAttr "fs" z) (concatStringsSep "\n" (attrValues z.fs))} + ''; mount.luks = q: x: ( recursiveUpdate - (mount-f { device = "/dev/mapper/${x.name}"; } x.content) - {luks.${q.device} = '' - cryptsetup status ${x.name} >/dev/null 2>/dev/null || cryptsetup luksOpen ${q.device} ${x.name} ${if builtins.hasAttr "keyfile" x then "--key-file " + x.keyfile else ""} - '';} + (mount-f { device = "/dev/mapper/${x.name}"; } x.content) + { + luks.${q.device} = '' + cryptsetup status ${x.name} >/dev/null 2>/dev/null || cryptsetup luksOpen ${q.device} ${x.name} ${if builtins.hasAttr "keyfile" x then "--key-file " + x.keyfile else ""} + ''; + } ); mount.lvm_lv = q: x: @@ -220,15 +229,17 @@ let mount.lvm_vg = q: x: ( recursiveUpdate - (foldl' recursiveUpdate {} (mapAttrsToList (name: mount-f { inherit name; vgname = q.name; }) x.lvs)) - {lvm.${q.device} = '' - vgchange -a y - '';} + (foldl' recursiveUpdate { } (mapAttrsToList (name: mount-f { inherit name; vgname = q.name; }) x.lvs)) + { + lvm.${q.device} = '' + vgchange -a y + ''; + } ); mount.lvm_pv = mount.noop; - mount.noop = q: x: {}; + mount.noop = q: x: { }; mount.mdadm = q: x: mount-f { device = "/dev/md/${q.name}"; } x.content; @@ -239,36 +250,39 @@ let mount.table = q: x: ( recursiveUpdate - (foldl' recursiveUpdate {} (imap (index: mount-f (q // { inherit index; device = helper.device-id q.device; })) x.partitions)) - {table.${q.device} = helper.find-device q.device;} + (foldl' recursiveUpdate { } (imap (index: mount-f (q // { inherit index; device = helper.device-id q.device; })) x.partitions)) + { table.${q.device} = helper.find-device q.device; } ); mount.zfs = mount.noop; mount.zpool = q: x: ( recursiveUpdate - (foldl' recursiveUpdate {} (map (mount-f (q // { pool = q.name; })) x.datasets)) - {zpool.${q.device} = '' - zpool list '${q.name}' >/dev/null 2>/dev/null || zpool import '${q.name}' - '';} + (foldl' recursiveUpdate { } (map (mount-f (q // { pool = q.name; })) x.datasets)) + { + zpool.${q.device} = '' + zpool list '${q.name}' >/dev/null 2>/dev/null || zpool import '${q.name}' + ''; + } ); mount.zfs_filesystem = q: x: { - zfs.${x.mountpoint} = '' - if ! findmnt '${q.pool}/${x.name}' /mnt${x.mountpoint} > /dev/null 2>&1; then - mount \ - ${lib.optionalString ((x.options.mountpoint or "") != "legacy") "-o zfsutil"} \ - -t zfs ${q.pool}/${x.name} /mnt${x.mountpoint} \ - -o X-mount.mkdir - fi - ''; - }; + zfs.${x.mountpoint} = '' + if ! findmnt '${q.pool}/${x.name}' /mnt${x.mountpoint} > /dev/null 2>&1; then + mount \ + ${lib.optionalString ((x.options.mountpoint or "") != "legacy") "-o zfsutil"} \ + -t zfs ${q.pool}/${x.name} /mnt${x.mountpoint} \ + -o X-mount.mkdir + fi + ''; + }; mount.zfs_volume = q: x: mount-f { device = "/dev/zvol/${q.pool}/${x.name}"; } x.content; -in { - config = config-f {}; +in +{ + config = config-f { }; create = cfg: '' set -efux ${create-f {} cfg} -- cgit v1.2.3 From 722dde361ca51864fd9b3b6b9a78875e436fbc24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Fri, 26 Aug 2022 10:28:07 +0200 Subject: zfs: support for root dataset mountpoint and mountpoint=none --- default.nix | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) (limited to 'default.nix') diff --git a/default.nix b/default.nix index ac84345..1865d69 100644 --- a/default.nix +++ b/default.nix @@ -256,29 +256,48 @@ let mount.zfs = mount.noop; - mount.zpool = q: x: ( + mount.zpool = q: x: + let + datasets = [{ + inherit (q) name; + type = "zfs_filesystem"; + dataset = q.name; + mountpoint = x.mountpoint or "/${q.name}"; + options = q.rootFsOptions or { }; + }] ++ x.datasets; + in recursiveUpdate - (foldl' recursiveUpdate { } (map (mount-f (q // { pool = q.name; })) x.datasets)) + (foldl' recursiveUpdate { } + ( + (map + (x: mount-f + ({ + dataset = x.dataset or "${q.name}/${x.name}"; + mountpoint = x.mountpoint or "/${q.name}/${x.name}"; + } // q) + x) + datasets) + ) + ) { zpool.${q.device} = '' zpool list '${q.name}' >/dev/null 2>/dev/null || zpool import '${q.name}' ''; - } - ); + }; mount.zfs_filesystem = q: x: { - zfs.${x.mountpoint} = '' - if ! findmnt '${q.pool}/${x.name}' /mnt${x.mountpoint} > /dev/null 2>&1; then + 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.pool}/${x.name} /mnt${x.mountpoint} \ + -t zfs ${q.dataset} /mnt${q.mountpoint} \ -o X-mount.mkdir fi ''; }; mount.zfs_volume = q: x: - mount-f { device = "/dev/zvol/${q.pool}/${x.name}"; } x.content; + mount-f { device = "/dev/zvol/${q.dataset}"; } x.content; in { -- cgit v1.2.3 From 9bb4aec9640cbc30e241c267158e506278862b5e Mon Sep 17 00:00:00 2001 From: lassulus Date: Fri, 26 Aug 2022 12:50:52 +0200 Subject: support zfs over legacy fs --- default.nix | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) (limited to 'default.nix') 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; -- cgit v1.2.3