types table: inline partition type

This commit is contained in:
lassulus 2023-04-07 14:29:39 +02:00
parent 8891df7029
commit d6f062ea11
22 changed files with 76 additions and 159 deletions

View File

@ -9,7 +9,6 @@
format = "gpt";
partitions = [
{
type = "partition";
name = "ESP";
start = "1MiB";
end = "100MiB";
@ -22,7 +21,6 @@
}
{
name = "root";
type = "partition";
start = "100MiB";
end = "100%";
part-type = "primary";

View File

@ -10,14 +10,12 @@
partitions = [
{
name = "boot";
type = "partition";
start = "0";
end = "1M";
part-type = "primary";
flags = [ "bios_grub" ];
}
{
type = "partition";
name = "ESP";
start = "1MiB";
end = "128MiB";
@ -29,7 +27,6 @@
};
}
{
type = "partition";
name = "mdadm";
start = "128MiB";
end = "100%";
@ -50,14 +47,12 @@
partitions = [
{
name = "boot";
type = "partition";
start = "0";
end = "1M";
part-type = "primary";
flags = [ "bios_grub" ];
}
{
type = "partition";
name = "ESP";
start = "1MiB";
end = "128MiB";
@ -69,7 +64,6 @@
};
}
{
type = "partition";
name = "mdadm";
start = "128MiB";
end = "100%";
@ -101,7 +95,6 @@
format = "gpt";
partitions = [
{
type = "partition";
name = "primary";
start = "1MiB";
end = "100%";

View File

@ -9,7 +9,6 @@
format = "gpt";
partitions = [
{
type = "partition";
name = "ESP";
start = "1MiB";
end = "128MiB";
@ -23,7 +22,6 @@
}
{
name = "root";
type = "partition";
start = "128MiB";
end = "100%";
content = {

View File

@ -9,7 +9,6 @@
format = "gpt";
partitions = [
{
type = "partition";
name = "ESP";
start = "1MiB";
end = "128MiB";
@ -32,7 +31,6 @@
format = "gpt";
partitions = [
{
type = "partition";
start = "1M";
end = "100%";
name = "luks";
@ -60,7 +58,6 @@
format = "gpt";
partitions = [
{
type = "partition";
start = "1M";
end = "100%";
name = "luks";
@ -90,7 +87,6 @@
format = "gpt";
partitions = [
{
type = "partition";
name = "bla";
start = "1MiB";
end = "100%";

View File

@ -11,7 +11,6 @@
partitions = [
{
name = "boot";
type = "partition";
start = "0";
end = "1M";
part-type = "primary";
@ -19,7 +18,6 @@
}
{
name = "root";
type = "partition";
# leave space for the grub aka BIOS boot
start = "1M";
end = "100%";

View File

@ -9,13 +9,11 @@
partitions = [
{
name = "boot";
type = "partition";
start = "0";
end = "1M";
flags = [ "bios_grub" ];
}
{
type = "partition";
name = "ESP";
start = "1M";
end = "512M";
@ -28,7 +26,6 @@
}
{
name = "nix";
type = "partition";
start = "512M";
end = "100%";
part-type = "primary";

View File

@ -10,13 +10,11 @@
partitions = [
{
name = "boot";
type = "partition";
start = "0";
end = "1M";
flags = [ "bios_grub" ];
}
{
type = "partition";
name = "ESP";
start = "1M";
end = "512M";
@ -28,7 +26,6 @@
};
}
{
type = "partition";
name = "root";
start = "512M";
end = "100%";

View File

@ -9,7 +9,6 @@
format = "gpt";
partitions = [
{
type = "partition";
name = "ESP";
start = "1MiB";
end = "100MiB";
@ -24,7 +23,6 @@
};
}
{
type = "partition";
name = "luks";
start = "100MiB";
end = "100%";

View File

@ -10,7 +10,6 @@
partitions = [
{
name = "boot";
type = "partition";
start = "0";
end = "100M";
fs-type = "fat32";
@ -21,7 +20,6 @@
};
}
{
type = "partition";
name = "primary";
start = "100M";
end = "100%";
@ -42,7 +40,6 @@
partitions = [
{
name = "boot";
type = "partition";
start = "0";
end = "100M";
fs-type = "fat32";
@ -53,7 +50,6 @@
};
}
{
type = "partition";
name = "primary";
start = "100M";
end = "100%";

View File

@ -10,14 +10,12 @@
partitions = [
{
name = "boot";
type = "partition";
start = "0";
end = "1M";
part-type = "primary";
flags = [ "bios_grub" ];
}
{
type = "partition";
name = "mdadm";
start = "1MiB";
end = "100%";
@ -38,14 +36,12 @@
partitions = [
{
name = "boot";
type = "partition";
start = "0";
end = "1M";
part-type = "primary";
flags = [ "bios_grub" ];
}
{
type = "partition";
name = "mdadm";
start = "1MiB";
end = "100%";
@ -67,7 +63,6 @@
format = "gpt";
partitions = [
{
type = "partition";
name = "primary";
start = "1MiB";
end = "100%";

View File

@ -10,7 +10,6 @@
partitions = [
{
name = "nix";
type = "partition";
part-type = "primary";
start = "0%";
end = "100%";
@ -33,7 +32,6 @@
partitions = [
{
name = "root";
type = "partition";
part-type = "primary";
start = "0%";
end = "100%";

View File

@ -10,7 +10,6 @@
partitions = [
{
name = "nix";
type = "partition";
part-type = "primary";
start = "0%";
end = "-10MiB";

View File

@ -9,7 +9,6 @@
format = "gpt";
partitions = [
{
type = "partition";
name = "ESP";
start = "1MiB";
end = "100MiB";
@ -22,7 +21,6 @@
}
{
name = "root";
type = "partition";
start = "100MiB";
end = "100%";
part-type = "primary";

View File

@ -25,7 +25,6 @@ let
partitions = [
{
name = "root";
type = "partition";
part-type = "primary";
start = "1M";
end = "100%";

View File

@ -9,7 +9,6 @@
format = "gpt";
partitions = [
{
type = "partition";
name = "ESP";
start = "1MiB";
end = "100MiB";
@ -22,7 +21,6 @@
}
{
name = "root";
type = "partition";
start = "100MiB";
end = "-1G";
part-type = "primary";
@ -34,7 +32,6 @@
}
{
name = "swap";
type = "partition";
start = "-1G";
end = "100%";
part-type = "primary";

View File

@ -9,7 +9,6 @@
format = "gpt";
partitions = [
{
type = "partition";
name = "ESP";
start = "1MiB";
end = "100MiB";
@ -22,7 +21,6 @@
}
{
name = "root";
type = "partition";
start = "100MiB";
end = "100%";
part-type = "primary";

View File

@ -10,7 +10,6 @@
partitions = [
{
name = "boot";
type = "partition";
start = "0";
end = "1M";
part-type = "primary";
@ -18,7 +17,6 @@
}
{
name = "root";
type = "partition";
# leave space for the grub aka BIOS boot
start = "1M";
end = "100%";

View File

@ -9,7 +9,6 @@
format = "gpt";
partitions = [
{
type = "partition";
name = "ESP";
start = "1MiB";
end = "100MiB";
@ -24,7 +23,6 @@
};
}
{
type = "partition";
start = "100MiB";
end = "100%";
name = "primary";

View File

@ -9,7 +9,6 @@
format = "gpt";
partitions = [
{
type = "partition";
name = "ESP";
start = "0";
end = "64MiB";
@ -22,7 +21,6 @@
};
}
{
type = "partition";
name = "zfs";
start = "128MiB";
end = "100%";
@ -42,7 +40,6 @@
format = "gpt";
partitions = [
{
type = "partition";
name = "zfs";
start = "128MiB";
end = "100%";

View File

@ -342,7 +342,6 @@ rec {
btrfs_subvol = ./btrfs_subvol.nix;
filesystem = ./filesystem.nix;
table = ./table.nix;
partition = ./partition.nix;
swap = ./swap.nix;
lvm_pv = ./lvm_pv.nix;
lvm_vg = ./lvm_vg.nix;

View File

@ -1,100 +0,0 @@
{ config, options, lib, diskoLib, ... }:
{
options = {
type = lib.mkOption {
type = lib.types.enum [ "partition" ];
internal = true;
description = "Type";
};
part-type = lib.mkOption {
type = lib.types.enum [ "primary" "logical" "extended" ];
default = "primary";
description = "Partition type";
};
fs-type = lib.mkOption {
type = lib.types.nullOr (lib.types.enum [ "btrfs" "ext2" "ext3" "ext4" "fat16" "fat32" "hfs" "hfs+" "linux-swap" "ntfs" "reiserfs" "udf" "xfs" ]);
default = null;
description = "Filesystem type to use";
};
name = lib.mkOption {
type = lib.types.nullOr lib.types.str;
description = "Name of the partition";
};
start = lib.mkOption {
type = lib.types.str;
default = "0%";
description = "Start of the partition";
};
end = lib.mkOption {
type = lib.types.str;
default = "100%";
description = "End of the partition";
};
index = lib.mkOption {
type = lib.types.int;
# TODO find a better way to get the index
default = lib.toInt (lib.head (builtins.match ".*entry ([[:digit:]]+)]" config._module.args.name));
description = "Index of the partition";
};
flags = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [ ];
description = "Partition flags";
};
bootable = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Whether to make the partition bootable";
};
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 = { dev, type }: ''
${lib.optionalString (type == "gpt") ''
parted -s ${dev} -- mkpart ${config.name} ${diskoLib.maybeStr config.fs-type} ${config.start} ${config.end}
''}
${lib.optionalString (type == "msdos") ''
parted -s ${dev} -- mkpart ${config.part-type} ${diskoLib.maybeStr config.fs-type} ${diskoLib.maybeStr config.fs-type} ${config.start} ${config.end}
''}
# ensure /dev/disk/by-path/..-partN exists before continuing
udevadm trigger --subsystem-match=block; udevadm settle
${lib.optionalString config.bootable ''
parted -s ${dev} -- set ${toString config.index} boot on
''}
${lib.concatMapStringsSep "" (flag: ''
parted -s ${dev} -- set ${toString config.index} ${flag} on
'') config.flags}
# ensure further operations can detect new partitions
udevadm trigger --subsystem-match=block; udevadm settle
${lib.optionalString (config.content != null) (config.content._create {dev = diskoLib.deviceNumbering dev config.index;})}
'';
};
_mount = diskoLib.mkMountOption {
inherit config options;
default = { dev }:
lib.optionalAttrs (config.content != null) (config.content._mount { dev = diskoLib.deviceNumbering dev config.index; });
};
_config = lib.mkOption {
internal = true;
readOnly = true;
default = dev:
lib.optional (config.content != null) (config.content._config (diskoLib.deviceNumbering dev config.index));
description = "NixOS configuration";
};
_pkgs = lib.mkOption {
internal = true;
readOnly = true;
type = lib.types.functionTo (lib.types.listOf lib.types.package);
default = pkgs: lib.optionals (config.content != null) (config.content._pkgs pkgs);
description = "Packages";
};
};
}

View File

@ -12,7 +12,51 @@
description = "The kind of partition table";
};
partitions = lib.mkOption {
type = lib.types.listOf subTypes.partition;
type = lib.types.listOf (lib.types.submodule ({ config, ... }: {
options = {
part-type = lib.mkOption {
type = lib.types.enum [ "primary" "logical" "extended" ];
default = "primary";
description = "Partition type";
};
fs-type = lib.mkOption {
type = lib.types.nullOr (lib.types.enum [ "btrfs" "ext2" "ext3" "ext4" "fat16" "fat32" "hfs" "hfs+" "linux-swap" "ntfs" "reiserfs" "udf" "xfs" ]);
default = null;
description = "Filesystem type to use";
};
name = lib.mkOption {
type = lib.types.nullOr lib.types.str;
description = "Name of the partition";
};
start = lib.mkOption {
type = lib.types.str;
default = "0%";
description = "Start of the partition";
};
end = lib.mkOption {
type = lib.types.str;
default = "100%";
description = "End of the partition";
};
index = lib.mkOption {
type = lib.types.int;
# TODO find a better way to get the index
default = lib.toInt (lib.head (builtins.match ".*entry ([[:digit:]]+)]" config._module.args.name));
description = "Index of the partition";
};
flags = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [ ];
description = "Partition flags";
};
bootable = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Whether to make the partition bootable";
};
content = diskoLib.partitionType;
};
}));
default = [ ];
description = "List of partitions to add to the partition table";
};
@ -21,21 +65,43 @@
readOnly = true;
type = lib.types.functionTo diskoLib.jsonType;
default = dev:
diskoLib.deepMergeMap (partition: partition._meta dev) config.partitions;
lib.foldr lib.recursiveUpdate {} (lib.imap (index: partition:
lib.optionalAttrs (partition.content != null) (partition.content._meta dev)
) config.partitions);
description = "Metadata";
};
_create = diskoLib.mkCreateOption {
inherit config options;
default = { dev }: ''
parted -s ${dev} -- mklabel ${config.format}
${lib.concatMapStrings (partition: partition._create {inherit dev; type = config.format;} ) config.partitions}
${lib.concatStrings (lib.imap (index: partition: ''
${lib.optionalString (config.format == "gpt") ''
parted -s ${dev} -- mkpart ${partition.name} ${diskoLib.maybeStr partition.fs-type} ${partition.start} ${partition.end}
''}
${lib.optionalString (config.format == "msdos") ''
parted -s ${dev} -- mkpart ${partition.part-type} ${diskoLib.maybeStr partition.fs-type} ${diskoLib.maybeStr partition.fs-type} ${partition.start} ${partition.end}
''}
# ensure /dev/disk/by-path/..-partN exists before continuing
udevadm trigger --subsystem-match=block; udevadm settle
${lib.optionalString partition.bootable ''
parted -s ${dev} -- set ${toString index} boot on
''}
${lib.concatMapStringsSep "" (flag: ''
parted -s ${dev} -- set ${toString index} ${flag} on
'') partition.flags}
# ensure further operations can detect new partitions
udevadm trigger --subsystem-match=block; udevadm settle
${lib.optionalString (partition.content != null) (partition.content._create { dev = diskoLib.deviceNumbering dev index; })}
'') config.partitions)}
'';
};
_mount = diskoLib.mkMountOption {
inherit config options;
default = { dev }:
let
partMounts = diskoLib.deepMergeMap (partition: partition._mount { inherit dev; }) config.partitions;
partMounts = lib.foldr lib.recursiveUpdate {} (lib.imap (index: partition:
lib.optionalAttrs (partition.content != null) (partition.content._mount { dev = diskoLib.deviceNumbering dev index; })
) config.partitions);
in
{
dev = partMounts.dev or "";
@ -46,7 +112,9 @@
internal = true;
readOnly = true;
default = dev:
map (partition: partition._config dev) config.partitions;
lib.imap (index: partition:
lib.optional (partition.content != null) (partition.content._config (diskoLib.deviceNumbering dev index))
) config.partitions;
description = "NixOS configuration";
};
_pkgs = lib.mkOption {
@ -54,7 +122,9 @@
readOnly = true;
type = lib.types.functionTo (lib.types.listOf lib.types.package);
default = pkgs:
[ pkgs.parted pkgs.systemdMinimal ] ++ lib.flatten (map (partition: partition._pkgs pkgs) config.partitions);
[ pkgs.parted pkgs.systemdMinimal ] ++ lib.flatten (map (partition:
lib.optional (partition.content != null) (partition.content._pkgs pkgs)
) config.partitions);
description = "Packages";
};
};