From 0d155fa5531f687cae0a9bdefe2a0757b9b8903b Mon Sep 17 00:00:00 2001
From: Dmitriy Kholkin <ataraxiadev@ataraxiadev.com>
Date: Mon, 10 Mar 2025 19:10:28 +0300
Subject: [PATCH] feat: add disko config for redshift

---
 hosts/redshift/default.nix     |   2 +
 hosts/redshift/disk-config.nix | 156 +++++++++++++++++++++++++++++++++
 2 files changed, 158 insertions(+)
 create mode 100644 hosts/redshift/disk-config.nix

diff --git a/hosts/redshift/default.nix b/hosts/redshift/default.nix
index 89c7303..79a4584 100644
--- a/hosts/redshift/default.nix
+++ b/hosts/redshift/default.nix
@@ -7,6 +7,8 @@
 {
   imports = [
     (modulesPath + "/profiles/qemu-guest.nix")
+
+    ./disk-config.nix
   ];
 
   ataraxia.defaults.role = "server";
diff --git a/hosts/redshift/disk-config.nix b/hosts/redshift/disk-config.nix
new file mode 100644
index 0000000..b72844e
--- /dev/null
+++ b/hosts/redshift/disk-config.nix
@@ -0,0 +1,156 @@
+{ inputs, ... }:
+{
+  imports = [ inputs.disko.nixosModules.disko ];
+
+  disko.devices.disk.disk1 =
+    let
+      device = "/dev/sda";
+    in
+    {
+      inherit device;
+      type = "disk";
+      content = {
+        type = "gpt";
+        partitions = {
+          boot = {
+            name = "boot";
+            size = "1M";
+            type = "EF02";
+          };
+          esp = {
+            name = "ESP";
+            size = "512M";
+            type = "EF00";
+            content = {
+              type = "filesystem";
+              format = "vfat";
+              mountpoint = "/boot";
+            };
+          };
+          swap = {
+            name = "swap";
+            size = "1G";
+            content = {
+              type = "swap";
+              randomEncryption = true;
+            };
+          };
+          root = {
+            name = "root";
+            size = "100%";
+            content = {
+              type = "btrfs";
+              extraArgs = [ "-f" ];
+              postCreateHook = ''
+                mount -t btrfs ${device}4 /mnt
+                btrfs subvolume snapshot -r /mnt/rootfs /mnt/snapshots/rootfs-blank
+                btrfs subvolume snapshot -r /mnt/homefs /mnt/snapshots/homefs-blank
+                btrfs subvolume snapshot -r /mnt/persist/docker /mnt/snapshots/docker-blank
+                btrfs subvolume snapshot -r /mnt/persist/podman /mnt/snapshots/podman-blank
+                btrfs subvolume snapshot -r /mnt/persist/containers /mnt/snapshots/containers-blank
+                btrfs subvolume snapshot -r /mnt/persist/libvirt /mnt/snapshots/libvirt-blank
+                btrfs subvolume snapshot -r /mnt/persist/log /mnt/snapshots/log-blank
+                btrfs subvolume snapshot -r /mnt/persist/impermanence /mnt/snapshots/impermanence-blank
+                btrfs subvolume snapshot -r /mnt/persist/srv /mnt/snapshots/srv-blank
+                umount /mnt
+              '';
+              subvolumes = {
+                "/snapshots" = { };
+                "/rootfs" = {
+                  mountpoint = "/";
+                  mountOptions = [
+                    "compress=zstd"
+                    "noatime"
+                    "autodefrag"
+                    "ssd"
+                  ];
+                };
+                "/homefs" = {
+                  mountpoint = "/home";
+                  mountOptions = [
+                    "compress=zstd"
+                    "noatime"
+                    "autodefrag"
+                    "ssd"
+                  ];
+                };
+                "/persist" = { };
+                "/persist/nix" = {
+                  mountpoint = "/nix";
+                  mountOptions = [
+                    "compress=zstd"
+                    "noatime"
+                    "autodefrag"
+                    "ssd"
+                  ];
+                };
+                "/persist/srv" = {
+                  mountpoint = "/srv";
+                  mountOptions = [
+                    "compress=zstd"
+                    "noatime"
+                    "autodefrag"
+                    "ssd"
+                  ];
+                };
+                "/persist/docker" = {
+                  mountpoint = "/var/lib/docker";
+                  mountOptions = [
+                    "compress=zstd"
+                    "noatime"
+                    "autodefrag"
+                    "ssd"
+                  ];
+                };
+                "/persist/podman" = {
+                  mountpoint = "/var/lib/podman";
+                  mountOptions = [
+                    "compress=zstd"
+                    "noatime"
+                    "autodefrag"
+                    "ssd"
+                  ];
+                };
+                "/persist/containers" = {
+                  mountpoint = "/var/lib/containers";
+                  mountOptions = [
+                    "compress=zstd"
+                    "noatime"
+                    "autodefrag"
+                    "ssd"
+                  ];
+                };
+                "/persist/libvirt" = {
+                  mountpoint = "/var/lib/libvirt";
+                  mountOptions = [
+                    "compress=zstd"
+                    "noatime"
+                    "autodefrag"
+                    "ssd"
+                  ];
+                };
+                "/persist/log" = {
+                  mountpoint = "/var/log";
+                  mountOptions = [
+                    "compress=zstd"
+                    "noatime"
+                    "autodefrag"
+                    "ssd"
+                  ];
+                };
+                "/persist/impermanence" = {
+                  mountpoint = "/persist";
+                  mountOptions = [
+                    "compress=zstd"
+                    "noatime"
+                    "autodefrag"
+                    "ssd"
+                  ];
+                };
+              };
+            };
+          };
+        };
+      };
+    };
+}