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,14 +2,27 @@
, 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 = {
disko.devices =
let
rootSize = 200;
zfs = {
size = if (!enableCeph) then "100%FREE" else "${toString rootSize}GiB";
content = {
pool = name;
type = "zfs";
};
};
in
{
disk.${disk} = {
device = disk;
type = "disk";
@ -27,14 +40,14 @@ assert lib.assertMsg (enableCeph || enableZfs) "Must enable ceph or zfs!";
format = "vfat";
mountpoint = "/boot";
};
}
++ [
} ++ [
{
name = "root";
start = if enableZfs then "512MiB" else "1MiB";
end = "100%";
part-type = "primary";
content = {
content = lib.optionalAttrs enableLuks
{
type = "luks";
name = "crypt-${name}";
# TODO: add password, otherwise prompt opens
@ -43,19 +56,15 @@ assert lib.assertMsg (enableCeph || enableZfs) "Must enable ceph or zfs!";
type = "lvm_pv";
vg = "lvm-${name}";
};
};
} // lib.optionalAttrs (!enableLuks) zfs.content;
}
];
};
};
} // lib.optionalAttrs enableLuks {
lvm_vg."lvm-${name}" = {
type = "lvm_vg";
lvs =
let
rootSize = 200;
in
lib.optionalAttrs enableCeph
lvs = lib.optionalAttrs enableCeph
{
# the header is 3650 byte long and substract an additional 446 byte for aligment
# error messages:
@ -71,17 +80,9 @@ 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";
} // lib.optionalAttrs enableZfs { inherit zfs; };
};
};
};
};
} // {
zpool."${name}" = {
type = "zpool";
mountRoot = "/mnt";

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
@ -18,6 +18,7 @@ while [[ $# -gt 0 ]]; do
shift
;;
"--no-ceph") ceph=false;;
"--no-luks") luks=false;;
"--no-zfs") zfs=false ;;
*)
echo "Argument $1 is not understood."
@ -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"