lib/disko: add cleaner functions and handle inner partitions

This commit is contained in:
Infinidoge 2024-11-23 09:30:38 -05:00
parent c64238a3da
commit 870894841f
No known key found for this signature in database

View file

@ -1,7 +1,7 @@
{ lib }: { lib }:
let let
inherit (builtins) mapAttrs removeAttrs; inherit (builtins) mapAttrs removeAttrs;
inherit (lib) optionals; inherit (lib) optionals flip genAttrs;
in in
rec { rec {
# Constants # Constants
@ -40,13 +40,14 @@ rec {
# btrfs # btrfs
mkBtrfsPart = size: mountpoint: content: { mkBtrfsPart' = base: mountpoint: content': {
inherit size;
content = { content = {
inherit mountpoint; inherit mountpoint;
type = "btrfs"; type = "btrfs";
} // content; } // content';
}; } // base;
mkBtrfsPart = size: mkBtrfsPart' { inherit size; };
mkBtrfsPartEndAt = end: mkBtrfsPart' { inherit end; };
mkBtrfsSubvols' = mountOptions: mapAttrs (n: v: { mkBtrfsSubvols' = mountOptions: mapAttrs (n: v: {
mountpoint = n; mountpoint = n;
@ -56,13 +57,14 @@ rec {
# ZFS # ZFS
mkZPart = size: pool: { mkZPart' = base: content: pool: {
inherit size;
content = { content = {
type = "zfs"; type = "zfs";
inherit pool; inherit pool;
}; } // content;
}; } // base;
mkZPart = size: mkZPart' { inherit size; } { };
mkZPartEndAt = end: mkZPart' { inherit end; } { };
mkZDisk = id: pool: mkDisk id { mkZDisk = id: pool: mkDisk id {
partitions = { partitions = {
@ -82,6 +84,7 @@ rec {
inherit mountOptions; inherit mountOptions;
} // options; } // options;
mkZPool = mkZPool' defaultMountOptions; mkZPool = mkZPool' defaultMountOptions;
mkZPools = mapAttrs mkZPool;
mkZfs' = mountOptions: mountpoint: options: { mkZfs' = mountOptions: mountpoint: options: {
type = "zfs_fs"; type = "zfs_fs";
@ -94,4 +97,6 @@ rec {
type = "zfs_volume"; type = "zfs_volume";
inherit size content; inherit size content;
}; };
markNeededForBoot = flip genAttrs (_: { neededForBoot = true; });
} }