Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions modules/mcl-disko/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,19 @@
options.mcl.disko = {
enable = mkEnableOption "Enable Module";

legacyBoot = mkOption {
type = types.bool;
default = false;
example = true;
description = "Declare if the configuration is for a Hetzner server or not";
partitioningPreset = mkOption {
type = types.enum [
"zfs"
"zfs-legacy-boot"
"ext4"
];
default = "zfs";
example = "zfs-legacy-boot";
description = "Declare the type of the primary partition";
};

swapSize = mkOption {
type = types.str;
type = types.nullOr types.str;
default = "32G";
example = "32768M";
description = "The size of the hard disk space used when RAM is full";
Expand Down Expand Up @@ -140,7 +144,7 @@

config.disko =
let
makePrimaryZfsDisk = import ./primaryZfsPartition.nix;
makePrimaryZfsDisk = import ./primaryPartition;
makeSecondaryZfsDisk = import ./secondaryZfsPartition.nix;

first = builtins.head cfg.disks;
Expand All @@ -159,7 +163,7 @@
isSecondary = true;
espSize = cfg.espSize;
swapSize = cfg.swapSize;
legacyBoot = cfg.legacyBoot;
partitioningPreset = cfg.partitioningPreset;
poolName = cfg.zpool.name;
}
else
Expand All @@ -180,14 +184,15 @@
isSecondary = false;
espSize = cfg.espSize;
swapSize = cfg.swapSize;
legacyBoot = cfg.legacyBoot;
partitioningPreset = cfg.partitioningPreset;
poolName = cfg.zpool.name;
};
};
zpool = import ./zpool.nix {
poolName = cfg.zpool.name;
poolMode = cfg.zpool.mode;
poolExtraDatasets = cfg.zpool.extraDatasets;
partitioningPreset = cfg.partitioningPreset;
inherit lib;
};
};
Expand Down
43 changes: 43 additions & 0 deletions modules/mcl-disko/primaryPartition/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
lib,
disk,
isSecondary,
espSize,
swapSize,
partitioningPreset,
poolName,
}:
{
type = "disk";
device = disk;
content = {
type = if partitioningPreset == "zfs-legacy-boot" then "table" else "gpt";
partitions =
if partitioningPreset == "zfs-legacy-boot" then
import ./zfs-legacy-boot.nix {
inherit
lib
isSecondary
espSize
swapSize
poolName
;
}
else if partitioningPreset == "ext4" then
import ./ext4.nix { inherit lib espSize swapSize; }
else
import ./zfs.nix {
inherit
lib
disk
isSecondary
espSize
swapSize
poolName
;
};
}
// lib.optionalAttrs (partitioningPreset == "zfs-legacy-boot") {
format = "gpt";
};
}
39 changes: 39 additions & 0 deletions modules/mcl-disko/primaryPartition/ext4.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
lib,
espSize,
swapSize,
}:
{
ESP = {
priority = 0;
type = "EF00";
size = espSize;
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
mountOptions = [ "umask=0077" ];
};
};
nixos = {
priority = 1;
start = espSize;
end = if swapSize != null then "-${swapSize}" else "100%";
content = {
type = "filesystem";
format = "ext4";
mountpoint = "/";
};
};

}
// lib.optionalAttrs (swapSize != null) {
"swap" = {
priority = 2;
size = swapSize;
content = {
type = "swap";
randomEncryption = true;
};
};
}
49 changes: 49 additions & 0 deletions modules/mcl-disko/primaryPartition/zfs-legacy-boot.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
lib,
isSecondary,
espSize,
swapSize,
poolName,
}:
[
{
name = "boot";
start = "1MiB";
end = "2MiB";
part-type = "primary";
flags = [ "bios_grub" ];
}
{
name = "ESP";
start = "2MiB";
end = espSize;
bootable = true;
content = {
type = "filesystem";
format = "vfat";
mountpoint = if isSecondary then null else "/boot";
};
}
{
name = "zfs";
start = espSize;
end = if swapSize != null then "-${swapSize}" else "100%";
part-type = "primary";
content = {
type = "zfs";
pool = "${poolName}";
};
}
]
++ lib.optionals (swapSize != null) [
{
name = "swap";
start = "-${swapSize}";
end = "100%";
part-type = "primary";
content = {
type = "swap";
randomEncryption = true;
};
}
]
44 changes: 44 additions & 0 deletions modules/mcl-disko/primaryPartition/zfs.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
lib,
disk,
isSecondary,
espSize,
swapSize,
poolName,
}:
{
"ESP" = {
priority = 0;
device = "${disk}-part1";
size = espSize;
type = "EF00";
content = {
type = "filesystem";
format = "vfat";
mountpoint = if isSecondary then null else "/boot";
mountOptions = [ "umask=0077" ];
};
};

"zfs" = {
priority = 1;
device = "${disk}-part2";
end = if swapSize != null then "-${swapSize}" else "100%";
type = "BF00";
content = {
type = "zfs";
pool = "${poolName}";
};
};
}
// lib.optionalAttrs (swapSize != null) {
"swap" = {
priority = 2;
device = "${disk}-part3";
size = swapSize;
content = {
type = "swap";
randomEncryption = true;
};
};
}
94 changes: 0 additions & 94 deletions modules/mcl-disko/primaryZfsPartition.nix

This file was deleted.

Loading