disko.nix 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. { lib, ... }:
  2. let
  3. mainDiskId = "nvme-KINGSTON_SNV3S1000G_50026B7383CC0908";
  4. storageDisks = [
  5. "ata-ST8000VN002-2ZM188_WPV023WG"
  6. "ata-ST8000VN002-2ZM188_WPV07RMA"
  7. "ata-ST8000VN002-2ZM188_WPV020CG"
  8. ];
  9. # Subvolumes with regular CoW behavior
  10. regular = [ "root" "home" "nix" "persist" "logs" "services" ];
  11. # Subvolumes that need noDataCow for performance
  12. noDataCow = [ "databases" "cache" "containers" ];
  13. # Function to create subvolume configuration
  14. mkSubvolume = name: {
  15. name = "@${name}";
  16. value = {
  17. mountpoint = if name == "root" then "/" else "/${name}";
  18. mountOptions = [
  19. "compress=zstd:1"
  20. "noatime"
  21. ] ++ lib.optional (lib.elem name noDataCow) "nodatacow";
  22. };
  23. };
  24. in
  25. {
  26. disko.devices = {
  27. disk = {
  28. # Root system drive (1TB NVMe)
  29. main = {
  30. type = "disk";
  31. device = "/dev/disk/by-id/${mainDiskId}";
  32. content = {
  33. type = "gpt";
  34. partitions = {
  35. # EFI boot partition
  36. efi = {
  37. size = "1G";
  38. type = "EF00";
  39. content = {
  40. type = "filesystem";
  41. format = "vfat";
  42. mountpoint = "/boot";
  43. };
  44. };
  45. # Main Btrfs partition
  46. root = {
  47. end = "-0";
  48. content = {
  49. type = "btrfs";
  50. extraArgs = [ "-f" ];
  51. subvolumes = {
  52. # Blank root template for ephemeral setup
  53. "@root-blank" = { };
  54. } // lib.listToAttrs (map mkSubvolume (regular ++ noDataCow));
  55. };
  56. };
  57. };
  58. };
  59. };
  60. } // lib.listToAttrs (lib.imap1
  61. (i: diskId: {
  62. name = "storage${toString i}";
  63. value = {
  64. type = "disk";
  65. device = "/dev/disk/by-id/${diskId}";
  66. content = {
  67. type = "gpt";
  68. partitions = {
  69. primary = {
  70. size = "100%";
  71. content = {
  72. type = "filesystem";
  73. format = "xfs";
  74. mountpoint = "/mnt/disk${toString i}";
  75. mountOptions = [ "defaults" "noatime" ];
  76. };
  77. };
  78. };
  79. };
  80. };
  81. })
  82. storageDisks);
  83. };
  84. }