Skip to content

Commit

Permalink
modules (disko): Add options to specify a storage disk
Browse files Browse the repository at this point in the history
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 britter/home-lab@af0a72d
  • Loading branch information
britter committed Jul 9, 2024
1 parent 9803b45 commit 7afe934
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 9 deletions.
23 changes: 20 additions & 3 deletions modules/nixos/disko/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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";
};
Expand All @@ -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
Expand All @@ -32,7 +44,7 @@ in {
(lib.mkIf efi {
disko.devices =
(import ./btrfs-luks.nix {
device = cfg.disk;
device = cfg.bootDisk;
inherit (cfg) swapSize;
})
.disko
Expand All @@ -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;
Expand Down
29 changes: 28 additions & 1 deletion modules/nixos/disko/ext-mbr.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
};
};
};
};
};
};
}
2 changes: 1 addition & 1 deletion systems/x86_64-linux/cyberoffice/configuration.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
acme.enable = true;
disko = {
enable = true;
disk = "/dev/sda";
bootDisk = "/dev/sda";
};
nextcloud.enable = true;
};
Expand Down
2 changes: 1 addition & 1 deletion systems/x86_64-linux/latitude-7280/configuration.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
modules = {
disko = {
enable = true;
disk = "/dev/sda";
bootDisk = "/dev/sda";
swapSize = "8GB";
};
};
Expand Down
2 changes: 1 addition & 1 deletion systems/x86_64-linux/pulse-14/configuration.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
modules = {
disko = {
enable = true;
disk = "/dev/nvme0n1";
bootDisk = "/dev/nvme0n1";
swapSize = "32GB";
};
};
Expand Down
6 changes: 5 additions & 1 deletion systems/x86_64-linux/warehouse/configuration.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
};
};
};
};
Expand Down
2 changes: 1 addition & 1 deletion systems/x86_64-linux/watchtower/configuration.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
modules = {
disko = {
enable = true;
disk = "/dev/sda";
bootDisk = "/dev/sda";
};
grafana.enable = true;
monitoring.openFirewall = false;
Expand Down

0 comments on commit 7afe934

Please sign in to comment.