disko: add option to format without luks

This commit is contained in:
Sandro - 2023-04-24 21:34:35 +02:00
parent ad86d6d59b
commit 6477422f89
Signed by: sandro
GPG Key ID: 3AF5A43A3EECC2E5
2 changed files with 121 additions and 120 deletions

View File

@ -2,60 +2,69 @@
, name ? "chaos"
, disk ? "/dev/sda1"
, enableCeph ? true
, enableZfs ? false
, enableLuks ? true
, enableZfs ? true
, ...
}:
assert lib.assertMsg (enableCeph || enableZfs) "Must enable ceph or zfs!";
assert lib.assertMsg (enableCeph -> enableLuks) "Ceph requires Luks!";
{
disko.devices = {
disk.${disk} = {
device = disk;
type = "disk";
content = {
type = "table";
format = "gpt";
partitions = lib.optional enableZfs
{
name = "ESP";
start = "1MiB";
end = "512MiB";
bootable = true;
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
};
}
++ [
{
name = "root";
start = if enableZfs then "512MiB" else "1MiB";
end = "100%";
part-type = "primary";
content = {
type = "luks";
name = "crypt-${name}";
# TODO: add password, otherwise prompt opens
keyFile = "/$PWD/keyFile";
content = {
type = "lvm_pv";
vg = "lvm-${name}";
};
};
}
];
disko.devices =
let
rootSize = 200;
zfs = {
size = if (!enableCeph) then "100%FREE" else "${toString rootSize}GiB";
content = {
pool = name;
type = "zfs";
};
};
};
lvm_vg."lvm-${name}" = {
type = "lvm_vg";
lvs =
let
rootSize = 200;
in
lib.optionalAttrs enableCeph
in
{
disk.${disk} = {
device = disk;
type = "disk";
content = {
type = "table";
format = "gpt";
partitions = lib.optional enableZfs
{
name = "ESP";
start = "1MiB";
end = "512MiB";
bootable = true;
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
};
} ++ [
{
name = "root";
start = if enableZfs then "512MiB" else "1MiB";
end = "100%";
part-type = "primary";
content = lib.optionalAttrs enableLuks
{
type = "luks";
name = "crypt-${name}";
# TODO: add password, otherwise prompt opens
keyFile = "/$PWD/keyFile";
content = {
type = "lvm_pv";
vg = "lvm-${name}";
};
} // lib.optionalAttrs (!enableLuks) zfs.content;
}
];
};
};
} // lib.optionalAttrs enableLuks {
lvm_vg."lvm-${name}" = {
type = "lvm_vg";
lvs = lib.optionalAttrs enableCeph
{
# the header is 3650 byte long and substract an additional 446 byte for aligment
# error messages:
@ -71,74 +80,66 @@ assert lib.assertMsg (enableCeph || enableZfs) "Must enable ceph or zfs!";
bootOther = "-512-20";
in
"$((($(lsblk /dev/sda --noheadings --nodeps --output SIZE --bytes)-${toString rootSizeMiB})${roundToMiB}${bootOther}))MiB";
} // lib.optionalAttrs enableZfs {
zfs = {
size = if (!enableCeph) then "100%FREE" else "${toString rootSize}GiB";
content = {
pool = name;
type = "zfs";
};
};
};
};
zpool."${name}" = {
type = "zpool";
mountRoot = "/mnt";
rootFsOptions.acltype = "posixacl";
options = {
ashift = "12";
autotrim = "on";
} // lib.optionalAttrs enableZfs { inherit zfs; };
};
datasets =
let
dataset = mountpoint: {
options = {
canmount = "on";
compression = "zstd";
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" = {
options = {
canmount = "off";
mountpoint = "none";
};
type = "zfs_fs";
};
"nixos/nix" = dataset "/nix";
"nixos/nix/store" = {
options = {
atime = "off";
canmount = "on";
mountpoint = "/nix/store";
};
type = "zfs_fs";
};
"nixos/nix/var" = dataset "/nix/var";
"reserved" = {
# zfs uses copy on write and requires some free space to delete files when the disk is completely filled
options = {
canmount = "off";
mountpoint = "none";
reservation = "5GiB";
};
type = "zfs_fs";
};
} // {
zpool."${name}" = {
type = "zpool";
mountRoot = "/mnt";
rootFsOptions.acltype = "posixacl";
options = {
ashift = "12";
autotrim = "on";
};
datasets =
let
dataset = mountpoint: {
options = {
canmount = "on";
compression = "zstd";
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" = {
options = {
canmount = "off";
mountpoint = "none";
};
type = "zfs_fs";
};
"nixos/nix" = dataset "/nix";
"nixos/nix/store" = {
options = {
atime = "off";
canmount = "on";
mountpoint = "/nix/store";
};
type = "zfs_fs";
};
"nixos/nix/var" = dataset "/nix/var";
"reserved" = {
# zfs uses copy on write and requires some free space to delete files when the disk is completely filled
options = {
canmount = "off";
mountpoint = "none";
reservation = "5GiB";
};
type = "zfs_fs";
};
};
};
};
};
}

View File

@ -1,6 +1,6 @@
#!/usr/bin/env bash
ceph=true zfs=true
ceph=true luks=true zfs=true
while [[ $# -gt 0 ]]; do
case "$1" in
@ -17,8 +17,9 @@ while [[ $# -gt 0 ]]; do
name=$2
shift
;;
"--no-ceph") ceph=false ;;
"--no-zfs") zfs=false ;;
"--no-ceph") ceph=false;;
"--no-luks") luks=false;;
"--no-zfs") zfs=false ;;
*)
echo "Argument $1 is not understood."
exit 2
@ -32,8 +33,7 @@ if [[ -z ${disk:-} || -z ${name:-} ]]; then
exit 1
fi
# TODO: wait for https://github.com/nix-community/disko/pull/211 to be merged
sudo nix run github:SuperSandro2000/disko/zpool-R -- --mode zap_create ./disko-config.nix --debug \
sudo nix run github:SuperSandro2000/disko/zpool-R -- --mode zap_create_mount ./disko-config.nix --debug \
--arg disk '"'"$disk"'"' --arg name '"'"$name"'"' \
--arg enableCeph "$ceph" --arg enableZfs "$zfs"
--arg enableCeph "$ceph" --arg enableLuks "$luks" --arg enableZfs "$zfs"