merge modules into one storage module

This commit is contained in:
Pim Kunis 2024-01-07 00:22:44 +01:00
parent 997d9bb0cb
commit 2804e764f5
7 changed files with 80 additions and 93 deletions

View file

@ -5,11 +5,10 @@
nixosModule.lab = {
terraformDatabase.enable = true;
disko.osDiskDevice = "/dev/sda";
dataDisk = {
enable = true;
devicePath = "/dev/nvme0n1p1";
storage = {
osDisk = "/dev/sda";
dataPartition = "/dev/nvme0n1p1";
};
ssh = {
@ -25,11 +24,9 @@
hostName = "atlas.hyp";
nixosModule.lab = {
disko.osDiskDevice = "/dev/sda";
dataDisk = {
enable = true;
devicePath = "/dev/nvme0n1p1";
storage = {
osDisk = "/dev/sda";
dataPartition = "/dev/nvme0n1p1";
};
ssh = {
@ -45,12 +42,11 @@
hostName = "lewis.hyp";
nixosModule.lab = {
disko.osDiskDevice = "/dev/sda";
dataHost.enable = true;
dataDisk = {
enable = true;
devicePath = "/dev/nvme0n1p1";
storage = {
osDisk = "/dev/sda";
dataPartition = "/dev/nvme0n1p1";
};
ssh = {

View file

@ -48,8 +48,7 @@ in
};
repoLocation = lib.mkOption {
# TODO: maybe make sure data disk is enabled? is there an "ensure" method in nix?
default = "${config.lab.dataDisk.mountPoint}/backups/nfs.borg";
default = "${config.lab.storage.dataMountPoint}/backups/nfs.borg";
type = lib.types.str;
description = ''
Location of the Borg repository to back up to.
@ -57,7 +56,7 @@ in
};
subvolumeLocation = lib.mkOption {
default = "${config.lab.dataDisk.mountPoint}/nfs";
default = "${config.lab.storage.dataMountPoint}/nfs";
type = lib.types.str;
description = ''
Location of the btrfs subvolume holding the data.
@ -65,7 +64,7 @@ in
};
snapshotLocation = lib.mkOption {
default = "${config.lab.dataDisk.mountPoint}/nfs-backup";
default = "${config.lab.storage.dataMountPoint}/nfs-backup";
type = lib.types.str;
description = ''
Location to (temporary) create a snapshot of the subvolume.

View file

@ -1,33 +0,0 @@
{ lib, config, ... }:
let cfg = config.lab.dataDisk;
in {
options.lab.dataDisk = {
enable = lib.mkOption {
default = false;
type = lib.types.bool;
description = ''
Whether to automatically mount a disk to be used as a data disk.
'';
};
mountPoint = lib.mkOption {
default = "/mnt/data";
type = lib.types.str;
description = ''
Mount point of the data disk (if enabled).
'';
};
devicePath = lib.mkOption {
default = "/dev/sda1";
type = lib.types.str;
description = ''
Path of the device to be used as a data disk.
'';
};
};
config = lib.mkIf cfg.enable {
fileSystems.${cfg.mountPoint} = { device = cfg.devicePath; };
};
}

View file

@ -4,11 +4,10 @@ let cfg = config.lab.dataHost;
in
{
imports = [
./storage.nix
./terraform-database
./data-disk.nix
./ssh-certificates.nix
./k3s
./disko.nix
./backups.nix
./networking.nix
./data-sharing.nix

View file

@ -1,39 +0,0 @@
{ lib, config, ... }:
let cfg = config.lab.disko;
in {
options.lab.disko.osDiskDevice = lib.mkOption {
type = lib.types.str;
description = ''
The disk device to be used for the operating system.
'';
};
# TODO: rename this to 'osDisk'. Unfortunately, we would need to run nixos-anywhere again then
config.disko.devices.disk.vdb = {
device = cfg.osDiskDevice;
type = "disk";
content = {
type = "gpt";
partitions = {
ESP = {
type = "EF00";
size = "500M";
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
};
};
root = {
end = "-4G";
content = {
type = "filesystem";
format = "btrfs";
mountpoint = "/";
};
};
swap = { size = "100%"; };
};
};
};
}

66
nixos/modules/storage.nix Normal file
View file

@ -0,0 +1,66 @@
{ lib, config, ... }:
let cfg = config.lab.storage;
in {
options.lab.storage = {
osDisk = lib.mkOption {
type = lib.types.str;
description = ''
The disk to be used for the machine's operating system.
'';
};
dataPartition = lib.mkOption {
type = lib.types.str;
description = ''
Partition to be used for data storage on this machine.
'';
};
dataMountPoint = lib.mkOption {
default = "/mnt/data";
type = lib.types.str;
description = ''
Mount point of the machine's data partition.
'';
};
};
config = {
fileSystems.${cfg.dataMountPoint}.device = cfg.dataPartition;
# TODO: Rename this to 'osDisk'. Unfortunately, we would need to run nixos-anywhere again then.
disko.devices.disk.vdb = {
device = cfg.osDisk;
type = "disk";
content = {
type = "gpt";
partitions = {
swap.size = "100%";
ESP = {
type = "EF00";
size = "500M";
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
};
};
root = {
end = "-4G";
content = {
type = "filesystem";
format = "btrfs";
mountpoint = "/";
};
};
};
};
};
};
}

View file

@ -18,8 +18,7 @@ in {
package = pkgs.postgresql_15;
enableTCPIP = true;
dataDir = lib.mkIf config.lab.dataDisk.enable
"${config.lab.dataDisk.mountPoint}/postgresql/${config.services.postgresql.package.psqlSchema}";
dataDir = "${config.lab.storage.dataMountPoint}/postgresql/${config.services.postgresql.package.psqlSchema}";
authentication = ''
hostssl terraformstates terraform all cert