mirror of
https://github.com/TECHNOFAB11/disko.git
synced 2025-12-12 16:10:03 +01:00
wip: optionsAfterCreate -> postCreateHook...
and introduce defineHookVariables
This commit is contained in:
parent
fb229950e0
commit
8e4b2d1e3b
1 changed files with 18 additions and 7 deletions
25
types.nix
25
types.nix
|
|
@ -116,6 +116,17 @@ rec {
|
||||||
*/
|
*/
|
||||||
maybeStr = x: optionalString (!isNull x) x;
|
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
|
/* Takes a disko device specification, returns an attrset with metadata
|
||||||
|
|
||||||
meta :: types.devices -> AttrSet
|
meta :: types.devices -> AttrSet
|
||||||
|
|
@ -1095,7 +1106,8 @@ rec {
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
zpool = types.submodule ({ config, ... }: {
|
zpool = types.submodule ({ config, options, ... }:
|
||||||
|
{
|
||||||
options = {
|
options = {
|
||||||
name = mkOption {
|
name = mkOption {
|
||||||
type = types.str;
|
type = types.str;
|
||||||
|
|
@ -1118,9 +1130,9 @@ rec {
|
||||||
default = {};
|
default = {};
|
||||||
description = "Options for the ZFS pool";
|
description = "Options for the ZFS pool";
|
||||||
};
|
};
|
||||||
optionsAfterCreate = mkOption {
|
postCreateHook = mkOption {
|
||||||
type = types.attrsOf types.str;
|
type = types.str;
|
||||||
default = {};
|
default = "zfs set keylocation=prompt $name";
|
||||||
};
|
};
|
||||||
rootFsOptions = mkOption {
|
rootFsOptions = mkOption {
|
||||||
type = types.attrsOf types.str;
|
type = types.attrsOf types.str;
|
||||||
|
|
@ -1154,14 +1166,13 @@ rec {
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
type = types.str;
|
type = types.str;
|
||||||
default = ''
|
default = ''
|
||||||
|
${diskoLib.defineHookVariables { inherit config options; }}
|
||||||
zpool create ${config.name} \
|
zpool create ${config.name} \
|
||||||
${config.mode} \
|
${config.mode} \
|
||||||
${concatStringsSep " " (mapAttrsToList (n: v: "-o ${n}=${v}") config.options)} \
|
${concatStringsSep " " (mapAttrsToList (n: v: "-o ${n}=${v}") config.options)} \
|
||||||
${concatStringsSep " " (mapAttrsToList (n: v: "-O ${n}=${v}") config.rootFsOptions)} \
|
${concatStringsSep " " (mapAttrsToList (n: v: "-O ${n}=${v}") config.rootFsOptions)} \
|
||||||
''${ZFSDEVICES_${config.name}}
|
''${ZFSDEVICES_${config.name}}
|
||||||
${lib.optionalString
|
${config.postCreateHook}
|
||||||
(config.optionsAfterCreate != {})
|
|
||||||
"zfs set ${concatStringsSep " " (mapAttrsToList (n: v: "${n}=${v}") config.optionsAfterCreate)} ${config.name}"}
|
|
||||||
${concatMapStrings (dataset: dataset._create config.name) (attrValues config.datasets)}
|
${concatMapStrings (dataset: dataset._create config.name) (attrValues config.datasets)}
|
||||||
'';
|
'';
|
||||||
description = "Creation script";
|
description = "Creation script";
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue