From 49badf305f632132cfa70eac4058d06d44ef3c20 Mon Sep 17 00:00:00 2001 From: phaer Date: Wed, 28 Dec 2022 16:22:03 +0100 Subject: [PATCH 01/24] zpool: add optionsAfterCreate... Not sure about the best implementation here yet. I'd like to use disk encryption with ZFS and existing disko facilities work fine to set it up, but we obviously can't use keylocation=prompt during disko formatting. So unlocking fails on boot if the file referred to by keylocation isn't included in the initrd. Ideally I could use keylocation=file://tmp/disk.key during partitioning, but set keylocation=prompt right after that. example usage: ``` rpool = { type = "zpool"; mode = ""; options = { ashift = "12"; autotrim = "on"; }; optionsAfterCreate = { keylocation = "prompt"; }; rootFsOptions = { encryption = "on"; keylocation = "file:///tmp/disk.key"; keyformat = "passphrase"; compression = "zstd"; acltype = "posixacl"; mountpoint = "none"; canmount = "off"; xattr = "sa"; dnodesize = "auto"; normalization = "formD"; relatime = "on"; }; ``` --- types.nix | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/types.nix b/types.nix index ff87a6c..256d2f0 100644 --- a/types.nix +++ b/types.nix @@ -1118,6 +1118,10 @@ rec { default = {}; description = "Options for the ZFS pool"; }; + optionsAfterCreate = mkOption { + type = types.attrsOf types.str; + default = {}; + }; rootFsOptions = mkOption { type = types.attrsOf types.str; default = {}; @@ -1155,6 +1159,7 @@ rec { ${concatStringsSep " " (mapAttrsToList (n: v: "-o ${n}=${v}") config.options)} \ ${concatStringsSep " " (mapAttrsToList (n: v: "-O ${n}=${v}") config.rootFsOptions)} \ ''${ZFSDEVICES_${config.name}} + zfs set ${concatStringsSep " " (mapAttrsToList (n: v: "${n}=${v}") config.optionsAfterCreate)} ${config.name} ${concatMapStrings (dataset: dataset._create config.name) (attrValues config.datasets)} ''; description = "Creation script"; From fb229950e0cdca4f5f4f03ffadce42132ad56df6 Mon Sep 17 00:00:00 2001 From: phaer Date: Wed, 28 Dec 2022 16:35:23 +0100 Subject: [PATCH 02/24] fix: make optionsAfterCreate optional. --- types.nix | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/types.nix b/types.nix index 256d2f0..219e929 100644 --- a/types.nix +++ b/types.nix @@ -1159,7 +1159,9 @@ rec { ${concatStringsSep " " (mapAttrsToList (n: v: "-o ${n}=${v}") config.options)} \ ${concatStringsSep " " (mapAttrsToList (n: v: "-O ${n}=${v}") config.rootFsOptions)} \ ''${ZFSDEVICES_${config.name}} - zfs set ${concatStringsSep " " (mapAttrsToList (n: v: "${n}=${v}") config.optionsAfterCreate)} ${config.name} + ${lib.optionalString + (config.optionsAfterCreate != {}) + "zfs set ${concatStringsSep " " (mapAttrsToList (n: v: "${n}=${v}") config.optionsAfterCreate)} ${config.name}"} ${concatMapStrings (dataset: dataset._create config.name) (attrValues config.datasets)} ''; description = "Creation script"; From 8e4b2d1e3bd3555f9e3d862bca1d0b66578c1e62 Mon Sep 17 00:00:00 2001 From: phaer Date: Fri, 6 Jan 2023 15:58:32 +0100 Subject: [PATCH 03/24] wip: optionsAfterCreate -> postCreateHook... and introduce defineHookVariables --- types.nix | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/types.nix b/types.nix index 219e929..f37edbb 100644 --- a/types.nix +++ b/types.nix @@ -116,6 +116,17 @@ rec { */ maybeStr = x: optionalString (!isNull x) x; + /* Takes a Submodules config and options argument and returns a serializable + subset of config variables as a shell script snippet. + */ + defineHookVariables = {config, options}: + lib.toShellVars + (lib.mapAttrs + (n: o: o.value) + (lib.filterAttrs diskoLib.isSerializable options)); + isSerializable = n: o: !(lib.hasPrefix "_" n || lib.hasSuffix "Hook" n || diskoLib.isAttrsOfSubmodule o); + isAttrsOfSubmodule = o: o.type.name == "attrsOf" && o.type.nestedTypes.elemType.name == "submodule"; + /* Takes a disko device specification, returns an attrset with metadata meta :: types.devices -> AttrSet @@ -1095,7 +1106,8 @@ rec { }; }); - zpool = types.submodule ({ config, ... }: { + zpool = types.submodule ({ config, options, ... }: + { options = { name = mkOption { type = types.str; @@ -1118,9 +1130,9 @@ rec { default = {}; description = "Options for the ZFS pool"; }; - optionsAfterCreate = mkOption { - type = types.attrsOf types.str; - default = {}; + postCreateHook = mkOption { + type = types.str; + default = "zfs set keylocation=prompt $name"; }; rootFsOptions = mkOption { type = types.attrsOf types.str; @@ -1154,14 +1166,13 @@ rec { readOnly = true; type = types.str; default = '' + ${diskoLib.defineHookVariables { inherit config options; }} zpool create ${config.name} \ ${config.mode} \ ${concatStringsSep " " (mapAttrsToList (n: v: "-o ${n}=${v}") config.options)} \ ${concatStringsSep " " (mapAttrsToList (n: v: "-O ${n}=${v}") config.rootFsOptions)} \ ''${ZFSDEVICES_${config.name}} - ${lib.optionalString - (config.optionsAfterCreate != {}) - "zfs set ${concatStringsSep " " (mapAttrsToList (n: v: "${n}=${v}") config.optionsAfterCreate)} ${config.name}"} + ${config.postCreateHook} ${concatMapStrings (dataset: dataset._create config.name) (attrValues config.datasets)} ''; description = "Creation script"; From ac991c281be0072fd51b53ea600efbc7f77711fe Mon Sep 17 00:00:00 2001 From: phaer Date: Fri, 6 Jan 2023 16:08:29 +0100 Subject: [PATCH 04/24] style: concatStrings map -> concatMapStrings --- types.nix | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/types.nix b/types.nix index f37edbb..03d6ae6 100644 --- a/types.nix +++ b/types.nix @@ -141,7 +141,7 @@ rec { sortedDeviceList = diskoLib.sortDevicesByDependencies ((diskoLib.meta devices).deviceDependencies or {}) devices; in '' set -efux - ${concatStrings (map (dev: attrByPath (dev ++ [ "_create" ]) "" devices) sortedDeviceList)} + ${concatMapStrings (dev: attrByPath (dev ++ [ "_create" ]) "" devices) sortedDeviceList} ''; /* Takes a disko device specification and returns a string which mounts the disks @@ -153,7 +153,7 @@ rec { in '' set -efux # first create the necessary devices - ${concatStrings (map (dev: attrByPath (dev ++ [ "_mount" "dev" ]) "" devices) sortedDeviceList)} + ${concatMapStrings (dev: attrByPath (dev ++ [ "_mount" "dev" ]) "" devices) sortedDeviceList} # and then mount the filesystems in alphabetical order # attrValues returns values sorted by name. This is important, because it @@ -657,7 +657,7 @@ rec { partMounts = diskoLib.deepMergeMap (partition: partition._mount dev) config.partitions; in { dev = '' - ${concatStrings (map (x: x.dev or "") (attrValues partMounts))} + ${concatMapStrings (x: x.dev or "") (attrValues partMounts)} ''; fs = partMounts.fs or {}; }; @@ -948,7 +948,7 @@ rec { in { dev = '' vgchange -a y - ${concatStrings (map (x: x.dev or "") (attrValues lvMounts))} + ${concatMapStrings (x: x.dev or "") (attrValues lvMounts)} ''; fs = lvMounts.fs; }; @@ -1186,7 +1186,7 @@ rec { in { dev = '' zpool list '${config.name}' >/dev/null 2>/dev/null || zpool import '${config.name}' - ${concatStrings (map (x: x.dev or "") (attrValues datasetMounts))} + ${concatMapStrings (x: x.dev or "") (attrValues datasetMounts)} ''; fs = datasetMounts.fs // optionalAttrs (!isNull config.mountpoint) { ${config.mountpoint} = '' From a78d3ce5783526b9b920c595acb9f1187943923a Mon Sep 17 00:00:00 2001 From: phaer Date: Fri, 6 Jan 2023 19:59:47 +0100 Subject: [PATCH 05/24] add hookMixin --- types.nix | 113 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 68 insertions(+), 45 deletions(-) diff --git a/types.nix b/types.nix index 03d6ae6..054340b 100644 --- a/types.nix +++ b/types.nix @@ -127,6 +127,38 @@ rec { isSerializable = n: o: !(lib.hasPrefix "_" n || lib.hasSuffix "Hook" n || diskoLib.isAttrsOfSubmodule o); isAttrsOfSubmodule = o: o.type.name == "attrsOf" && o.type.nestedTypes.elemType.name == "submodule"; + hookMixin = { config, options,... }: { + options = let + mkHook = mkOption { + type = types.str; + default = ""; + }; + in { + preCreateHook = mkHook; + postCreateHook = mkHook; + preMountHook = mkHook; + postMountHook = mkHook; + }; + }; + + mkCreateOption = { config, options, default }: + mkOption { + description = "Creation script"; + internal = true; + readOnly = true; + type = types.str; + default = lib.concatStringsSep "\n" [ + "(" #subshell for namespacing + (diskoLib.defineHookVariables { inherit config options; }) + config.preCreateHook + default + config.postCreateHook + ")" + ]; + }; + + + /* Takes a disko device specification, returns an attrset with metadata meta :: types.devices -> AttrSet @@ -255,7 +287,7 @@ rec { }; }; - nodev = types.submodule ({ config, ... }: { + nodev = types.submodule [diskoLib.hookMixin ({ config, options, ... }: { options = { type = mkOption { type = types.enum [ "nodev" ]; @@ -332,9 +364,9 @@ rec { description = "Packages"; }; }; - }); + })]; - btrfs = types.submodule ({ config, ... }: { + btrfs = types.submodule [diskoLib.hookMixin ({ config, options, ... }: { options = { type = mkOption { type = types.enum [ "btrfs" ]; @@ -423,9 +455,9 @@ rec { description = "Packages"; }; }; - }); + })]; - btrfs_subvol = types.submodule ({ config, ... }: { + btrfs_subvol = types.submodule [diskoLib.hookMixin ({ config, options, ... }: { options = { name = mkOption { type = types.str; @@ -518,9 +550,9 @@ rec { description = "Packages"; }; }; - }); + })]; - filesystem = types.submodule ({ config, ... }: { + filesystem = types.submodule [diskoLib.hookMixin ({ config, options, ... }: { options = { type = mkOption { type = types.enum [ "filesystem" ]; @@ -611,9 +643,9 @@ rec { description = "Packages"; }; }; - }); + })]; - table = types.submodule ({ config, ... }: { + table = types.submodule [diskoLib.hookMixin ({ config, options, ... }: { options = { type = mkOption { type = types.enum [ "table" ]; @@ -679,9 +711,9 @@ rec { description = "Packages"; }; }; - }); + })]; - partition = types.submodule ({ config, ... }: { + partition = types.submodule [diskoLib.hookMixin ({ config, options, ... }: { options = { type = mkOption { type = types.enum [ "partition" ]; @@ -785,9 +817,9 @@ rec { description = "Packages"; }; }; - }); + })]; - swap = types.submodule ({ config, ... }: { + swap = types.submodule [diskoLib.hookMixin ({ config, options, ... }: { options = { type = mkOption { type = types.enum [ "swap" ]; @@ -848,9 +880,9 @@ rec { description = "Packages"; }; }; - }); + })]; - lvm_pv = types.submodule ({ config, ... }: { + lvm_pv = types.submodule [diskoLib.hookMixin ({ config, options, ... }: { options = { type = mkOption { type = types.enum [ "lvm_pv" ]; @@ -902,9 +934,9 @@ rec { description = "Packages"; }; }; - }); + })]; - lvm_vg = types.submodule ({ config, ... }: { + lvm_vg = types.submodule [diskoLib.hookMixin ({ config, options, ... }: { options = { name = mkOption { type = types.str; @@ -969,9 +1001,9 @@ rec { description = "Packages"; }; }; - }); + })]; - lvm_lv = types.submodule ({ config, ... }: { + lvm_lv = types.submodule [diskoLib.hookMixin ({ config, options, ... }: { options = { name = mkOption { type = types.str; @@ -1051,9 +1083,9 @@ rec { description = "Packages"; }; }; - }); + })]; - zfs = types.submodule ({ config, ... }: { + zfs = types.submodule [diskoLib.hookMixin ({ config, options, ... }: { options = { type = mkOption { type = types.enum [ "zfs" ]; @@ -1104,9 +1136,9 @@ rec { description = "Packages"; }; }; - }); + })]; - zpool = types.submodule ({ config, options, ... }: + zpool = types.submodule [diskoLib.hookMixin ({ config, options, ... }: { options = { name = mkOption { @@ -1130,10 +1162,6 @@ rec { default = {}; description = "Options for the ZFS pool"; }; - postCreateHook = mkOption { - type = types.str; - default = "zfs set keylocation=prompt $name"; - }; rootFsOptions = mkOption { type = types.attrsOf types.str; default = {}; @@ -1161,21 +1189,16 @@ rec { diskoLib.deepMergeMap (dataset: dataset._meta [ "zpool" config.name ]) (attrValues config.datasets); description = "Metadata"; }; - _create = mkOption { - internal = true; - readOnly = true; - type = types.str; + _create = diskoLib.mkCreateOption { + inherit config options; default = '' - ${diskoLib.defineHookVariables { inherit config options; }} zpool create ${config.name} \ ${config.mode} \ ${concatStringsSep " " (mapAttrsToList (n: v: "-o ${n}=${v}") config.options)} \ ${concatStringsSep " " (mapAttrsToList (n: v: "-O ${n}=${v}") config.rootFsOptions)} \ ''${ZFSDEVICES_${config.name}} - ${config.postCreateHook} ${concatMapStrings (dataset: dataset._create config.name) (attrValues config.datasets)} ''; - description = "Creation script"; }; _mount = mkOption { internal = true; @@ -1225,9 +1248,9 @@ rec { description = "Packages"; }; }; - }); + })]; - zfs_dataset = types.submodule ({ config, ... }: { + zfs_dataset = types.submodule [diskoLib.hookMixin ({ config, options, ... }: { options = { name = mkOption { type = types.str; @@ -1332,9 +1355,9 @@ rec { description = "Packages"; }; }; - }); + })]; - mdadm = types.submodule ({ config, ... }: { + mdadm = types.submodule [diskoLib.hookMixin ({ config, options, ... }: { options = { name = mkOption { type = types.str; @@ -1407,9 +1430,9 @@ rec { description = "Packages"; }; }; - }); + })]; - mdraid = types.submodule ({ config, ... }: { + mdraid = types.submodule [diskoLib.hookMixin ({ config, options, ... }: { options = { type = mkOption { type = types.enum [ "mdraid" ]; @@ -1462,9 +1485,9 @@ rec { description = "Packages"; }; }; - }); + })]; - luks = types.submodule ({ config, ... }: { + luks = types.submodule [diskoLib.hookMixin ({ config, options, ... }: { options = { type = mkOption { type = types.enum [ "luks" ]; @@ -1541,9 +1564,9 @@ rec { description = "Packages"; }; }; - }); + })]; - disk = types.submodule ({ config, ... }: { + disk = types.submodule [diskoLib.hookMixin ({ config, options, ... }: { options = { name = mkOption { type = types.str; @@ -1599,5 +1622,5 @@ rec { description = "Packages"; }; }; - }); + })]; } From 360ee1522f3feeb973fded3033b146be189c1785 Mon Sep 17 00:00:00 2001 From: phaer Date: Fri, 6 Jan 2023 23:56:13 +0100 Subject: [PATCH 06/24] revert mkCreateOption --- types.nix | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/types.nix b/types.nix index 054340b..05021f9 100644 --- a/types.nix +++ b/types.nix @@ -141,24 +141,6 @@ rec { }; }; - mkCreateOption = { config, options, default }: - mkOption { - description = "Creation script"; - internal = true; - readOnly = true; - type = types.str; - default = lib.concatStringsSep "\n" [ - "(" #subshell for namespacing - (diskoLib.defineHookVariables { inherit config options; }) - config.preCreateHook - default - config.postCreateHook - ")" - ]; - }; - - - /* Takes a disko device specification, returns an attrset with metadata meta :: types.devices -> AttrSet @@ -1189,8 +1171,10 @@ rec { diskoLib.deepMergeMap (dataset: dataset._meta [ "zpool" config.name ]) (attrValues config.datasets); description = "Metadata"; }; - _create = diskoLib.mkCreateOption { - inherit config options; + _create = mkOption { + internal = true; + readOnly = true; + type = types.str; default = '' zpool create ${config.name} \ ${config.mode} \ @@ -1199,6 +1183,7 @@ rec { ''${ZFSDEVICES_${config.name}} ${concatMapStrings (dataset: dataset._create config.name) (attrValues config.datasets)} ''; + description = "Creation script"; }; _mount = mkOption { internal = true; From 30642cadbc8bf9db5fbde7231904b1fdae5b75c9 Mon Sep 17 00:00:00 2001 From: phaer Date: Mon, 9 Jan 2023 20:18:17 +0100 Subject: [PATCH 07/24] _create: take an attrset Please enter the commit message for your changes. Lines starting --- types.nix | 66 +++++++++++++++++++++++++++---------------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/types.nix b/types.nix index 05021f9..bc92a6b 100644 --- a/types.nix +++ b/types.nix @@ -155,7 +155,7 @@ rec { sortedDeviceList = diskoLib.sortDevicesByDependencies ((diskoLib.meta devices).deviceDependencies or {}) devices; in '' set -efux - ${concatMapStrings (dev: attrByPath (dev ++ [ "_create" ]) "" devices) sortedDeviceList} + ${concatMapStrings (dev: (attrByPath (dev ++ [ "_create" ]) ({}: {}) devices) {}) sortedDeviceList} ''; /* Takes a disko device specification and returns a string which mounts the disks @@ -307,8 +307,8 @@ rec { _create = mkOption { internal = true; readOnly = true; - type = types.str; - default = ""; + type = types.functionTo types.str; + default = {}: ""; description = "Creation script"; }; _mount = mkOption { @@ -387,9 +387,9 @@ rec { internal = true; readOnly = true; type = types.functionTo types.str; - default = dev: '' + default = {dev}: '' mkfs.btrfs ${dev} ${config.extraArgs} - ${concatMapStrings (subvol: subvol._create dev) (attrValues config.subvolumes)} + ${concatMapStrings (subvol: subvol._create { inherit dev; }) (attrValues config.subvolumes)} ''; description = "Creation script"; }; @@ -479,7 +479,7 @@ rec { internal = true; readOnly = true; type = types.functionTo types.str; - default = dev: '' + default = {dev}: '' MNTPOINT=$(mktemp -d) ( mount ${dev} "$MNTPOINT" -o subvol=/ @@ -571,7 +571,7 @@ rec { internal = true; readOnly = true; type = types.functionTo types.str; - default = dev: '' + default = {dev}: '' mkfs.${config.format} \ ${config.extraArgs} \ ${dev} @@ -656,9 +656,9 @@ rec { internal = true; readOnly = true; type = types.functionTo types.str; - default = dev: '' + default = {dev}: '' parted -s ${dev} -- mklabel ${config.format} - ${concatMapStrings (partition: partition._create dev config.format) config.partitions} + ${concatMapStrings (partition: partition._create {inherit dev; type = config.format;} ) config.partitions} ''; description = "Creation script"; }; @@ -754,8 +754,8 @@ rec { _create = mkOption { internal = true; readOnly = true; - type = types.functionTo (types.functionTo types.str); - default = dev: type: '' + type = types.functionTo types.str; + default = {dev, type}: '' ${optionalString (type == "gpt") '' parted -s ${dev} -- mkpart ${config.name} ${diskoLib.maybeStr config.fs-type} ${config.start} ${config.end} ''} @@ -772,7 +772,7 @@ rec { '') config.flags} # ensure further operations can detect new partitions udevadm trigger --subsystem-match=block; udevadm settle - ${optionalString (!isNull config.content) (config.content._create (diskoLib.deviceNumbering dev config.index))} + ${optionalString (!isNull config.content) (config.content._create {dev = (diskoLib.deviceNumbering dev config.index);})} ''; description = "Creation script"; }; @@ -825,7 +825,7 @@ rec { internal = true; readOnly = true; type = types.functionTo types.str; - default = dev: '' + default = {dev}: '' mkswap ${dev} ''; description = "Creation script"; @@ -888,7 +888,7 @@ rec { internal = true; readOnly = true; type = types.functionTo types.str; - default = dev: '' + default = {dev}: '' pvcreate ${dev} LVMDEVICES_${config.vg}="''${LVMDEVICES_${config.vg}:-}${dev} " ''; @@ -946,10 +946,10 @@ rec { _create = mkOption { internal = true; readOnly = true; - type = types.str; - default = '' + type = types.functionTo types.str; + default = {}: '' vgcreate ${config.name} $LVMDEVICES_${config.name} - ${concatMapStrings (lv: lv._create config.name) (attrValues config.lvs)} + ${concatMapStrings (lv: lv._create {vg = config.name; }) (attrValues config.lvs)} ''; description = "Creation script"; }; @@ -1025,7 +1025,7 @@ rec { internal = true; readOnly = true; type = types.functionTo types.str; - default = vg: '' + default = {vg}: '' lvcreate \ --yes \ ${if hasInfix "%" config.size then "-l" else "-L"} ${config.size} \ @@ -1033,7 +1033,7 @@ rec { ${optionalString (!isNull config.lvm_type) "--type=${config.lvm_type}"} \ ${config.extraArgs} \ ${vg} - ${optionalString (!isNull config.content) (config.content._create "/dev/${vg}/${config.name}")} + ${optionalString (!isNull config.content) (config.content._create {dev = "/dev/${vg}/${config.name}";})} ''; description = "Creation script"; }; @@ -1091,7 +1091,7 @@ rec { internal = true; readOnly = true; type = types.functionTo types.str; - default = dev: '' + default = {dev}: '' ZFSDEVICES_${config.pool}="''${ZFSDEVICES_${config.pool}:-}${dev} " ''; description = "Creation script"; @@ -1174,14 +1174,14 @@ rec { _create = mkOption { internal = true; readOnly = true; - type = types.str; - default = '' + type = types.functionTo types.str; + default = {}: '' zpool create ${config.name} \ ${config.mode} \ ${concatStringsSep " " (mapAttrsToList (n: v: "-o ${n}=${v}") config.options)} \ ${concatStringsSep " " (mapAttrsToList (n: v: "-O ${n}=${v}") config.rootFsOptions)} \ ''${ZFSDEVICES_${config.name}} - ${concatMapStrings (dataset: dataset._create config.name) (attrValues config.datasets)} + ${concatMapStrings (dataset: dataset._create {zpool = config.name;}) (attrValues config.datasets)} ''; description = "Creation script"; }; @@ -1290,13 +1290,13 @@ rec { internal = true; readOnly = true; type = types.functionTo types.str; - default = zpool: '' + default = {zpool}: '' zfs create ${zpool}/${config.name} \ ${concatStringsSep " " (mapAttrsToList (n: v: "-o ${n}=${v}") config.options)} \ ${optionalString (config.zfs_type == "volume") "-V ${config.size}"} ${optionalString (config.zfs_type == "volume") '' udevadm trigger --subsystem-match=block; udevadm settle - ${optionalString (!isNull config.content) (config.content._create "/dev/zvol/${zpool}/${config.name}")} + ${optionalString (!isNull config.content) (config.content._create {dev = "/dev/zvol/${zpool}/${config.name}";})} ''} ''; description = "Creation script"; @@ -1377,8 +1377,8 @@ rec { _create = mkOption { internal = true; readOnly = true; - type = types.str; - default = '' + type = types.functionTo types.str; + default = {}: '' echo 'y' | mdadm --create /dev/md/${config.name} \ --level=${toString config.level} \ --raid-devices=''${RAIDDEVICES_N_${config.name}} \ @@ -1387,7 +1387,7 @@ rec { --homehost=any \ ''${RAIDDEVICES_${config.name}} udevadm trigger --subsystem-match=block; udevadm settle - ${optionalString (!isNull config.content) (config.content._create "/dev/md/${config.name}")} + ${optionalString (!isNull config.content) (config.content._create {dev = "/dev/md/${config.name}";})} ''; description = "Creation script"; }; @@ -1442,7 +1442,7 @@ rec { internal = true; readOnly = true; type = types.functionTo types.str; - default = dev: '' + default = {dev}: '' RAIDDEVICES_N_${config.name}=$((''${RAIDDEVICES_N_${config.name}:-0}+1)) RAIDDEVICES_${config.name}="''${RAIDDEVICES_${config.name}:-}${dev} " ''; @@ -1506,10 +1506,10 @@ rec { internal = true; readOnly = true; type = types.functionTo types.str; - default = dev: '' + default = {dev}: '' cryptsetup -q luksFormat ${dev} ${diskoLib.maybeStr config.keyFile} ${toString config.extraArgs} cryptsetup luksOpen ${dev} ${config.name} ${optionalString (!isNull config.keyFile) "--key-file ${config.keyFile}"} - ${optionalString (!isNull config.content) (config.content._create "/dev/mapper/${config.name}")} + ${optionalString (!isNull config.content) (config.content._create {dev = "/dev/mapper/${config.name}";})} ''; description = "Creation script"; }; @@ -1580,8 +1580,8 @@ rec { _create = mkOption { internal = true; readOnly = true; - type = types.str; - default = config.content._create config.device; + type = types.functionTo types.str; + default = {}: config.content._create {dev = config.device;}; description = "Creation script"; }; _mount = mkOption { From 7b59532520828dd510d5d19a7a5b125fda47af66 Mon Sep 17 00:00:00 2001 From: phaer Date: Mon, 9 Jan 2023 20:35:54 +0100 Subject: [PATCH 08/24] _mount: take an attrset --- types.nix | 70 +++++++++++++++++++++++++++---------------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/types.nix b/types.nix index bc92a6b..d0de2da 100644 --- a/types.nix +++ b/types.nix @@ -162,12 +162,12 @@ rec { mount :: types.devices -> str */ mount = devices: let - fsMounts = diskoLib.deepMergeMap (dev: dev._mount.fs or {}) (flatten (map attrValues (attrValues devices))); + fsMounts = diskoLib.deepMergeMap (dev: (dev._mount {}).fs or {}) (flatten (map attrValues (attrValues devices))); sortedDeviceList = diskoLib.sortDevicesByDependencies ((diskoLib.meta devices).deviceDependencies or {}) devices; in '' set -efux # first create the necessary devices - ${concatMapStrings (dev: attrByPath (dev ++ [ "_mount" "dev" ]) "" devices) sortedDeviceList} + ${concatMapStrings (dev: ((attrByPath (dev ++ [ "_mount" ]) "" devices) {}).dev ) sortedDeviceList} # and then mount the filesystems in alphabetical order # attrValues returns values sorted by name. This is important, because it @@ -314,8 +314,8 @@ rec { _mount = mkOption { internal = true; readOnly = true; - type = diskoLib.jsonType; - default = { + type = types.functionTo diskoLib.jsonType; + default = {}: { fs.${config.mountpoint} = '' if ! findmnt ${config.fsType} "/mnt${config.mountpoint}" > /dev/null 2>&1; then mount -t ${config.fsType} ${config.device} "/mnt${config.mountpoint}" \ @@ -397,9 +397,9 @@ rec { internal = true; readOnly = true; type = types.functionTo diskoLib.jsonType; - default = dev: + default = {dev}: let - subvolMounts = diskoLib.deepMergeMap (subvol: subvol._mount dev config.mountpoint) (attrValues config.subvolumes); + subvolMounts = diskoLib.deepMergeMap (subvol: subvol._mount {inherit dev; parent = config.mountpoint;}) (attrValues config.subvolumes); in { fs = subvolMounts.fs // optionalAttrs (!isNull config.mountpoint) { ${config.mountpoint} = '' @@ -492,8 +492,8 @@ rec { _mount = mkOption { internal = true; readOnly = true; - type = types.functionTo (types.functionTo diskoLib.jsonType); - default = dev: parent: let + type = types.functionTo diskoLib.jsonType; + default = {dev, parent}: let mountpoint = if (!isNull config.mountpoint) then config.mountpoint else if (isNull parent) then config.name else null; @@ -582,7 +582,7 @@ rec { internal = true; readOnly = true; type = types.functionTo diskoLib.jsonType; - default = dev: { + default = {dev}: { fs.${config.mountpoint} = '' if ! findmnt ${dev} "/mnt${config.mountpoint}" > /dev/null 2>&1; then mount ${dev} "/mnt${config.mountpoint}" \ @@ -666,9 +666,9 @@ rec { internal = true; readOnly = true; type = types.functionTo diskoLib.jsonType; - default = dev: + default = {dev}: let - partMounts = diskoLib.deepMergeMap (partition: partition._mount dev) config.partitions; + partMounts = diskoLib.deepMergeMap (partition: partition._mount {inherit dev;}) config.partitions; in { dev = '' ${concatMapStrings (x: x.dev or "") (attrValues partMounts)} @@ -780,8 +780,8 @@ rec { internal = true; readOnly = true; type = types.functionTo diskoLib.jsonType; - default = dev: - optionalAttrs (!isNull config.content) (config.content._mount (diskoLib.deviceNumbering dev config.index)); + default = {dev}: + optionalAttrs (!isNull config.content) (config.content._mount {dev = (diskoLib.deviceNumbering dev config.index);}); description = "Mount script"; }; _config = mkOption { @@ -834,7 +834,7 @@ rec { internal = true; readOnly = true; type = types.functionTo diskoLib.jsonType; - default = dev: { + default = {dev}: { fs.${dev} = '' if ! swapon --show | grep -q '^${dev} '; then swapon ${dev} @@ -898,7 +898,7 @@ rec { internal = true; readOnly = true; type = types.functionTo diskoLib.jsonType; - default = dev: + default = {dev}: {}; description = "Mount script"; }; @@ -956,9 +956,9 @@ rec { _mount = mkOption { internal = true; readOnly = true; - type = diskoLib.jsonType; - default = let - lvMounts = diskoLib.deepMergeMap (lv: lv._mount config.name) (attrValues config.lvs); + type = types.functionTo diskoLib.jsonType; + default = {}: let + lvMounts = diskoLib.deepMergeMap (lv: lv._mount {vg = config.name;}) (attrValues config.lvs); in { dev = '' vgchange -a y @@ -1041,8 +1041,8 @@ rec { internal = true; readOnly = true; type = types.functionTo diskoLib.jsonType; - default = vg: - optionalAttrs (!isNull config.content) (config.content._mount "/dev/${vg}/${config.name}"); + default = {vg}: + optionalAttrs (!isNull config.content) (config.content._mount {dev = "/dev/${vg}/${config.name}";}); description = "Mount script"; }; _config = mkOption { @@ -1100,7 +1100,7 @@ rec { internal = true; readOnly = true; type = types.functionTo diskoLib.jsonType; - default = dev: + default = {dev}: {}; description = "Mount script"; }; @@ -1188,9 +1188,9 @@ rec { _mount = mkOption { internal = true; readOnly = true; - type = diskoLib.jsonType; - default = let - datasetMounts = diskoLib.deepMergeMap (dataset: dataset._mount config.name) (attrValues config.datasets); + type = types.functionTo diskoLib.jsonType; + default = {}: let + datasetMounts = diskoLib.deepMergeMap (dataset: dataset._mount {zpool = config.name;}) (attrValues config.datasets); in { dev = '' zpool list '${config.name}' >/dev/null 2>/dev/null || zpool import '${config.name}' @@ -1305,8 +1305,8 @@ rec { internal = true; readOnly = true; type = types.functionTo diskoLib.jsonType; - default = zpool: - optionalAttrs (config.zfs_type == "volume" && !isNull config.content) (config.content._mount "/dev/zvol/${zpool}/${config.name}") // + default = {zpool}: + optionalAttrs (config.zfs_type == "volume" && !isNull config.content) (config.content._mount {dev = "/dev/zvol/${zpool}/${config.name}";}) // optionalAttrs (config.zfs_type == "filesystem" && config.options.mountpoint or "" != "none") { fs.${config.mountpoint} = '' if ! findmnt ${zpool}/${config.name} "/mnt${config.mountpoint}" > /dev/null 2>&1; then mount ${zpool}/${config.name} "/mnt${config.mountpoint}" \ @@ -1394,9 +1394,9 @@ rec { _mount = mkOption { internal = true; readOnly = true; - type = diskoLib.jsonType; - default = - optionalAttrs (!isNull config.content) (config.content._mount "/dev/md/${config.name}"); + type = types.functionTo diskoLib.jsonType; + default = {}: + optionalAttrs (!isNull config.content) (config.content._mount {dev = "/dev/md/${config.name}";}); # TODO we probably need to assemble the mdadm somehow description = "Mount script"; }; @@ -1452,7 +1452,7 @@ rec { internal = true; readOnly = true; type = types.functionTo diskoLib.jsonType; - default = dev: + default = {dev}: {}; description = "Mount script"; }; @@ -1517,9 +1517,9 @@ rec { internal = true; readOnly = true; type = types.functionTo diskoLib.jsonType; - default = dev: + default = {dev}: let - contentMount = config.content._mount "/dev/mapper/${config.name}"; + contentMount = config.content._mount {dev = "/dev/mapper/${config.name}";}; in { dev = '' @@ -1587,9 +1587,9 @@ rec { _mount = mkOption { internal = true; readOnly = true; - type = diskoLib.jsonType; - default = - optionalAttrs (!isNull config.content) (config.content._mount config.device); + type = types.functionTo diskoLib.jsonType; + default = {}: + optionalAttrs (!isNull config.content) (config.content._mount {dev = config.device;}); description = "Mount script"; }; _config = mkOption { From 313d0e23150a10684d202d290b0343fe1ebf6e67 Mon Sep 17 00:00:00 2001 From: phaer Date: Tue, 10 Jan 2023 10:25:21 +0100 Subject: [PATCH 09/24] re-add mkCreateOption --- types.nix | 129 +++++++++++++++++++----------------------------------- 1 file changed, 44 insertions(+), 85 deletions(-) diff --git a/types.nix b/types.nix index d0de2da..6fd9ca2 100644 --- a/types.nix +++ b/types.nix @@ -141,6 +141,16 @@ rec { }; }; + mkCreateOption = { config, options, default }: + mkOption { + internal = true; + readOnly = true; + type = types.functionTo types.str; + default = {}: ""; + description = "Creation script"; + }; + + /* Takes a disko device specification, returns an attrset with metadata meta :: types.devices -> AttrSet @@ -304,12 +314,9 @@ rec { }; description = "Metadata"; }; - _create = mkOption { - internal = true; - readOnly = true; - type = types.functionTo types.str; + _create = diskoLib.mkCreateOption { + inherit config options; default = {}: ""; - description = "Creation script"; }; _mount = mkOption { internal = true; @@ -383,15 +390,12 @@ rec { diskoLib.deepMergeMap (subvol: subvol._meta dev) (attrValues config.subvolumes); description = "Metadata"; }; - _create = mkOption { - internal = true; - readOnly = true; - type = types.functionTo types.str; + _create = diskoLib.mkCreateOption { + inherit config options; default = {dev}: '' mkfs.btrfs ${dev} ${config.extraArgs} ${concatMapStrings (subvol: subvol._create { inherit dev; }) (attrValues config.subvolumes)} ''; - description = "Creation script"; }; _mount = mkOption { internal = true; @@ -475,10 +479,8 @@ rec { }; description = "Metadata"; }; - _create = mkOption { - internal = true; - readOnly = true; - type = types.functionTo types.str; + _create = diskoLib.mkCreateOption { + inherit config options; default = {dev}: '' MNTPOINT=$(mktemp -d) ( @@ -487,7 +489,6 @@ rec { btrfs subvolume create "$MNTPOINT"/${config.name} ${config.extraArgs} ) ''; - description = "Creation script"; }; _mount = mkOption { internal = true; @@ -567,16 +568,13 @@ rec { }; description = "Metadata"; }; - _create = mkOption { - internal = true; - readOnly = true; - type = types.functionTo types.str; + _create = diskoLib.mkCreateOption { + inherit config options; default = {dev}: '' mkfs.${config.format} \ ${config.extraArgs} \ ${dev} ''; - description = "Creation script"; }; _mount = mkOption { internal = true; @@ -652,15 +650,12 @@ rec { diskoLib.deepMergeMap (partition: partition._meta dev) config.partitions; description = "Metadata"; }; - _create = mkOption { - internal = true; - readOnly = true; - type = types.functionTo types.str; + _create = diskoLib.mkCreateOption { + inherit config options; default = {dev}: '' parted -s ${dev} -- mklabel ${config.format} ${concatMapStrings (partition: partition._create {inherit dev; type = config.format;} ) config.partitions} ''; - description = "Creation script"; }; _mount = mkOption { internal = true; @@ -751,10 +746,8 @@ rec { optionalAttrs (!isNull config.content) (config.content._meta dev); description = "Metadata"; }; - _create = mkOption { - internal = true; - readOnly = true; - type = types.functionTo types.str; + _create = diskoLib.mkCreateOption { + inherit config options; default = {dev, type}: '' ${optionalString (type == "gpt") '' parted -s ${dev} -- mkpart ${config.name} ${diskoLib.maybeStr config.fs-type} ${config.start} ${config.end} @@ -774,7 +767,6 @@ rec { udevadm trigger --subsystem-match=block; udevadm settle ${optionalString (!isNull config.content) (config.content._create {dev = (diskoLib.deviceNumbering dev config.index);})} ''; - description = "Creation script"; }; _mount = mkOption { internal = true; @@ -821,14 +813,11 @@ rec { }; description = "Metadata"; }; - _create = mkOption { - internal = true; - readOnly = true; - type = types.functionTo types.str; + _create = diskoLib.mkCreateOption { + inherit config options; default = {dev}: '' mkswap ${dev} ''; - description = "Creation script"; }; _mount = mkOption { internal = true; @@ -884,15 +873,12 @@ rec { }; description = "Metadata"; }; - _create = mkOption { - internal = true; - readOnly = true; - type = types.functionTo types.str; + _create = diskoLib.mkCreateOption { + inherit config options; default = {dev}: '' pvcreate ${dev} LVMDEVICES_${config.vg}="''${LVMDEVICES_${config.vg}:-}${dev} " ''; - description = "Creation script"; }; _mount = mkOption { internal = true; @@ -943,15 +929,12 @@ rec { diskoLib.deepMergeMap (lv: lv._meta [ "lvm_vg" config.name ]) (attrValues config.lvs); description = "Metadata"; }; - _create = mkOption { - internal = true; - readOnly = true; - type = types.functionTo types.str; + _create = diskoLib.mkCreateOption { + inherit config options; default = {}: '' vgcreate ${config.name} $LVMDEVICES_${config.name} ${concatMapStrings (lv: lv._create {vg = config.name; }) (attrValues config.lvs)} ''; - description = "Creation script"; }; _mount = mkOption { internal = true; @@ -1021,10 +1004,8 @@ rec { optionalAttrs (!isNull config.content) (config.content._meta dev); description = "Metadata"; }; - _create = mkOption { - internal = true; - readOnly = true; - type = types.functionTo types.str; + _create = diskoLib.mkCreateOption { + inherit config options; default = {vg}: '' lvcreate \ --yes \ @@ -1035,7 +1016,6 @@ rec { ${vg} ${optionalString (!isNull config.content) (config.content._create {dev = "/dev/${vg}/${config.name}";})} ''; - description = "Creation script"; }; _mount = mkOption { internal = true; @@ -1087,14 +1067,11 @@ rec { }; description = "Metadata"; }; - _create = mkOption { - internal = true; - readOnly = true; - type = types.functionTo types.str; + _create = diskoLib.mkCreateOption { + inherit config options; default = {dev}: '' ZFSDEVICES_${config.pool}="''${ZFSDEVICES_${config.pool}:-}${dev} " ''; - description = "Creation script"; }; _mount = mkOption { internal = true; @@ -1171,10 +1148,8 @@ rec { diskoLib.deepMergeMap (dataset: dataset._meta [ "zpool" config.name ]) (attrValues config.datasets); description = "Metadata"; }; - _create = mkOption { - internal = true; - readOnly = true; - type = types.functionTo types.str; + _create = diskoLib.mkCreateOption { + inherit config options; default = {}: '' zpool create ${config.name} \ ${config.mode} \ @@ -1183,7 +1158,6 @@ rec { ''${ZFSDEVICES_${config.name}} ${concatMapStrings (dataset: dataset._create {zpool = config.name;}) (attrValues config.datasets)} ''; - description = "Creation script"; }; _mount = mkOption { internal = true; @@ -1286,10 +1260,8 @@ rec { optionalAttrs (!isNull config.content) (config.content._meta dev); description = "Metadata"; }; - _create = mkOption { - internal = true; - readOnly = true; - type = types.functionTo types.str; + _create = diskoLib.mkCreateOption { + inherit config options; default = {zpool}: '' zfs create ${zpool}/${config.name} \ ${concatStringsSep " " (mapAttrsToList (n: v: "-o ${n}=${v}") config.options)} \ @@ -1299,7 +1271,6 @@ rec { ${optionalString (!isNull config.content) (config.content._create {dev = "/dev/zvol/${zpool}/${config.name}";})} ''} ''; - description = "Creation script"; }; _mount = mkOption { internal = true; @@ -1374,10 +1345,8 @@ rec { optionalAttrs (!isNull config.content) (config.content._meta [ "mdadm" config.name ]); description = "Metadata"; }; - _create = mkOption { - internal = true; - readOnly = true; - type = types.functionTo types.str; + _create = diskoLib.mkCreateOption { + inherit config options; default = {}: '' echo 'y' | mdadm --create /dev/md/${config.name} \ --level=${toString config.level} \ @@ -1389,7 +1358,6 @@ rec { udevadm trigger --subsystem-match=block; udevadm settle ${optionalString (!isNull config.content) (config.content._create {dev = "/dev/md/${config.name}";})} ''; - description = "Creation script"; }; _mount = mkOption { internal = true; @@ -1438,15 +1406,12 @@ rec { }; description = "Metadata"; }; - _create = mkOption { - internal = true; - readOnly = true; - type = types.functionTo types.str; + _create = diskoLib.mkCreateOption { + inherit config options; default = {dev}: '' RAIDDEVICES_N_${config.name}=$((''${RAIDDEVICES_N_${config.name}:-0}+1)) RAIDDEVICES_${config.name}="''${RAIDDEVICES_${config.name}:-}${dev} " ''; - description = "Creation script"; }; _mount = mkOption { internal = true; @@ -1502,16 +1467,13 @@ rec { optionalAttrs (!isNull config.content) (config.content._meta dev); description = "Metadata"; }; - _create = mkOption { - internal = true; - readOnly = true; - type = types.functionTo types.str; + _create = diskoLib.mkCreateOption { + inherit config options; default = {dev}: '' cryptsetup -q luksFormat ${dev} ${diskoLib.maybeStr config.keyFile} ${toString config.extraArgs} cryptsetup luksOpen ${dev} ${config.name} ${optionalString (!isNull config.keyFile) "--key-file ${config.keyFile}"} ${optionalString (!isNull config.content) (config.content._create {dev = "/dev/mapper/${config.name}";})} ''; - description = "Creation script"; }; _mount = mkOption { internal = true; @@ -1577,12 +1539,9 @@ rec { optionalAttrs (!isNull config.content) (config.content._meta [ "disk" config.device ]); description = "Metadata"; }; - _create = mkOption { - internal = true; - readOnly = true; - type = types.functionTo types.str; + _create = diskoLib.mkCreateOption { + inherit config options; default = {}: config.content._create {dev = config.device;}; - description = "Creation script"; }; _mount = mkOption { internal = true; From 0e658ad7f7c7f67e2efff238ba0fe85f020fd7a1 Mon Sep 17 00:00:00 2001 From: phaer Date: Tue, 10 Jan 2023 10:45:57 +0100 Subject: [PATCH 10/24] run hooks, fix defineHookVariables --- types.nix | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/types.nix b/types.nix index 6fd9ca2..fbf5744 100644 --- a/types.nix +++ b/types.nix @@ -120,12 +120,20 @@ rec { subset of config variables as a shell script snippet. */ defineHookVariables = {config, options}: + let + sanitizeName = lib.replaceStrings ["-"] ["_"]; + isAttrsOfSubmodule = o: o.type.name == "attrsOf" && o.type.nestedTypes.elemType.name == "submodule"; + isSerializable = n: o: !( + lib.hasPrefix "_" n + || lib.hasSuffix "Hook" n + || isAttrsOfSubmodule o + # TODO don't hardcode diskoLib.subType options. + || n == "content" || n == "partitions"); + in lib.toShellVars - (lib.mapAttrs - (n: o: o.value) - (lib.filterAttrs diskoLib.isSerializable options)); - isSerializable = n: o: !(lib.hasPrefix "_" n || lib.hasSuffix "Hook" n || diskoLib.isAttrsOfSubmodule o); - isAttrsOfSubmodule = o: o.type.name == "attrsOf" && o.type.nestedTypes.elemType.name == "submodule"; + (lib.mapAttrs' + (n: o: lib.nameValuePair (sanitizeName n) o.value) + (lib.filterAttrs isSerializable options)); hookMixin = { config, options,... }: { options = let @@ -146,7 +154,13 @@ rec { internal = true; readOnly = true; type = types.functionTo types.str; - default = {}: ""; + default = args: + lib.concatStrings [ + (diskoLib.defineHookVariables { inherit config options; }) + config.preCreateHook + (default args) + config.postCreateHook + ]; description = "Creation script"; }; From 92467bb9a84bbb062d214c4554b621acaf3d3011 Mon Sep 17 00:00:00 2001 From: phaer Date: Tue, 10 Jan 2023 10:53:14 +0100 Subject: [PATCH 11/24] namespace hooks via subshell --- types.nix | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/types.nix b/types.nix index fbf5744..9c44197 100644 --- a/types.nix +++ b/types.nix @@ -155,11 +155,13 @@ rec { readOnly = true; type = types.functionTo types.str; default = args: - lib.concatStrings [ + lib.concatStringsSep "\n" [ + "(" # subshell for namespacing (diskoLib.defineHookVariables { inherit config options; }) config.preCreateHook (default args) config.postCreateHook + ")" ]; description = "Creation script"; }; From c7e5f3caeca0270592d09d809be9e3dce1d2c218 Mon Sep 17 00:00:00 2001 From: phaer Date: Tue, 10 Jan 2023 16:36:13 +0100 Subject: [PATCH 12/24] wip: add mkMountOption --- types.nix | 134 ++++++++++++++++++------------------------------------ 1 file changed, 45 insertions(+), 89 deletions(-) diff --git a/types.nix b/types.nix index 9c44197..a7f61bd 100644 --- a/types.nix +++ b/types.nix @@ -149,7 +149,7 @@ rec { }; }; - mkCreateOption = { config, options, default }: + mkCreateOption = { config, options, default }@attrs: mkOption { internal = true; readOnly = true; @@ -159,13 +159,22 @@ rec { "(" # subshell for namespacing (diskoLib.defineHookVariables { inherit config options; }) config.preCreateHook - (default args) + (attrs.default args) config.postCreateHook ")" ]; description = "Creation script"; }; + mkMountOption = { config, options, default }@attrs: + mkOption { + internal = true; + readOnly = true; + type = types.functionTo diskoLib.jsonType; + default = args: let v = attrs.default args; in lib.traceSeqN 3 [(config.name or "unnamed") (v.fs or "")] v; + description = "Mount script"; + }; + /* Takes a disko device specification, returns an attrset with metadata @@ -196,8 +205,6 @@ rec { ${concatMapStrings (dev: ((attrByPath (dev ++ [ "_mount" ]) "" devices) {}).dev ) sortedDeviceList} # and then mount the filesystems in alphabetical order - # attrValues returns values sorted by name. This is important, because it - # ensures that "/" is processed before "/foo" etc. ${concatStrings (attrValues fsMounts)} ''; @@ -334,10 +341,8 @@ rec { inherit config options; default = {}: ""; }; - _mount = mkOption { - internal = true; - readOnly = true; - type = types.functionTo diskoLib.jsonType; + _mount = diskoLib.mkMountOption { + inherit config options; default = {}: { fs.${config.mountpoint} = '' if ! findmnt ${config.fsType} "/mnt${config.mountpoint}" > /dev/null 2>&1; then @@ -347,7 +352,6 @@ rec { fi ''; }; - description = "Mount script"; }; _config = mkOption { internal = true; @@ -413,10 +417,8 @@ rec { ${concatMapStrings (subvol: subvol._create { inherit dev; }) (attrValues config.subvolumes)} ''; }; - _mount = mkOption { - internal = true; - readOnly = true; - type = types.functionTo diskoLib.jsonType; + _mount = diskoLib.mkMountOption { + inherit config options; default = {dev}: let subvolMounts = diskoLib.deepMergeMap (subvol: subvol._mount {inherit dev; parent = config.mountpoint;}) (attrValues config.subvolumes); @@ -431,7 +433,6 @@ rec { ''; }; }; - description = "Mount script"; }; _config = mkOption { internal = true; @@ -506,10 +507,8 @@ rec { ) ''; }; - _mount = mkOption { - internal = true; - readOnly = true; - type = types.functionTo diskoLib.jsonType; + _mount = diskoLib.mkMountOption { + inherit config options; default = {dev, parent}: let mountpoint = if (!isNull config.mountpoint) then config.mountpoint else if (isNull parent) then config.name @@ -523,7 +522,6 @@ rec { fi ''; }; - description = "Mount script"; }; _config = mkOption { internal = true; @@ -592,10 +590,8 @@ rec { ${dev} ''; }; - _mount = mkOption { - internal = true; - readOnly = true; - type = types.functionTo diskoLib.jsonType; + _mount = diskoLib.mkMountOption { + inherit config options; default = {dev}: { fs.${config.mountpoint} = '' if ! findmnt ${dev} "/mnt${config.mountpoint}" > /dev/null 2>&1; then @@ -606,7 +602,6 @@ rec { fi ''; }; - description = "Mount script"; }; _config = mkOption { internal = true; @@ -673,10 +668,8 @@ rec { ${concatMapStrings (partition: partition._create {inherit dev; type = config.format;} ) config.partitions} ''; }; - _mount = mkOption { - internal = true; - readOnly = true; - type = types.functionTo diskoLib.jsonType; + _mount = diskoLib.mkMountOption { + inherit config options; default = {dev}: let partMounts = diskoLib.deepMergeMap (partition: partition._mount {inherit dev;}) config.partitions; @@ -686,7 +679,6 @@ rec { ''; fs = partMounts.fs or {}; }; - description = "Mount script"; }; _config = mkOption { internal = true; @@ -784,13 +776,10 @@ rec { ${optionalString (!isNull config.content) (config.content._create {dev = (diskoLib.deviceNumbering dev config.index);})} ''; }; - _mount = mkOption { - internal = true; - readOnly = true; - type = types.functionTo diskoLib.jsonType; + _mount = diskoLib.mkMountOption { + inherit config options; default = {dev}: optionalAttrs (!isNull config.content) (config.content._mount {dev = (diskoLib.deviceNumbering dev config.index);}); - description = "Mount script"; }; _config = mkOption { internal = true; @@ -835,10 +824,8 @@ rec { mkswap ${dev} ''; }; - _mount = mkOption { - internal = true; - readOnly = true; - type = types.functionTo diskoLib.jsonType; + _mount = diskoLib.mkMountOption { + inherit config options; default = {dev}: { fs.${dev} = '' if ! swapon --show | grep -q '^${dev} '; then @@ -846,7 +833,6 @@ rec { fi ''; }; - description = "Mount script"; }; _config = mkOption { internal = true; @@ -896,13 +882,10 @@ rec { LVMDEVICES_${config.vg}="''${LVMDEVICES_${config.vg}:-}${dev} " ''; }; - _mount = mkOption { - internal = true; - readOnly = true; - type = types.functionTo diskoLib.jsonType; + _mount = diskoLib.mkMountOption { + inherit config options; default = {dev}: {}; - description = "Mount script"; }; _config = mkOption { internal = true; @@ -952,10 +935,8 @@ rec { ${concatMapStrings (lv: lv._create {vg = config.name; }) (attrValues config.lvs)} ''; }; - _mount = mkOption { - internal = true; - readOnly = true; - type = types.functionTo diskoLib.jsonType; + _mount = diskoLib.mkMountOption { + inherit config options; default = {}: let lvMounts = diskoLib.deepMergeMap (lv: lv._mount {vg = config.name;}) (attrValues config.lvs); in { @@ -965,7 +946,6 @@ rec { ''; fs = lvMounts.fs; }; - description = "Mount script"; }; _config = mkOption { internal = true; @@ -1033,13 +1013,10 @@ rec { ${optionalString (!isNull config.content) (config.content._create {dev = "/dev/${vg}/${config.name}";})} ''; }; - _mount = mkOption { - internal = true; - readOnly = true; - type = types.functionTo diskoLib.jsonType; + _mount = diskoLib.mkMountOption { + inherit config options; default = {vg}: optionalAttrs (!isNull config.content) (config.content._mount {dev = "/dev/${vg}/${config.name}";}); - description = "Mount script"; }; _config = mkOption { internal = true; @@ -1089,13 +1066,10 @@ rec { ZFSDEVICES_${config.pool}="''${ZFSDEVICES_${config.pool}:-}${dev} " ''; }; - _mount = mkOption { - internal = true; - readOnly = true; - type = types.functionTo diskoLib.jsonType; + _mount = diskoLib.mkMountOption { + inherit config options; default = {dev}: {}; - description = "Mount script"; }; _config = mkOption { internal = true; @@ -1175,10 +1149,8 @@ rec { ${concatMapStrings (dataset: dataset._create {zpool = config.name;}) (attrValues config.datasets)} ''; }; - _mount = mkOption { - internal = true; - readOnly = true; - type = types.functionTo diskoLib.jsonType; + _mount = diskoLib.mkMountOption { + inherit config options; default = {}: let datasetMounts = diskoLib.deepMergeMap (dataset: dataset._mount {zpool = config.name;}) (attrValues config.datasets); in { @@ -1198,7 +1170,6 @@ rec { ''; }; }; - description = "Mount script"; }; _config = mkOption { internal = true; @@ -1288,10 +1259,8 @@ rec { ''} ''; }; - _mount = mkOption { - internal = true; - readOnly = true; - type = types.functionTo diskoLib.jsonType; + _mount = diskoLib.mkMountOption { + inherit config options; default = {zpool}: optionalAttrs (config.zfs_type == "volume" && !isNull config.content) (config.content._mount {dev = "/dev/zvol/${zpool}/${config.name}";}) // optionalAttrs (config.zfs_type == "filesystem" && config.options.mountpoint or "" != "none") { fs.${config.mountpoint} = '' @@ -1303,7 +1272,6 @@ rec { -t zfs fi ''; }; - description = "Mount script"; }; _config = mkOption { internal = true; @@ -1375,14 +1343,11 @@ rec { ${optionalString (!isNull config.content) (config.content._create {dev = "/dev/md/${config.name}";})} ''; }; - _mount = mkOption { - internal = true; - readOnly = true; - type = types.functionTo diskoLib.jsonType; + _mount = diskoLib.mkMountOption { + inherit config options; default = {}: optionalAttrs (!isNull config.content) (config.content._mount {dev = "/dev/md/${config.name}";}); # TODO we probably need to assemble the mdadm somehow - description = "Mount script"; }; _config = mkOption { internal = true; @@ -1429,13 +1394,10 @@ rec { RAIDDEVICES_${config.name}="''${RAIDDEVICES_${config.name}:-}${dev} " ''; }; - _mount = mkOption { - internal = true; - readOnly = true; - type = types.functionTo diskoLib.jsonType; + _mount = diskoLib.mkMountOption { + inherit config options; default = {dev}: {}; - description = "Mount script"; }; _config = mkOption { internal = true; @@ -1491,10 +1453,8 @@ rec { ${optionalString (!isNull config.content) (config.content._create {dev = "/dev/mapper/${config.name}";})} ''; }; - _mount = mkOption { - internal = true; - readOnly = true; - type = types.functionTo diskoLib.jsonType; + _mount = diskoLib.mkMountOption { + inherit config options; default = {dev}: let contentMount = config.content._mount {dev = "/dev/mapper/${config.name}";}; @@ -1507,7 +1467,6 @@ rec { ''; fs = optionalAttrs (!isNull config.content) contentMount.fs or {}; }; - description = "Mount script"; }; _config = mkOption { internal = true; @@ -1559,13 +1518,10 @@ rec { inherit config options; default = {}: config.content._create {dev = config.device;}; }; - _mount = mkOption { - internal = true; - readOnly = true; - type = types.functionTo diskoLib.jsonType; + _mount = diskoLib.mkMountOption { + inherit config options; default = {}: optionalAttrs (!isNull config.content) (config.content._mount {dev = config.device;}); - description = "Mount script"; }; _config = mkOption { internal = true; From ad6ab7df50a162f2183f5752146d051b5ab05e04 Mon Sep 17 00:00:00 2001 From: phaer Date: Sat, 14 Jan 2023 17:24:49 +0100 Subject: [PATCH 13/24] add debug output --- types.nix | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/types.nix b/types.nix index a7f61bd..1476ca7 100644 --- a/types.nix +++ b/types.nix @@ -137,15 +137,15 @@ rec { hookMixin = { config, options,... }: { options = let - mkHook = mkOption { + mkHook = default: mkOption { type = types.str; - default = ""; + default = default; }; in { - preCreateHook = mkHook; - postCreateHook = mkHook; - preMountHook = mkHook; - postMountHook = mkHook; + preCreateHook = mkHook "echo 'DEBUG preCreate: ${config.type}'"; + postCreateHook = mkHook "echo 'DEBUG postCreate: ${config.type}'"; + preMountHook = mkHook "echo 'DEBUG preMount: ${config.type}'"; + postMountHook = mkHook "echo 'DEBUG postMount: ${config.type}'"; }; }; @@ -155,14 +155,17 @@ rec { readOnly = true; type = types.functionTo types.str; default = args: - lib.concatStringsSep "\n" [ - "(" # subshell for namespacing - (diskoLib.defineHookVariables { inherit config options; }) - config.preCreateHook - (attrs.default args) - config.postCreateHook - ")" - ]; + let name = "format"; + test = lib.optionalString (config ? name) "${config.${name}}"; + in + '' + ( # ${config.type} ${concatMapStringsSep " " (n: toString (config.${n} or "")) ["name" "device" "format" "mountpoint"]} + ${diskoLib.defineHookVariables { inherit config options; }} + ${config.preCreateHook} + ${attrs.default args} + ${config.postCreateHook} + ) + ''; description = "Creation script"; }; From 21e31af6785707bf369f7521f534b4798b49b3f0 Mon Sep 17 00:00:00 2001 From: phaer Date: Sat, 14 Jan 2023 22:38:22 +0100 Subject: [PATCH 14/24] try an anonymous function for namespacing... ...no local yet --- types.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types.nix b/types.nix index 1476ca7..fe78c16 100644 --- a/types.nix +++ b/types.nix @@ -159,12 +159,12 @@ rec { test = lib.optionalString (config ? name) "${config.${name}}"; in '' - ( # ${config.type} ${concatMapStringsSep " " (n: toString (config.${n} or "")) ["name" "device" "format" "mountpoint"]} + function { # ${config.type} ${concatMapStringsSep " " (n: toString (config.${n} or "")) ["name" "device" "format" "mountpoint"]} ${diskoLib.defineHookVariables { inherit config options; }} ${config.preCreateHook} ${attrs.default args} ${config.postCreateHook} - ) + } ''; description = "Creation script"; }; From 32f3730777738e5e895c96040cd3c3afc0b1df4a Mon Sep 17 00:00:00 2001 From: phaer Date: Sat, 14 Jan 2023 22:43:07 +0100 Subject: [PATCH 15/24] Revert "try an anonymous function for namespacing..." This reverts commit 6390d835025eb36a81bd2b97dcd1a5746e07ebfe. --- types.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types.nix b/types.nix index fe78c16..1476ca7 100644 --- a/types.nix +++ b/types.nix @@ -159,12 +159,12 @@ rec { test = lib.optionalString (config ? name) "${config.${name}}"; in '' - function { # ${config.type} ${concatMapStringsSep " " (n: toString (config.${n} or "")) ["name" "device" "format" "mountpoint"]} + ( # ${config.type} ${concatMapStringsSep " " (n: toString (config.${n} or "")) ["name" "device" "format" "mountpoint"]} ${diskoLib.defineHookVariables { inherit config options; }} ${config.preCreateHook} ${attrs.default args} ${config.postCreateHook} - } + ) ''; description = "Creation script"; }; From 63eca646536050700ea651f5deed45dec74033c4 Mon Sep 17 00:00:00 2001 From: phaer Date: Sat, 14 Jan 2023 23:04:31 +0100 Subject: [PATCH 16/24] replace subshell by code block... ..for now, because subshell break zfs creation --- types.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types.nix b/types.nix index 1476ca7..ebe7365 100644 --- a/types.nix +++ b/types.nix @@ -159,12 +159,12 @@ rec { test = lib.optionalString (config ? name) "${config.${name}}"; in '' - ( # ${config.type} ${concatMapStringsSep " " (n: toString (config.${n} or "")) ["name" "device" "format" "mountpoint"]} + { # ${config.type} ${concatMapStringsSep " " (n: toString (config.${n} or "")) ["name" "device" "format" "mountpoint"]} ${diskoLib.defineHookVariables { inherit config options; }} ${config.preCreateHook} ${attrs.default args} ${config.postCreateHook} - ) + } ''; description = "Creation script"; }; From 10e1037ad76cc55bf242ad9119470533212114dd Mon Sep 17 00:00:00 2001 From: phaer Date: Sun, 15 Jan 2023 12:51:23 +0100 Subject: [PATCH 17/24] Revert "replace subshell by code block..." This reverts commit 9628475f870cafc470dd7ad7b829b60f1b649861. --- types.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types.nix b/types.nix index ebe7365..1476ca7 100644 --- a/types.nix +++ b/types.nix @@ -159,12 +159,12 @@ rec { test = lib.optionalString (config ? name) "${config.${name}}"; in '' - { # ${config.type} ${concatMapStringsSep " " (n: toString (config.${n} or "")) ["name" "device" "format" "mountpoint"]} + ( # ${config.type} ${concatMapStringsSep " " (n: toString (config.${n} or "")) ["name" "device" "format" "mountpoint"]} ${diskoLib.defineHookVariables { inherit config options; }} ${config.preCreateHook} ${attrs.default args} ${config.postCreateHook} - } + ) ''; description = "Creation script"; }; From 5034d2d83607d6462ce4efaacec8c1b53334a095 Mon Sep 17 00:00:00 2001 From: phaer Date: Sun, 15 Jan 2023 15:52:25 +0100 Subject: [PATCH 18/24] mount: allow empty .dev --- types.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types.nix b/types.nix index 1476ca7..b483c95 100644 --- a/types.nix +++ b/types.nix @@ -205,7 +205,7 @@ rec { in '' set -efux # first create the necessary devices - ${concatMapStrings (dev: ((attrByPath (dev ++ [ "_mount" ]) "" devices) {}).dev ) sortedDeviceList} + ${concatMapStrings (dev: ((attrByPath (dev ++ [ "_mount" ]) "" devices) {}).dev or "") sortedDeviceList} # and then mount the filesystems in alphabetical order ${concatStrings (attrValues fsMounts)} From d64b6b0868f1cf7ab3605c69d53aae522bb10a3b Mon Sep 17 00:00:00 2001 From: phaer Date: Sun, 15 Jan 2023 16:12:38 +0100 Subject: [PATCH 19/24] create: use tempdir for DEVICES... instead of env vars. As we need to append to them in subshells. --- types.nix | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/types.nix b/types.nix index b483c95..5faf0a9 100644 --- a/types.nix +++ b/types.nix @@ -193,6 +193,11 @@ rec { sortedDeviceList = diskoLib.sortDevicesByDependencies ((diskoLib.meta devices).deviceDependencies or {}) devices; in '' set -efux + + disko_devices_dir=$(mktemp -d) + trap 'rm -rf "$disko_devices_dir"' EXIT + mkdir -p "$disko_devices_dir" + ${concatMapStrings (dev: (attrByPath (dev ++ [ "_create" ]) ({}: {}) devices) {}) sortedDeviceList} ''; /* Takes a disko device specification and returns a string which mounts the disks @@ -882,7 +887,7 @@ rec { inherit config options; default = {dev}: '' pvcreate ${dev} - LVMDEVICES_${config.vg}="''${LVMDEVICES_${config.vg}:-}${dev} " + echo "${dev}" >> $disko_devices_dir/lvm_${config.vg} ''; }; _mount = diskoLib.mkMountOption { @@ -934,7 +939,7 @@ rec { _create = diskoLib.mkCreateOption { inherit config options; default = {}: '' - vgcreate ${config.name} $LVMDEVICES_${config.name} + vgcreate ${config.name} $(tr '\n' ' ' < $disko_devices_dir/lvm_${config.name}) ${concatMapStrings (lv: lv._create {vg = config.name; }) (attrValues config.lvs)} ''; }; @@ -1066,7 +1071,7 @@ rec { _create = diskoLib.mkCreateOption { inherit config options; default = {dev}: '' - ZFSDEVICES_${config.pool}="''${ZFSDEVICES_${config.pool}:-}${dev} " + echo "${dev}" >> $disko_devices_dir/zfs_${config.pool} ''; }; _mount = diskoLib.mkMountOption { @@ -1148,7 +1153,7 @@ rec { ${config.mode} \ ${concatStringsSep " " (mapAttrsToList (n: v: "-o ${n}=${v}") config.options)} \ ${concatStringsSep " " (mapAttrsToList (n: v: "-O ${n}=${v}") config.rootFsOptions)} \ - ''${ZFSDEVICES_${config.name}} + $(tr '\n' ' ' < $disko_devices_dir/zfs_${config.name}) ${concatMapStrings (dataset: dataset._create {zpool = config.name;}) (attrValues config.datasets)} ''; }; @@ -1337,11 +1342,11 @@ rec { default = {}: '' echo 'y' | mdadm --create /dev/md/${config.name} \ --level=${toString config.level} \ - --raid-devices=''${RAIDDEVICES_N_${config.name}} \ + --raid-devices=$(wc -l $disko_devices_dir/raid_${config.name} | cut -f 1 -d " ") \ --metadata=${config.metadata} \ --force \ --homehost=any \ - ''${RAIDDEVICES_${config.name}} + $(tr '\n' ' ' < $disko_devices_dir/raid_${config.name}) udevadm trigger --subsystem-match=block; udevadm settle ${optionalString (!isNull config.content) (config.content._create {dev = "/dev/md/${config.name}";})} ''; @@ -1393,8 +1398,7 @@ rec { _create = diskoLib.mkCreateOption { inherit config options; default = {dev}: '' - RAIDDEVICES_N_${config.name}=$((''${RAIDDEVICES_N_${config.name}:-0}+1)) - RAIDDEVICES_${config.name}="''${RAIDDEVICES_${config.name}:-}${dev} " + echo "${dev}" >> $disko_devices_dir/raid_${config.name} ''; }; _mount = diskoLib.mkMountOption { From 94d1319001065ce356bb7f6a380282e8eb1a5d80 Mon Sep 17 00:00:00 2001 From: phaer Date: Sun, 15 Jan 2023 16:24:31 +0100 Subject: [PATCH 20/24] remove trace --- types.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types.nix b/types.nix index 5faf0a9..af444e8 100644 --- a/types.nix +++ b/types.nix @@ -174,7 +174,7 @@ rec { internal = true; readOnly = true; type = types.functionTo diskoLib.jsonType; - default = args: let v = attrs.default args; in lib.traceSeqN 3 [(config.name or "unnamed") (v.fs or "")] v; + default = args: attrs.default args; description = "Mount script"; }; From f8050d6f8487f51c3b83213e8bbb38d3b311530a Mon Sep 17 00:00:00 2001 From: phaer Date: Sun, 15 Jan 2023 16:36:59 +0100 Subject: [PATCH 21/24] fix examples... ...why did those tests pass before? config didn't match options schema --- example/config.nix | 7 +++---- example/stand-alone/configuration.nix | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/example/config.nix b/example/config.nix index 58edb1e..cb013cd 100644 --- a/example/config.nix +++ b/example/config.nix @@ -5,7 +5,7 @@ type = "lvm_vg"; lvs = { root = { - type = "lv"; + type = "lvm_lv"; size = "10G"; content = { type = "filesystem"; @@ -14,7 +14,7 @@ }; }; home = { - type = "lv"; + type = "lvm_lv"; size = "10G"; content = { type = "filesystem"; @@ -33,9 +33,8 @@ format = "gpt"; partitions = [ { - name = "boot"; + name = "ESP"; type = "partition"; - part-type = "ESP"; start = "1MiB"; end = "1024MiB"; fs-type = "fat32"; diff --git a/example/stand-alone/configuration.nix b/example/stand-alone/configuration.nix index 67576a0..c53bdf9 100644 --- a/example/stand-alone/configuration.nix +++ b/example/stand-alone/configuration.nix @@ -18,7 +18,7 @@ disk = { sda = { device = "/dev/sda"; - type = "device"; + type = "disk"; content = { type = "table"; format = "msdos"; From dfd7ee959089702e5bf55b4a7803d80fdb578ca4 Mon Sep 17 00:00:00 2001 From: phaer Date: Sun, 15 Jan 2023 17:28:23 +0100 Subject: [PATCH 22/24] module: dash -> bash --- module.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/module.nix b/module.nix index ad30856..806d397 100644 --- a/module.nix +++ b/module.nix @@ -20,12 +20,12 @@ in { }; }; config = lib.mkIf (cfg.devices.disk != {}) { - system.build.formatScript = pkgs.writers.writeDash "disko-create" '' + system.build.formatScript = pkgs.writers.writeBash "disko-create" '' export PATH=${lib.makeBinPath (types.diskoLib.packages cfg.devices pkgs)}:$PATH ${types.diskoLib.create cfg.devices} ''; - system.build.mountScript = pkgs.writers.writeDash "disko-mount" '' + system.build.mountScript = pkgs.writers.writeBash "disko-mount" '' export PATH=${lib.makeBinPath (types.diskoLib.packages cfg.devices pkgs)}:$PATH ${types.diskoLib.mount cfg.devices} ''; From caf893b6eb79178c0f9c70a05f3848cfffc23e96 Mon Sep 17 00:00:00 2001 From: phaer Date: Thu, 19 Jan 2023 13:09:41 +0100 Subject: [PATCH 23/24] hooks: remove debug output --- types.nix | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/types.nix b/types.nix index af444e8..cd3659d 100644 --- a/types.nix +++ b/types.nix @@ -137,15 +137,15 @@ rec { hookMixin = { config, options,... }: { options = let - mkHook = default: mkOption { + mkHook = mkOption { type = types.str; - default = default; + default = ""; }; in { - preCreateHook = mkHook "echo 'DEBUG preCreate: ${config.type}'"; - postCreateHook = mkHook "echo 'DEBUG postCreate: ${config.type}'"; - preMountHook = mkHook "echo 'DEBUG preMount: ${config.type}'"; - postMountHook = mkHook "echo 'DEBUG postMount: ${config.type}'"; + preCreateHook = mkHook; + postCreateHook = mkHook; + preMountHook = mkHook; + postMountHook = mkHook; }; }; From a63d0fa12b9df151897d189257ae441381cfc864 Mon Sep 17 00:00:00 2001 From: phaer Date: Thu, 19 Jan 2023 13:12:08 +0100 Subject: [PATCH 24/24] hooks: add description --- types.nix | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/types.nix b/types.nix index cd3659d..5d7d337 100644 --- a/types.nix +++ b/types.nix @@ -137,15 +137,16 @@ rec { hookMixin = { config, options,... }: { options = let - mkHook = mkOption { + mkHook = description: mkOption { + inherit description; type = types.str; default = ""; }; in { - preCreateHook = mkHook; - postCreateHook = mkHook; - preMountHook = mkHook; - postMountHook = mkHook; + preCreateHook = mkHook "shell commands to run before create"; + postCreateHook = mkHook "shell commands to run after create"; + preMountHook = mkHook "shell commands to run before mount"; + postMountHook = mkHook "shell commands to run after mount"; }; };