mirror of
https://github.com/TECHNOFAB11/disko.git
synced 2025-12-11 23:50:05 +01:00
types: split zfs_dataset into zfs_fs & zfs_volume
This commit is contained in:
parent
654ecb386e
commit
7d70009c26
7 changed files with 100 additions and 46 deletions
|
|
@ -163,21 +163,21 @@
|
||||||
|
|
||||||
datasets = {
|
datasets = {
|
||||||
zfs_fs = {
|
zfs_fs = {
|
||||||
zfs_type = "filesystem";
|
type = "zfs_fs";
|
||||||
mountpoint = "/zfs_fs";
|
mountpoint = "/zfs_fs";
|
||||||
options."com.sun:auto-snapshot" = "true";
|
options."com.sun:auto-snapshot" = "true";
|
||||||
};
|
};
|
||||||
zfs_unmounted_fs = {
|
zfs_unmounted_fs = {
|
||||||
zfs_type = "filesystem";
|
type = "zfs_fs";
|
||||||
options.mountpoint = "none";
|
options.mountpoint = "none";
|
||||||
};
|
};
|
||||||
zfs_legacy_fs = {
|
zfs_legacy_fs = {
|
||||||
zfs_type = "filesystem";
|
type = "zfs_fs";
|
||||||
options.mountpoint = "legacy";
|
options.mountpoint = "legacy";
|
||||||
mountpoint = "/zfs_legacy_fs";
|
mountpoint = "/zfs_legacy_fs";
|
||||||
};
|
};
|
||||||
zfs_testvolume = {
|
zfs_testvolume = {
|
||||||
zfs_type = "volume";
|
type = "zfs_volume";
|
||||||
size = "10M";
|
size = "10M";
|
||||||
content = {
|
content = {
|
||||||
type = "filesystem";
|
type = "filesystem";
|
||||||
|
|
|
||||||
|
|
@ -50,11 +50,11 @@
|
||||||
type = "zpool";
|
type = "zpool";
|
||||||
datasets = {
|
datasets = {
|
||||||
"root" = {
|
"root" = {
|
||||||
zfs_type = "filesystem";
|
type = "zfs_fs";
|
||||||
options.mountpoint = "none";
|
options.mountpoint = "none";
|
||||||
};
|
};
|
||||||
"root/zfs_fs" = {
|
"root/zfs_fs" = {
|
||||||
zfs_type = "filesystem";
|
type = "zfs_fs";
|
||||||
mountpoint = "/zfs_fs";
|
mountpoint = "/zfs_fs";
|
||||||
options."com.sun:auto-snapshot" = "true";
|
options."com.sun:auto-snapshot" = "true";
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -64,21 +64,21 @@
|
||||||
|
|
||||||
datasets = {
|
datasets = {
|
||||||
zfs_fs = {
|
zfs_fs = {
|
||||||
zfs_type = "filesystem";
|
type = "zfs_fs";
|
||||||
mountpoint = "/zfs_fs";
|
mountpoint = "/zfs_fs";
|
||||||
options."com.sun:auto-snapshot" = "true";
|
options."com.sun:auto-snapshot" = "true";
|
||||||
};
|
};
|
||||||
zfs_unmounted_fs = {
|
zfs_unmounted_fs = {
|
||||||
zfs_type = "filesystem";
|
type = "zfs_fs";
|
||||||
options.mountpoint = "none";
|
options.mountpoint = "none";
|
||||||
};
|
};
|
||||||
zfs_legacy_fs = {
|
zfs_legacy_fs = {
|
||||||
zfs_type = "filesystem";
|
type = "zfs_fs";
|
||||||
options.mountpoint = "legacy";
|
options.mountpoint = "legacy";
|
||||||
mountpoint = "/zfs_legacy_fs";
|
mountpoint = "/zfs_legacy_fs";
|
||||||
};
|
};
|
||||||
zfs_testvolume = {
|
zfs_testvolume = {
|
||||||
zfs_type = "volume";
|
type = "zfs_volume";
|
||||||
size = "10M";
|
size = "10M";
|
||||||
content = {
|
content = {
|
||||||
type = "filesystem";
|
type = "filesystem";
|
||||||
|
|
@ -87,8 +87,7 @@
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
encrypted = {
|
encrypted = {
|
||||||
zfs_type = "filesystem";
|
type = "zfs_fs";
|
||||||
size = "20M";
|
|
||||||
options = {
|
options = {
|
||||||
mountpoint = "none";
|
mountpoint = "none";
|
||||||
encryption = "aes-256-gcm";
|
encryption = "aes-256-gcm";
|
||||||
|
|
@ -97,8 +96,7 @@
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
"encrypted/test" = {
|
"encrypted/test" = {
|
||||||
zfs_type = "filesystem";
|
type = "zfs_fs";
|
||||||
size = "2M";
|
|
||||||
mountpoint = "/zfs_crypted";
|
mountpoint = "/zfs_crypted";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -133,7 +133,7 @@ rec {
|
||||||
|| lib.hasSuffix "Hook" n
|
|| lib.hasSuffix "Hook" n
|
||||||
|| isAttrsOfSubmodule o
|
|| isAttrsOfSubmodule o
|
||||||
# TODO don't hardcode diskoLib.subType options.
|
# TODO don't hardcode diskoLib.subType options.
|
||||||
|| n == "content" || n == "partitions"
|
|| n == "content" || n == "partitions" || n == "datasets"
|
||||||
);
|
);
|
||||||
in
|
in
|
||||||
lib.toShellVars
|
lib.toShellVars
|
||||||
|
|
@ -348,6 +348,8 @@ rec {
|
||||||
zfs = ./zfs.nix;
|
zfs = ./zfs.nix;
|
||||||
zpool = ./zpool.nix;
|
zpool = ./zpool.nix;
|
||||||
zfs_dataset = ./zfs_dataset.nix;
|
zfs_dataset = ./zfs_dataset.nix;
|
||||||
|
zfs_fs = ./zfs_fs.nix;
|
||||||
|
zfs_volume = ./zfs_volume.nix;
|
||||||
mdadm = ./mdadm.nix;
|
mdadm = ./mdadm.nix;
|
||||||
mdraid = ./mdraid.nix;
|
mdraid = ./mdraid.nix;
|
||||||
luks = ./luks.nix;
|
luks = ./luks.nix;
|
||||||
|
|
|
||||||
|
|
@ -7,15 +7,11 @@
|
||||||
description = "Name of the dataset";
|
description = "Name of the dataset";
|
||||||
};
|
};
|
||||||
type = lib.mkOption {
|
type = lib.mkOption {
|
||||||
type = lib.types.enum [ "zfs_dataset" ];
|
type = lib.types.enum [ "zfs_fs" ];
|
||||||
default = "zfs_dataset";
|
default = "zfs_fs";
|
||||||
internal = true;
|
internal = true;
|
||||||
description = "Type";
|
description = "Type";
|
||||||
};
|
};
|
||||||
zfs_type = lib.mkOption {
|
|
||||||
type = lib.types.enum [ "filesystem" "volume" ];
|
|
||||||
description = "The type of the dataset";
|
|
||||||
};
|
|
||||||
options = lib.mkOption {
|
options = lib.mkOption {
|
||||||
type = lib.types.attrsOf lib.types.str;
|
type = lib.types.attrsOf lib.types.str;
|
||||||
default = { };
|
default = { };
|
||||||
|
|
@ -27,46 +23,30 @@
|
||||||
description = "Mount options";
|
description = "Mount options";
|
||||||
};
|
};
|
||||||
|
|
||||||
# filesystem options
|
|
||||||
mountpoint = lib.mkOption {
|
mountpoint = lib.mkOption {
|
||||||
type = lib.types.nullOr optionTypes.absolute-pathname;
|
type = lib.types.nullOr optionTypes.absolute-pathname;
|
||||||
default = null;
|
default = null;
|
||||||
description = "Path to mount the dataset to";
|
description = "Path to mount the dataset to";
|
||||||
};
|
};
|
||||||
|
|
||||||
# volume options
|
|
||||||
size = lib.mkOption {
|
|
||||||
type = lib.types.nullOr lib.types.str; # TODO size
|
|
||||||
default = null;
|
|
||||||
description = "Size of the dataset";
|
|
||||||
};
|
|
||||||
|
|
||||||
content = diskoLib.partitionType;
|
|
||||||
_meta = lib.mkOption {
|
_meta = lib.mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
type = lib.types.functionTo diskoLib.jsonType;
|
type = lib.types.functionTo diskoLib.jsonType;
|
||||||
default = dev:
|
default = dev: {};
|
||||||
lib.optionalAttrs (config.content != null) (config.content._meta dev);
|
|
||||||
description = "Metadata";
|
description = "Metadata";
|
||||||
};
|
};
|
||||||
_create = diskoLib.mkCreateOption {
|
_create = diskoLib.mkCreateOption {
|
||||||
inherit config options;
|
inherit config options;
|
||||||
default = { zpool }: ''
|
default = { zpool }: ''
|
||||||
zfs create ${zpool}/${config.name} \
|
zfs create ${zpool}/${config.name} \
|
||||||
${lib.concatStringsSep " " (lib.mapAttrsToList (n: v: "-o ${n}=${v}") config.options)} \
|
${lib.concatStringsSep " " (lib.mapAttrsToList (n: v: "-o ${n}=${v}") config.options)}
|
||||||
${lib.optionalString (config.zfs_type == "volume") "-V ${config.size}"}
|
|
||||||
${lib.optionalString (config.zfs_type == "volume") ''
|
|
||||||
udevadm trigger --subsystem-match=block; udevadm settle
|
|
||||||
${lib.optionalString (config.content != null) (config.content._create {dev = "/dev/zvol/${zpool}/${config.name}";})}
|
|
||||||
''}
|
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
_mount = diskoLib.mkMountOption {
|
_mount = diskoLib.mkMountOption {
|
||||||
inherit config options;
|
inherit config options;
|
||||||
default = { zpool }:
|
default = { zpool }:
|
||||||
lib.optionalAttrs (config.zfs_type == "volume" && config.content != null) (config.content._mount { dev = "/dev/zvol/${zpool}/${config.name}"; }) //
|
lib.optionalAttrs (config.options.mountpoint or "" != "none") {
|
||||||
lib.optionalAttrs (config.zfs_type == "filesystem" && config.options.mountpoint or "" != "none") {
|
|
||||||
fs.${config.mountpoint} = ''
|
fs.${config.mountpoint} = ''
|
||||||
if ! findmnt ${zpool}/${config.name} "${rootMountPoint}${config.mountpoint}" > /dev/null 2>&1; then
|
if ! findmnt ${zpool}/${config.name} "${rootMountPoint}${config.mountpoint}" > /dev/null 2>&1; then
|
||||||
mount ${zpool}/${config.name} "${rootMountPoint}${config.mountpoint}" \
|
mount ${zpool}/${config.name} "${rootMountPoint}${config.mountpoint}" \
|
||||||
|
|
@ -82,22 +62,22 @@
|
||||||
internal = true;
|
internal = true;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
default = zpool:
|
default = zpool:
|
||||||
(lib.optional (config.zfs_type == "volume" && config.content != null) (config.content._config "/dev/zvol/${zpool}/${config.name}")) ++
|
lib.optional (config.options.mountpoint or "" != "none") {
|
||||||
(lib.optional (config.zfs_type == "filesystem" && config.options.mountpoint or "" != "none") {
|
|
||||||
fileSystems.${config.mountpoint} = {
|
fileSystems.${config.mountpoint} = {
|
||||||
device = "${zpool}/${config.name}";
|
device = "${zpool}/${config.name}";
|
||||||
fsType = "zfs";
|
fsType = "zfs";
|
||||||
options = config.mountOptions ++ lib.optional ((config.options.mountpoint or "") != "legacy") "zfsutil";
|
options = config.mountOptions ++ lib.optional ((config.options.mountpoint or "") != "legacy") "zfsutil";
|
||||||
};
|
};
|
||||||
});
|
};
|
||||||
description = "NixOS configuration";
|
description = "NixOS configuration";
|
||||||
};
|
};
|
||||||
_pkgs = lib.mkOption {
|
_pkgs = lib.mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
type = lib.types.functionTo (lib.types.listOf lib.types.package);
|
type = lib.types.functionTo (lib.types.listOf lib.types.package);
|
||||||
default = pkgs: [ pkgs.util-linux ] ++ lib.optionals (config.content != null) (config.content._pkgs pkgs);
|
default = pkgs: [ pkgs.util-linux ];
|
||||||
description = "Packages";
|
description = "Packages";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
73
types/zfs_volume.nix
Normal file
73
types/zfs_volume.nix
Normal file
|
|
@ -0,0 +1,73 @@
|
||||||
|
{ config, options, lib, diskoLib, optionTypes, rootMountPoint, ... }:
|
||||||
|
{
|
||||||
|
options = {
|
||||||
|
name = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
default = config._module.args.name;
|
||||||
|
description = "Name of the dataset";
|
||||||
|
};
|
||||||
|
type = lib.mkOption {
|
||||||
|
type = lib.types.enum [ "zfs_volume" ];
|
||||||
|
default = "zfs_volume";
|
||||||
|
internal = true;
|
||||||
|
description = "Type";
|
||||||
|
};
|
||||||
|
options = lib.mkOption {
|
||||||
|
type = lib.types.attrsOf lib.types.str;
|
||||||
|
default = { };
|
||||||
|
description = "Options to set for the dataset";
|
||||||
|
};
|
||||||
|
mountOptions = lib.mkOption {
|
||||||
|
type = lib.types.listOf lib.types.str;
|
||||||
|
default = [ "defaults" ];
|
||||||
|
description = "Mount options";
|
||||||
|
};
|
||||||
|
|
||||||
|
# volume options
|
||||||
|
size = lib.mkOption {
|
||||||
|
type = lib.types.nullOr lib.types.str; # TODO size
|
||||||
|
default = null;
|
||||||
|
description = "Size of the dataset";
|
||||||
|
};
|
||||||
|
|
||||||
|
content = diskoLib.partitionType;
|
||||||
|
|
||||||
|
_meta = lib.mkOption {
|
||||||
|
internal = true;
|
||||||
|
readOnly = true;
|
||||||
|
type = lib.types.functionTo diskoLib.jsonType;
|
||||||
|
default = dev:
|
||||||
|
lib.optionalAttrs (config.content != null) (config.content._meta dev);
|
||||||
|
description = "Metadata";
|
||||||
|
};
|
||||||
|
_create = diskoLib.mkCreateOption {
|
||||||
|
inherit config options;
|
||||||
|
default = { zpool }: ''
|
||||||
|
zfs create ${zpool}/${config.name} \
|
||||||
|
${lib.concatStringsSep " " (lib.mapAttrsToList (n: v: "-o ${n}=${v}") config.options)} -V ${config.size}
|
||||||
|
udevadm trigger --subsystem-match=block; udevadm settle
|
||||||
|
${lib.optionalString (config.content != null) (config.content._create {dev = "/dev/zvol/${zpool}/${config.name}";})}
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
_mount = diskoLib.mkMountOption {
|
||||||
|
inherit config options;
|
||||||
|
default = { zpool }:
|
||||||
|
lib.optionalAttrs (config.content != null) (config.content._mount { dev = "/dev/zvol/${zpool}/${config.name}"; });
|
||||||
|
};
|
||||||
|
_config = lib.mkOption {
|
||||||
|
internal = true;
|
||||||
|
readOnly = true;
|
||||||
|
default = zpool:
|
||||||
|
lib.optional (config.content != null) (config.content._config "/dev/zvol/${zpool}/${config.name}");
|
||||||
|
description = "NixOS configuration";
|
||||||
|
};
|
||||||
|
_pkgs = lib.mkOption {
|
||||||
|
internal = true;
|
||||||
|
readOnly = true;
|
||||||
|
type = lib.types.functionTo (lib.types.listOf lib.types.package);
|
||||||
|
default = pkgs: [ pkgs.util-linux ] ++ lib.optionals (config.content != null) (config.content._pkgs pkgs);
|
||||||
|
description = "Packages";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -38,7 +38,8 @@
|
||||||
description = "Options to pass to mount";
|
description = "Options to pass to mount";
|
||||||
};
|
};
|
||||||
datasets = lib.mkOption {
|
datasets = lib.mkOption {
|
||||||
type = lib.types.attrsOf subTypes.zfs_dataset;
|
type = lib.types.attrsOf (diskoLib.subType { inherit (subTypes) zfs_fs zfs_volume; });
|
||||||
|
# type = lib.types.attrsOf subTypes.zfs_fs;
|
||||||
description = "List of datasets to define";
|
description = "List of datasets to define";
|
||||||
};
|
};
|
||||||
_meta = lib.mkOption {
|
_meta = lib.mkOption {
|
||||||
|
|
@ -72,7 +73,7 @@
|
||||||
zpool list '${config.name}' >/dev/null 2>/dev/null || zpool import '${config.name}'
|
zpool list '${config.name}' >/dev/null 2>/dev/null || zpool import '${config.name}'
|
||||||
${lib.concatMapStrings (x: x.dev or "") (lib.attrValues datasetMounts)}
|
${lib.concatMapStrings (x: x.dev or "") (lib.attrValues datasetMounts)}
|
||||||
'';
|
'';
|
||||||
fs = datasetMounts.fs // lib.optionalAttrs (config.mountpoint != null) {
|
fs = (datasetMounts.fs or {}) // lib.optionalAttrs (config.mountpoint != null) {
|
||||||
${config.mountpoint} = ''
|
${config.mountpoint} = ''
|
||||||
if ! findmnt ${config.name} "${rootMountPoint}${config.mountpoint}" > /dev/null 2>&1; then
|
if ! findmnt ${config.name} "${rootMountPoint}${config.mountpoint}" > /dev/null 2>&1; then
|
||||||
mount ${config.name} "${rootMountPoint}${config.mountpoint}" \
|
mount ${config.name} "${rootMountPoint}${config.mountpoint}" \
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue