Skip to content

Commit eef1b08

Browse files
MartinNikovPetarKirov
authored andcommitted
config(mcl-disko): Add ext4 primary partition type
1 parent 4daa7fb commit eef1b08

File tree

7 files changed

+254
-165
lines changed

7 files changed

+254
-165
lines changed

modules/mcl-disko/default.nix

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,19 @@
1818
options.mcl.disko = {
1919
enable = mkEnableOption "Enable Module";
2020

21-
legacyBoot = mkOption {
22-
type = types.bool;
23-
default = false;
24-
example = true;
25-
description = "Declare if the configuration is for a Hetzner server or not";
21+
partitioningPreset = mkOption {
22+
type = types.enum [
23+
"zfs"
24+
"zfs-legacy-boot"
25+
"ext4"
26+
];
27+
default = "zfs";
28+
example = "zfs-legacy-boot";
29+
description = "Declare the type of the primary partition";
2630
};
2731

2832
swapSize = mkOption {
29-
type = types.str;
33+
type = types.nullOr types.str;
3034
default = "32G";
3135
example = "32768M";
3236
description = "The size of the hard disk space used when RAM is full";
@@ -140,7 +144,7 @@
140144

141145
config.disko =
142146
let
143-
makePrimaryZfsDisk = import ./primaryZfsPartition.nix;
147+
makePrimaryZfsDisk = import ./primaryPartition;
144148
makeSecondaryZfsDisk = import ./secondaryZfsPartition.nix;
145149

146150
first = builtins.head cfg.disks;
@@ -159,7 +163,7 @@
159163
isSecondary = true;
160164
espSize = cfg.espSize;
161165
swapSize = cfg.swapSize;
162-
legacyBoot = cfg.legacyBoot;
166+
partitioningPreset = cfg.partitioningPreset;
163167
poolName = cfg.zpool.name;
164168
}
165169
else
@@ -180,14 +184,15 @@
180184
isSecondary = false;
181185
espSize = cfg.espSize;
182186
swapSize = cfg.swapSize;
183-
legacyBoot = cfg.legacyBoot;
187+
partitioningPreset = cfg.partitioningPreset;
184188
poolName = cfg.zpool.name;
185189
};
186190
};
187191
zpool = import ./zpool.nix {
188192
poolName = cfg.zpool.name;
189193
poolMode = cfg.zpool.mode;
190194
poolExtraDatasets = cfg.zpool.extraDatasets;
195+
partitioningPreset = cfg.partitioningPreset;
191196
inherit lib;
192197
};
193198
};
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
lib,
3+
disk,
4+
isSecondary,
5+
espSize,
6+
swapSize,
7+
partitioningPreset,
8+
poolName,
9+
}:
10+
{
11+
type = "disk";
12+
device = disk;
13+
content = {
14+
type = if partitioningPreset == "zfs-legacy-boot" then "table" else "gpt";
15+
partitions =
16+
if partitioningPreset == "zfs-legacy-boot" then
17+
import ./zfs-legacy-boot.nix {
18+
inherit
19+
lib
20+
isSecondary
21+
espSize
22+
swapSize
23+
poolName
24+
;
25+
}
26+
else if partitioningPreset == "ext4" then
27+
import ./ext4.nix { inherit lib espSize swapSize; }
28+
else
29+
import ./zfs.nix {
30+
inherit
31+
lib
32+
disk
33+
isSecondary
34+
espSize
35+
swapSize
36+
poolName
37+
;
38+
};
39+
}
40+
// lib.optionalAttrs (partitioningPreset == "zfs-legacy-boot") {
41+
format = "gpt";
42+
};
43+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
lib,
3+
espSize,
4+
swapSize,
5+
}:
6+
{
7+
ESP = {
8+
priority = 0;
9+
type = "EF00";
10+
size = espSize;
11+
content = {
12+
type = "filesystem";
13+
format = "vfat";
14+
mountpoint = "/boot";
15+
mountOptions = [ "umask=0077" ];
16+
};
17+
};
18+
nixos = {
19+
priority = 1;
20+
start = espSize;
21+
end = if swapSize != null then "-${swapSize}" else "100%";
22+
content = {
23+
type = "filesystem";
24+
format = "ext4";
25+
mountpoint = "/";
26+
};
27+
};
28+
29+
}
30+
// lib.optionalAttrs (swapSize != null) {
31+
"swap" = {
32+
priority = 2;
33+
size = swapSize;
34+
content = {
35+
type = "swap";
36+
randomEncryption = true;
37+
};
38+
};
39+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
lib,
3+
isSecondary,
4+
espSize,
5+
swapSize,
6+
poolName,
7+
}:
8+
[
9+
{
10+
name = "boot";
11+
start = "1MiB";
12+
end = "2MiB";
13+
part-type = "primary";
14+
flags = [ "bios_grub" ];
15+
}
16+
{
17+
name = "ESP";
18+
start = "2MiB";
19+
end = espSize;
20+
bootable = true;
21+
content = {
22+
type = "filesystem";
23+
format = "vfat";
24+
mountpoint = if isSecondary then null else "/boot";
25+
};
26+
}
27+
{
28+
name = "zfs";
29+
start = espSize;
30+
end = if swapSize != null then "-${swapSize}" else "100%";
31+
part-type = "primary";
32+
content = {
33+
type = "zfs";
34+
pool = "${poolName}";
35+
};
36+
}
37+
]
38+
++ lib.optionals (swapSize != null) [
39+
{
40+
name = "swap";
41+
start = "-${swapSize}";
42+
end = "100%";
43+
part-type = "primary";
44+
content = {
45+
type = "swap";
46+
randomEncryption = true;
47+
};
48+
}
49+
]
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
lib,
3+
disk,
4+
isSecondary,
5+
espSize,
6+
swapSize,
7+
poolName,
8+
}:
9+
{
10+
"ESP" = {
11+
priority = 0;
12+
device = "${disk}-part1";
13+
size = espSize;
14+
type = "EF00";
15+
content = {
16+
type = "filesystem";
17+
format = "vfat";
18+
mountpoint = if isSecondary then null else "/boot";
19+
mountOptions = [ "umask=0077" ];
20+
};
21+
};
22+
23+
"zfs" = {
24+
priority = 1;
25+
device = "${disk}-part2";
26+
end = if swapSize != null then "-${swapSize}" else "100%";
27+
type = "BF00";
28+
content = {
29+
type = "zfs";
30+
pool = "${poolName}";
31+
};
32+
};
33+
}
34+
// lib.optionalAttrs (swapSize != null) {
35+
"swap" = {
36+
priority = 2;
37+
device = "${disk}-part3";
38+
size = swapSize;
39+
content = {
40+
type = "swap";
41+
randomEncryption = true;
42+
};
43+
};
44+
}

modules/mcl-disko/primaryZfsPartition.nix

Lines changed: 0 additions & 94 deletions
This file was deleted.

0 commit comments

Comments
 (0)