disko: remove lvm, cleanup datasets, move zfs options to zpool

This commit is contained in:
Sandro - 2023-12-25 01:53:43 +01:00
parent 55e30d758f
commit 86b0aecdf4
Signed by: sandro
GPG Key ID: 3AF5A43A3EECC2E5

View File

@ -69,10 +69,8 @@ in
let let
diskName = if disk.name != "" then "-${disk.name}" else ""; diskName = if disk.name != "" then "-${disk.name}" else "";
luksName = "crypt-${config.networking.hostName}${diskName}"; luksName = "crypt-${config.networking.hostName}${diskName}";
rootSize = 200; # size of the zfs partition if inside of lvm
vgName = "lvm-${config.networking.hostName}${diskName}";
zfs = { zfs = {
size = if (!disk.withCeph) then "100%FREE" else "${toString rootSize}GiB"; size = "100%FREE";
content = { content = {
pool = zfsName; pool = zfsName;
type = "zfs"; type = "zfs";
@ -87,50 +85,45 @@ in
content = { content = {
type = "table"; type = "table";
format = "gpt"; format = "gpt";
partitions = lib.optional disk.withZfs partitions = lib.optional disk.withZfs {
{ name = "ESP";
name = "ESP"; start = "1MiB";
start = "1MiB"; end = "512MiB";
end = "512MiB"; bootable = true;
bootable = true; content = {
content = { type = "filesystem";
type = "filesystem"; format = "vfat";
format = "vfat"; mountpoint = "/boot";
mountpoint = "/boot"; };
}; } ++ [
} ++ [
{ {
name = "root"; name = "root";
start = if disk.withZfs then "512MiB" else "1MiB"; start = if disk.withZfs then "512MiB" else "1MiB";
end = "100%"; end = "100%";
part-type = "primary"; part-type = "primary";
content = lib.optionalAttrs disk.withLuks content = lib.optionalAttrs disk.withLuks {
{ type = "luks";
type = "luks"; name = luksName;
name = luksName; # trim potential new lines to not have them in the password
# trim potential new lines to not have them in the password keyFile = "tr -d '\n' </$PWD/keyFile";
keyFile = "tr -d '\n' </$PWD/keyFile"; inherit (zfs) content;
content = { } // lib.optionalAttrs (!disk.withLuks) zfs.content;
type = "lvm_pv";
vg = vgName;
};
} // lib.optionalAttrs (!disk.withLuks) zfs.content;
} }
]; ];
}; };
}; };
} // lib.optionalAttrs disk.withLuks {
lvm_vg.${vgName} = {
type = "lvm_vg";
lvs = lib.optionalAttrs disk.withCeph
{
ceph.size = "100%FREE";
} // lib.optionalAttrs disk.withZfs { inherit zfs; };
};
} // { } // {
zpool.${zfsName} = { zpool.${zfsName} = {
type = "zpool"; type = "zpool";
rootFsOptions.acltype = "posixacl"; # -O
rootFsOptions = {
acltype = "posixacl";
compression = "zstd";
dnodesize = "auto";
normalization = "formD";
xattr = "sa";
};
# -o
options = { options = {
ashift = "12"; ashift = "12";
autotrim = "on"; autotrim = "on";
@ -141,25 +134,12 @@ in
inherit mountpoint; inherit mountpoint;
options = { options = {
canmount = "on"; canmount = "on";
compression = "zstd";
dnodesize = "auto";
normalization = "formD";
xattr = "sa";
inherit mountpoint; inherit mountpoint;
}; };
type = "zfs_fs"; type = "zfs_fs";
}; };
in
{ datasetNoMount = {
"data" = dataset "/";
"data/etc" = dataset "/etc";
"data/home" = dataset "/home";
"data/var" = dataset "/var";
# used by services.postgresqlBackup and later by restic
"data/var/backup" = dataset "/var/backup";
"data/var/lib" = dataset "/var/lib";
"data/var/log" = dataset "/var/log";
"nixos" = lib.recursiveUpdate (dataset "nixos") {
mountpoint = null; mountpoint = null;
options = { options = {
canmount = "off"; canmount = "off";
@ -167,11 +147,20 @@ in
}; };
type = "zfs_fs"; type = "zfs_fs";
}; };
"nixos/nix" = dataset "/nix"; in
"nixos/nix/store" = lib.recursiveUpdate (dataset "/nix/store") { {
"root" = dataset "/";
"data" = datasetNoMount;
# used by services.postgresqlBackup and later by restic
"data/backup" = dataset "/var/backup";
"data/etc" = dataset "/etc";
"data/lib" = dataset "/var/lib";
"home" = dataset "/home";
"nix" = lib.recursiveUpdate (dataset "/nix") {
options.atime = "off"; options.atime = "off";
}; };
"nixos/nix/var" = dataset "/nix/var"; "nix/store" = dataset "/nix/store";
"nix/var" = dataset "/nix/var";
# zfs uses copy on write and requires some free space to delete files when the disk is completely filled # zfs uses copy on write and requires some free space to delete files when the disk is completely filled
"reserved" = lib.recursiveUpdate (dataset "reserved") { "reserved" = lib.recursiveUpdate (dataset "reserved") {
mountpoint = null; mountpoint = null;