diff --git a/nixos/machines/default.nix b/nixos/machines/default.nix index a8d14c3..dfadb75 100644 --- a/nixos/machines/default.nix +++ b/nixos/machines/default.nix @@ -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 = { diff --git a/nixos/modules/backups.nix b/nixos/modules/backups.nix index 11d838d..977159a 100644 --- a/nixos/modules/backups.nix +++ b/nixos/modules/backups.nix @@ -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. diff --git a/nixos/modules/data-disk.nix b/nixos/modules/data-disk.nix deleted file mode 100644 index e4bb6d3..0000000 --- a/nixos/modules/data-disk.nix +++ /dev/null @@ -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; }; - }; -} diff --git a/nixos/modules/default.nix b/nixos/modules/default.nix index dbd248e..71fef6b 100644 --- a/nixos/modules/default.nix +++ b/nixos/modules/default.nix @@ -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 diff --git a/nixos/modules/disko.nix b/nixos/modules/disko.nix deleted file mode 100644 index 58f5cc6..0000000 --- a/nixos/modules/disko.nix +++ /dev/null @@ -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%"; }; - }; - }; - }; -} diff --git a/nixos/modules/storage.nix b/nixos/modules/storage.nix new file mode 100644 index 0000000..f01b665 --- /dev/null +++ b/nixos/modules/storage.nix @@ -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 = "/"; + }; + }; + }; + }; + }; + }; +} diff --git a/nixos/modules/terraform-database/default.nix b/nixos/modules/terraform-database/default.nix index 4cf6f82..db68f34 100644 --- a/nixos/modules/terraform-database/default.nix +++ b/nixos/modules/terraform-database/default.nix @@ -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