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
1 changed files with 42 additions and 53 deletions

View File

@ -69,10 +69,8 @@ in
let
diskName = if disk.name != "" then "-${disk.name}" else "";
luksName = "crypt-${config.networking.hostName}${diskName}";
rootSize = 200; # size of the zfs partition if inside of lvm
vgName = "lvm-${config.networking.hostName}${diskName}";
zfs = {
size = if (!disk.withCeph) then "100%FREE" else "${toString rootSize}GiB";
size = "100%FREE";
content = {
pool = zfsName;
type = "zfs";
@ -87,50 +85,45 @@ in
content = {
type = "table";
format = "gpt";
partitions = lib.optional disk.withZfs
{
name = "ESP";
start = "1MiB";
end = "512MiB";
bootable = true;
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
};
} ++ [
partitions = lib.optional disk.withZfs {
name = "ESP";
start = "1MiB";
end = "512MiB";
bootable = true;
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
};
} ++ [
{
name = "root";
start = if disk.withZfs then "512MiB" else "1MiB";
end = "100%";
part-type = "primary";
content = lib.optionalAttrs disk.withLuks
{
type = "luks";
name = luksName;
# trim potential new lines to not have them in the password
keyFile = "tr -d '\n' </$PWD/keyFile";
content = {
type = "lvm_pv";
vg = vgName;
};
} // lib.optionalAttrs (!disk.withLuks) zfs.content;
content = lib.optionalAttrs disk.withLuks {
type = "luks";
name = luksName;
# trim potential new lines to not have them in the password
keyFile = "tr -d '\n' </$PWD/keyFile";
inherit (zfs) content;
} // 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} = {
type = "zpool";
rootFsOptions.acltype = "posixacl";
# -O
rootFsOptions = {
acltype = "posixacl";
compression = "zstd";
dnodesize = "auto";
normalization = "formD";
xattr = "sa";
};
# -o
options = {
ashift = "12";
autotrim = "on";
@ -141,25 +134,12 @@ in
inherit mountpoint;
options = {
canmount = "on";
compression = "zstd";
dnodesize = "auto";
normalization = "formD";
xattr = "sa";
inherit mountpoint;
};
type = "zfs_fs";
};
in
{
"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") {
datasetNoMount = {
mountpoint = null;
options = {
canmount = "off";
@ -167,11 +147,20 @@ in
};
type = "zfs_fs";
};
"nixos/nix" = dataset "/nix";
"nixos/nix/store" = lib.recursiveUpdate (dataset "/nix/store") {
in
{
"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";
};
"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
"reserved" = lib.recursiveUpdate (dataset "reserved") {
mountpoint = null;