mirror of
https://github.com/TECHNOFAB11/disko.git
synced 2025-12-12 16:10:03 +01:00
wip: add mkMountOption
This commit is contained in:
parent
92467bb9a8
commit
c7e5f3caec
1 changed files with 45 additions and 89 deletions
134
types.nix
134
types.nix
|
|
@ -149,7 +149,7 @@ rec {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
mkCreateOption = { config, options, default }:
|
mkCreateOption = { config, options, default }@attrs:
|
||||||
mkOption {
|
mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
|
|
@ -159,13 +159,22 @@ rec {
|
||||||
"(" # subshell for namespacing
|
"(" # subshell for namespacing
|
||||||
(diskoLib.defineHookVariables { inherit config options; })
|
(diskoLib.defineHookVariables { inherit config options; })
|
||||||
config.preCreateHook
|
config.preCreateHook
|
||||||
(default args)
|
(attrs.default args)
|
||||||
config.postCreateHook
|
config.postCreateHook
|
||||||
")"
|
")"
|
||||||
];
|
];
|
||||||
description = "Creation script";
|
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
|
/* Takes a disko device specification, returns an attrset with metadata
|
||||||
|
|
||||||
|
|
@ -196,8 +205,6 @@ rec {
|
||||||
${concatMapStrings (dev: ((attrByPath (dev ++ [ "_mount" ]) "" devices) {}).dev ) sortedDeviceList}
|
${concatMapStrings (dev: ((attrByPath (dev ++ [ "_mount" ]) "" devices) {}).dev ) sortedDeviceList}
|
||||||
|
|
||||||
# and then mount the filesystems in alphabetical order
|
# 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)}
|
${concatStrings (attrValues fsMounts)}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
|
@ -334,10 +341,8 @@ rec {
|
||||||
inherit config options;
|
inherit config options;
|
||||||
default = {}: "";
|
default = {}: "";
|
||||||
};
|
};
|
||||||
_mount = mkOption {
|
_mount = diskoLib.mkMountOption {
|
||||||
internal = true;
|
inherit config options;
|
||||||
readOnly = true;
|
|
||||||
type = types.functionTo diskoLib.jsonType;
|
|
||||||
default = {}: {
|
default = {}: {
|
||||||
fs.${config.mountpoint} = ''
|
fs.${config.mountpoint} = ''
|
||||||
if ! findmnt ${config.fsType} "/mnt${config.mountpoint}" > /dev/null 2>&1; then
|
if ! findmnt ${config.fsType} "/mnt${config.mountpoint}" > /dev/null 2>&1; then
|
||||||
|
|
@ -347,7 +352,6 @@ rec {
|
||||||
fi
|
fi
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
description = "Mount script";
|
|
||||||
};
|
};
|
||||||
_config = mkOption {
|
_config = mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
|
|
@ -413,10 +417,8 @@ rec {
|
||||||
${concatMapStrings (subvol: subvol._create { inherit dev; }) (attrValues config.subvolumes)}
|
${concatMapStrings (subvol: subvol._create { inherit dev; }) (attrValues config.subvolumes)}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
_mount = mkOption {
|
_mount = diskoLib.mkMountOption {
|
||||||
internal = true;
|
inherit config options;
|
||||||
readOnly = true;
|
|
||||||
type = types.functionTo diskoLib.jsonType;
|
|
||||||
default = {dev}:
|
default = {dev}:
|
||||||
let
|
let
|
||||||
subvolMounts = diskoLib.deepMergeMap (subvol: subvol._mount {inherit dev; parent = config.mountpoint;}) (attrValues config.subvolumes);
|
subvolMounts = diskoLib.deepMergeMap (subvol: subvol._mount {inherit dev; parent = config.mountpoint;}) (attrValues config.subvolumes);
|
||||||
|
|
@ -431,7 +433,6 @@ rec {
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
description = "Mount script";
|
|
||||||
};
|
};
|
||||||
_config = mkOption {
|
_config = mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
|
|
@ -506,10 +507,8 @@ rec {
|
||||||
)
|
)
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
_mount = mkOption {
|
_mount = diskoLib.mkMountOption {
|
||||||
internal = true;
|
inherit config options;
|
||||||
readOnly = true;
|
|
||||||
type = types.functionTo diskoLib.jsonType;
|
|
||||||
default = {dev, parent}: let
|
default = {dev, parent}: let
|
||||||
mountpoint = if (!isNull config.mountpoint) then config.mountpoint
|
mountpoint = if (!isNull config.mountpoint) then config.mountpoint
|
||||||
else if (isNull parent) then config.name
|
else if (isNull parent) then config.name
|
||||||
|
|
@ -523,7 +522,6 @@ rec {
|
||||||
fi
|
fi
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
description = "Mount script";
|
|
||||||
};
|
};
|
||||||
_config = mkOption {
|
_config = mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
|
|
@ -592,10 +590,8 @@ rec {
|
||||||
${dev}
|
${dev}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
_mount = mkOption {
|
_mount = diskoLib.mkMountOption {
|
||||||
internal = true;
|
inherit config options;
|
||||||
readOnly = true;
|
|
||||||
type = types.functionTo diskoLib.jsonType;
|
|
||||||
default = {dev}: {
|
default = {dev}: {
|
||||||
fs.${config.mountpoint} = ''
|
fs.${config.mountpoint} = ''
|
||||||
if ! findmnt ${dev} "/mnt${config.mountpoint}" > /dev/null 2>&1; then
|
if ! findmnt ${dev} "/mnt${config.mountpoint}" > /dev/null 2>&1; then
|
||||||
|
|
@ -606,7 +602,6 @@ rec {
|
||||||
fi
|
fi
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
description = "Mount script";
|
|
||||||
};
|
};
|
||||||
_config = mkOption {
|
_config = mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
|
|
@ -673,10 +668,8 @@ rec {
|
||||||
${concatMapStrings (partition: partition._create {inherit dev; type = config.format;} ) config.partitions}
|
${concatMapStrings (partition: partition._create {inherit dev; type = config.format;} ) config.partitions}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
_mount = mkOption {
|
_mount = diskoLib.mkMountOption {
|
||||||
internal = true;
|
inherit config options;
|
||||||
readOnly = true;
|
|
||||||
type = types.functionTo diskoLib.jsonType;
|
|
||||||
default = {dev}:
|
default = {dev}:
|
||||||
let
|
let
|
||||||
partMounts = diskoLib.deepMergeMap (partition: partition._mount {inherit dev;}) config.partitions;
|
partMounts = diskoLib.deepMergeMap (partition: partition._mount {inherit dev;}) config.partitions;
|
||||||
|
|
@ -686,7 +679,6 @@ rec {
|
||||||
'';
|
'';
|
||||||
fs = partMounts.fs or {};
|
fs = partMounts.fs or {};
|
||||||
};
|
};
|
||||||
description = "Mount script";
|
|
||||||
};
|
};
|
||||||
_config = mkOption {
|
_config = mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
|
|
@ -784,13 +776,10 @@ rec {
|
||||||
${optionalString (!isNull config.content) (config.content._create {dev = (diskoLib.deviceNumbering dev config.index);})}
|
${optionalString (!isNull config.content) (config.content._create {dev = (diskoLib.deviceNumbering dev config.index);})}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
_mount = mkOption {
|
_mount = diskoLib.mkMountOption {
|
||||||
internal = true;
|
inherit config options;
|
||||||
readOnly = true;
|
|
||||||
type = types.functionTo diskoLib.jsonType;
|
|
||||||
default = {dev}:
|
default = {dev}:
|
||||||
optionalAttrs (!isNull config.content) (config.content._mount {dev = (diskoLib.deviceNumbering dev config.index);});
|
optionalAttrs (!isNull config.content) (config.content._mount {dev = (diskoLib.deviceNumbering dev config.index);});
|
||||||
description = "Mount script";
|
|
||||||
};
|
};
|
||||||
_config = mkOption {
|
_config = mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
|
|
@ -835,10 +824,8 @@ rec {
|
||||||
mkswap ${dev}
|
mkswap ${dev}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
_mount = mkOption {
|
_mount = diskoLib.mkMountOption {
|
||||||
internal = true;
|
inherit config options;
|
||||||
readOnly = true;
|
|
||||||
type = types.functionTo diskoLib.jsonType;
|
|
||||||
default = {dev}: {
|
default = {dev}: {
|
||||||
fs.${dev} = ''
|
fs.${dev} = ''
|
||||||
if ! swapon --show | grep -q '^${dev} '; then
|
if ! swapon --show | grep -q '^${dev} '; then
|
||||||
|
|
@ -846,7 +833,6 @@ rec {
|
||||||
fi
|
fi
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
description = "Mount script";
|
|
||||||
};
|
};
|
||||||
_config = mkOption {
|
_config = mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
|
|
@ -896,13 +882,10 @@ rec {
|
||||||
LVMDEVICES_${config.vg}="''${LVMDEVICES_${config.vg}:-}${dev} "
|
LVMDEVICES_${config.vg}="''${LVMDEVICES_${config.vg}:-}${dev} "
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
_mount = mkOption {
|
_mount = diskoLib.mkMountOption {
|
||||||
internal = true;
|
inherit config options;
|
||||||
readOnly = true;
|
|
||||||
type = types.functionTo diskoLib.jsonType;
|
|
||||||
default = {dev}:
|
default = {dev}:
|
||||||
{};
|
{};
|
||||||
description = "Mount script";
|
|
||||||
};
|
};
|
||||||
_config = mkOption {
|
_config = mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
|
|
@ -952,10 +935,8 @@ rec {
|
||||||
${concatMapStrings (lv: lv._create {vg = config.name; }) (attrValues config.lvs)}
|
${concatMapStrings (lv: lv._create {vg = config.name; }) (attrValues config.lvs)}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
_mount = mkOption {
|
_mount = diskoLib.mkMountOption {
|
||||||
internal = true;
|
inherit config options;
|
||||||
readOnly = true;
|
|
||||||
type = types.functionTo diskoLib.jsonType;
|
|
||||||
default = {}: let
|
default = {}: let
|
||||||
lvMounts = diskoLib.deepMergeMap (lv: lv._mount {vg = config.name;}) (attrValues config.lvs);
|
lvMounts = diskoLib.deepMergeMap (lv: lv._mount {vg = config.name;}) (attrValues config.lvs);
|
||||||
in {
|
in {
|
||||||
|
|
@ -965,7 +946,6 @@ rec {
|
||||||
'';
|
'';
|
||||||
fs = lvMounts.fs;
|
fs = lvMounts.fs;
|
||||||
};
|
};
|
||||||
description = "Mount script";
|
|
||||||
};
|
};
|
||||||
_config = mkOption {
|
_config = mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
|
|
@ -1033,13 +1013,10 @@ rec {
|
||||||
${optionalString (!isNull config.content) (config.content._create {dev = "/dev/${vg}/${config.name}";})}
|
${optionalString (!isNull config.content) (config.content._create {dev = "/dev/${vg}/${config.name}";})}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
_mount = mkOption {
|
_mount = diskoLib.mkMountOption {
|
||||||
internal = true;
|
inherit config options;
|
||||||
readOnly = true;
|
|
||||||
type = types.functionTo diskoLib.jsonType;
|
|
||||||
default = {vg}:
|
default = {vg}:
|
||||||
optionalAttrs (!isNull config.content) (config.content._mount {dev = "/dev/${vg}/${config.name}";});
|
optionalAttrs (!isNull config.content) (config.content._mount {dev = "/dev/${vg}/${config.name}";});
|
||||||
description = "Mount script";
|
|
||||||
};
|
};
|
||||||
_config = mkOption {
|
_config = mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
|
|
@ -1089,13 +1066,10 @@ rec {
|
||||||
ZFSDEVICES_${config.pool}="''${ZFSDEVICES_${config.pool}:-}${dev} "
|
ZFSDEVICES_${config.pool}="''${ZFSDEVICES_${config.pool}:-}${dev} "
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
_mount = mkOption {
|
_mount = diskoLib.mkMountOption {
|
||||||
internal = true;
|
inherit config options;
|
||||||
readOnly = true;
|
|
||||||
type = types.functionTo diskoLib.jsonType;
|
|
||||||
default = {dev}:
|
default = {dev}:
|
||||||
{};
|
{};
|
||||||
description = "Mount script";
|
|
||||||
};
|
};
|
||||||
_config = mkOption {
|
_config = mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
|
|
@ -1175,10 +1149,8 @@ rec {
|
||||||
${concatMapStrings (dataset: dataset._create {zpool = config.name;}) (attrValues config.datasets)}
|
${concatMapStrings (dataset: dataset._create {zpool = config.name;}) (attrValues config.datasets)}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
_mount = mkOption {
|
_mount = diskoLib.mkMountOption {
|
||||||
internal = true;
|
inherit config options;
|
||||||
readOnly = true;
|
|
||||||
type = types.functionTo diskoLib.jsonType;
|
|
||||||
default = {}: let
|
default = {}: let
|
||||||
datasetMounts = diskoLib.deepMergeMap (dataset: dataset._mount {zpool = config.name;}) (attrValues config.datasets);
|
datasetMounts = diskoLib.deepMergeMap (dataset: dataset._mount {zpool = config.name;}) (attrValues config.datasets);
|
||||||
in {
|
in {
|
||||||
|
|
@ -1198,7 +1170,6 @@ rec {
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
description = "Mount script";
|
|
||||||
};
|
};
|
||||||
_config = mkOption {
|
_config = mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
|
|
@ -1288,10 +1259,8 @@ rec {
|
||||||
''}
|
''}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
_mount = mkOption {
|
_mount = diskoLib.mkMountOption {
|
||||||
internal = true;
|
inherit config options;
|
||||||
readOnly = true;
|
|
||||||
type = types.functionTo diskoLib.jsonType;
|
|
||||||
default = {zpool}:
|
default = {zpool}:
|
||||||
optionalAttrs (config.zfs_type == "volume" && !isNull config.content) (config.content._mount {dev = "/dev/zvol/${zpool}/${config.name}";}) //
|
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} = ''
|
optionalAttrs (config.zfs_type == "filesystem" && config.options.mountpoint or "" != "none") { fs.${config.mountpoint} = ''
|
||||||
|
|
@ -1303,7 +1272,6 @@ rec {
|
||||||
-t zfs
|
-t zfs
|
||||||
fi
|
fi
|
||||||
''; };
|
''; };
|
||||||
description = "Mount script";
|
|
||||||
};
|
};
|
||||||
_config = mkOption {
|
_config = mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
|
|
@ -1375,14 +1343,11 @@ rec {
|
||||||
${optionalString (!isNull config.content) (config.content._create {dev = "/dev/md/${config.name}";})}
|
${optionalString (!isNull config.content) (config.content._create {dev = "/dev/md/${config.name}";})}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
_mount = mkOption {
|
_mount = diskoLib.mkMountOption {
|
||||||
internal = true;
|
inherit config options;
|
||||||
readOnly = true;
|
|
||||||
type = types.functionTo diskoLib.jsonType;
|
|
||||||
default = {}:
|
default = {}:
|
||||||
optionalAttrs (!isNull config.content) (config.content._mount {dev = "/dev/md/${config.name}";});
|
optionalAttrs (!isNull config.content) (config.content._mount {dev = "/dev/md/${config.name}";});
|
||||||
# TODO we probably need to assemble the mdadm somehow
|
# TODO we probably need to assemble the mdadm somehow
|
||||||
description = "Mount script";
|
|
||||||
};
|
};
|
||||||
_config = mkOption {
|
_config = mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
|
|
@ -1429,13 +1394,10 @@ rec {
|
||||||
RAIDDEVICES_${config.name}="''${RAIDDEVICES_${config.name}:-}${dev} "
|
RAIDDEVICES_${config.name}="''${RAIDDEVICES_${config.name}:-}${dev} "
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
_mount = mkOption {
|
_mount = diskoLib.mkMountOption {
|
||||||
internal = true;
|
inherit config options;
|
||||||
readOnly = true;
|
|
||||||
type = types.functionTo diskoLib.jsonType;
|
|
||||||
default = {dev}:
|
default = {dev}:
|
||||||
{};
|
{};
|
||||||
description = "Mount script";
|
|
||||||
};
|
};
|
||||||
_config = mkOption {
|
_config = mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
|
|
@ -1491,10 +1453,8 @@ rec {
|
||||||
${optionalString (!isNull config.content) (config.content._create {dev = "/dev/mapper/${config.name}";})}
|
${optionalString (!isNull config.content) (config.content._create {dev = "/dev/mapper/${config.name}";})}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
_mount = mkOption {
|
_mount = diskoLib.mkMountOption {
|
||||||
internal = true;
|
inherit config options;
|
||||||
readOnly = true;
|
|
||||||
type = types.functionTo diskoLib.jsonType;
|
|
||||||
default = {dev}:
|
default = {dev}:
|
||||||
let
|
let
|
||||||
contentMount = config.content._mount {dev = "/dev/mapper/${config.name}";};
|
contentMount = config.content._mount {dev = "/dev/mapper/${config.name}";};
|
||||||
|
|
@ -1507,7 +1467,6 @@ rec {
|
||||||
'';
|
'';
|
||||||
fs = optionalAttrs (!isNull config.content) contentMount.fs or {};
|
fs = optionalAttrs (!isNull config.content) contentMount.fs or {};
|
||||||
};
|
};
|
||||||
description = "Mount script";
|
|
||||||
};
|
};
|
||||||
_config = mkOption {
|
_config = mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
|
|
@ -1559,13 +1518,10 @@ rec {
|
||||||
inherit config options;
|
inherit config options;
|
||||||
default = {}: config.content._create {dev = config.device;};
|
default = {}: config.content._create {dev = config.device;};
|
||||||
};
|
};
|
||||||
_mount = mkOption {
|
_mount = diskoLib.mkMountOption {
|
||||||
internal = true;
|
inherit config options;
|
||||||
readOnly = true;
|
|
||||||
type = types.functionTo diskoLib.jsonType;
|
|
||||||
default = {}:
|
default = {}:
|
||||||
optionalAttrs (!isNull config.content) (config.content._mount {dev = config.device;});
|
optionalAttrs (!isNull config.content) (config.content._mount {dev = config.device;});
|
||||||
description = "Mount script";
|
|
||||||
};
|
};
|
||||||
_config = mkOption {
|
_config = mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue