From 7afe934d0671b77951cb9c950c26ee6c4893ee4e Mon Sep 17 00:00:00 2001 From: Benedikt Ritter Date: Tue, 9 Jul 2024 16:34:46 +0200 Subject: [PATCH] modules (disko): Add options to specify a storage disk It turns out that using a boot disk of size 6TB causes proxmos VMs to hang indefinitely. For that reason, I'm no creating a secondary storage disk and format them using btrfs where each subvolume is configured for a dataDir of a service that requires storage. See also https://github.com/britter/home-lab/commit/af0a72d80637c6da1c80c27f217cb9b4edf6b9c7 --- modules/nixos/disko/default.nix | 23 +++++++++++++-- modules/nixos/disko/ext-mbr.nix | 29 ++++++++++++++++++- .../cyberoffice/configuration.nix | 2 +- .../latitude-7280/configuration.nix | 2 +- .../x86_64-linux/pulse-14/configuration.nix | 2 +- .../x86_64-linux/warehouse/configuration.nix | 6 +++- .../x86_64-linux/watchtower/configuration.nix | 2 +- 7 files changed, 57 insertions(+), 9 deletions(-) diff --git a/modules/nixos/disko/default.nix b/modules/nixos/disko/default.nix index e29db9a..8af1c1e 100644 --- a/modules/nixos/disko/default.nix +++ b/modules/nixos/disko/default.nix @@ -13,7 +13,7 @@ in { options.my.modules.disko = { enable = lib.mkEnableOption "disko"; - disk = lib.mkOption { + bootDisk = lib.mkOption { type = lib.types.str; description = "Disk to install to"; }; @@ -22,6 +22,18 @@ in { description = "Size of the swap partition"; default = null; }; + storageDisk = { + disk = lib.mkOption { + type = lib.types.nullOr lib.types.str; + description = "Disk to use for storage"; + default = null; + }; + subvolumes = lib.mkOption { + type = lib.types.listOf lib.types.str; + description = "Mount points of the storage disk subvolumes"; + default = []; + }; + }; }; config = let @@ -32,7 +44,7 @@ in { (lib.mkIf efi { disko.devices = (import ./btrfs-luks.nix { - device = cfg.disk; + device = cfg.bootDisk; inherit (cfg) swapSize; }) .disko @@ -46,7 +58,12 @@ in { (lib.mkIf mbr { disko.devices = (import ./ext-mbr.nix { - device = cfg.disk; + device = cfg.bootDisk; + storageDisk = { + inherit (cfg.storageDisk) disk; + inherit (cfg.storageDisk) subvolumes; + }; + inherit lib; }) .disko .devices; diff --git a/modules/nixos/disko/ext-mbr.nix b/modules/nixos/disko/ext-mbr.nix index 204dd93..e34d393 100644 --- a/modules/nixos/disko/ext-mbr.nix +++ b/modules/nixos/disko/ext-mbr.nix @@ -2,7 +2,12 @@ # By default Proxmox uses SeaBIOS to boot VMs and that required legacy # boot using MBR. # This is taken from https://github.com/nix-community/disko/blob/9d5c673a6611b7bf448dbfb0843c75b9cce9cf1f/example/gpt-bios-compat.nix -{device ? throw "Set this to your disk device, e.g. /dev/sda", ...}: { +{ + device ? throw "Set this to your disk device, e.g. /dev/sda", + storageDisk, + lib, + ... +}: { disko.devices = { disk.main = { inherit device; @@ -26,5 +31,27 @@ }; }; }; + disk.storage = lib.mkIf (storageDisk.disk != null) { + device = storageDisk.disk; + type = "disk"; + content = { + type = "gpt"; + partitions = { + storage = { + size = "100%"; + content = { + type = "btrfs"; + subvolumes = lib.mkMerge (lib.map (v: { + ${v} = { + mountpoint = "${v}"; + mountOptions = ["noatime"]; + }; + }) + storageDisk.subvolumes); + }; + }; + }; + }; + }; }; } diff --git a/systems/x86_64-linux/cyberoffice/configuration.nix b/systems/x86_64-linux/cyberoffice/configuration.nix index eccf6ea..76ee770 100644 --- a/systems/x86_64-linux/cyberoffice/configuration.nix +++ b/systems/x86_64-linux/cyberoffice/configuration.nix @@ -13,7 +13,7 @@ acme.enable = true; disko = { enable = true; - disk = "/dev/sda"; + bootDisk = "/dev/sda"; }; nextcloud.enable = true; }; diff --git a/systems/x86_64-linux/latitude-7280/configuration.nix b/systems/x86_64-linux/latitude-7280/configuration.nix index d61dcdd..af60261 100644 --- a/systems/x86_64-linux/latitude-7280/configuration.nix +++ b/systems/x86_64-linux/latitude-7280/configuration.nix @@ -16,7 +16,7 @@ modules = { disko = { enable = true; - disk = "/dev/sda"; + bootDisk = "/dev/sda"; swapSize = "8GB"; }; }; diff --git a/systems/x86_64-linux/pulse-14/configuration.nix b/systems/x86_64-linux/pulse-14/configuration.nix index 49e93d8..103e672 100644 --- a/systems/x86_64-linux/pulse-14/configuration.nix +++ b/systems/x86_64-linux/pulse-14/configuration.nix @@ -20,7 +20,7 @@ modules = { disko = { enable = true; - disk = "/dev/nvme0n1"; + bootDisk = "/dev/nvme0n1"; swapSize = "32GB"; }; }; diff --git a/systems/x86_64-linux/warehouse/configuration.nix b/systems/x86_64-linux/warehouse/configuration.nix index 0bede96..dbdeef7 100644 --- a/systems/x86_64-linux/warehouse/configuration.nix +++ b/systems/x86_64-linux/warehouse/configuration.nix @@ -12,7 +12,11 @@ modules = { disko = { enable = true; - disk = "/dev/sda"; + bootDisk = "/dev/sda"; + storageDisk = { + disk = "/dev/sdb"; + subvolumes = ["/var/lib/minio" "/var/lib/postgres"]; + }; }; }; }; diff --git a/systems/x86_64-linux/watchtower/configuration.nix b/systems/x86_64-linux/watchtower/configuration.nix index 1d3201c..eb3429e 100644 --- a/systems/x86_64-linux/watchtower/configuration.nix +++ b/systems/x86_64-linux/watchtower/configuration.nix @@ -12,7 +12,7 @@ modules = { disko = { enable = true; - disk = "/dev/sda"; + bootDisk = "/dev/sda"; }; grafana.enable = true; monitoring.openFirewall = false;