mirror of
https://github.com/TECHNOFAB11/disko.git
synced 2025-12-12 08:00:05 +01:00
lib.types: turn _create, _mount and _config into values
This commit is contained in:
parent
8002e7cb89
commit
ab9b880db2
17 changed files with 194 additions and 146 deletions
|
|
@ -1,4 +1,4 @@
|
|||
{ config, options, lib, diskoLib, parent, ... }@args:
|
||||
{ config, options, lib, diskoLib, parent, device, ... }@args:
|
||||
{
|
||||
options = {
|
||||
type = lib.mkOption {
|
||||
|
|
@ -6,6 +6,11 @@
|
|||
internal = true;
|
||||
description = "Partition table";
|
||||
};
|
||||
device = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = device;
|
||||
description = "Device to use for the partition table";
|
||||
};
|
||||
partitions = lib.mkOption {
|
||||
type = lib.types.attrsOf (lib.types.submodule ({ name, ... }@partition: {
|
||||
options = {
|
||||
|
|
@ -14,6 +19,11 @@
|
|||
default = "8300";
|
||||
description = "Filesystem type to use, run sgdisk -L to see what is available";
|
||||
};
|
||||
device = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "/dev/disk/by-partlabel/${partition.config.label}";
|
||||
description = "Device to use for the partition";
|
||||
};
|
||||
priority = lib.mkOption {
|
||||
type = lib.types.int;
|
||||
default = if (partition.config.size or "" == "100%") then 9001 else 1000;
|
||||
|
|
@ -51,7 +61,7 @@
|
|||
or - for relative sizes from the disks end
|
||||
'';
|
||||
};
|
||||
content = diskoLib.partitionType { parent = config; };
|
||||
content = diskoLib.partitionType { parent = config; device = partition.config.device; };
|
||||
};
|
||||
}));
|
||||
default = [ ];
|
||||
|
|
@ -75,27 +85,27 @@
|
|||
};
|
||||
_create = diskoLib.mkCreateOption {
|
||||
inherit config options;
|
||||
default = { dev }: ''
|
||||
default = ''
|
||||
${lib.concatStrings (lib.imap (index: partition: ''
|
||||
sgdisk \
|
||||
--new=${toString index}:${partition.start}:${partition.end} \
|
||||
--change-name=${toString index}:${partition.label} \
|
||||
--typecode=${toString index}:${partition.type} \
|
||||
${dev}
|
||||
${config.device}
|
||||
# ensure /dev/disk/by-path/..-partN exists before continuing
|
||||
udevadm trigger --subsystem-match=block; udevadm settle
|
||||
${lib.optionalString (partition.content != null) (partition.content._create { dev = "/dev/disk/by-partlabel/${partition.label}"; })}
|
||||
${lib.optionalString (partition.content != null) partition.content._create}
|
||||
'') (lib.sort (x: y: x.priority < y.priority) (lib.attrValues config.partitions)))}
|
||||
|
||||
'';
|
||||
};
|
||||
_mount = diskoLib.mkMountOption {
|
||||
inherit config options;
|
||||
default = { dev }:
|
||||
default =
|
||||
let
|
||||
partMounts = lib.foldr lib.recursiveUpdate { } (lib.imap
|
||||
(index: partition:
|
||||
lib.optionalAttrs (partition.content != null) (partition.content._mount { dev = "/dev/disk/by-partlabel/${partition.label}"; })
|
||||
lib.optionalAttrs (partition.content != null) partition.content._mount
|
||||
)
|
||||
(lib.attrValues config.partitions));
|
||||
in
|
||||
|
|
@ -107,10 +117,9 @@
|
|||
_config = lib.mkOption {
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
default = dev:
|
||||
lib.imap
|
||||
(index: partition:
|
||||
lib.optional (partition.content != null) (partition.content._config "/dev/disk/by-partlabel/${partition.label}")
|
||||
default = map
|
||||
(partition:
|
||||
lib.optional (partition.content != null) partition.content._config
|
||||
)
|
||||
(lib.attrValues config.partitions);
|
||||
description = "NixOS configuration";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue