summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorSoispha <soispha@vhack.eu>2023-07-03 15:04:48 +0200
committerSoispha <soispha@vhack.eu>2023-07-03 15:04:48 +0200
commitf7a4052cf74987ba1c25a0128039ed1545d9e300 (patch)
tree4217794c7a31abe47596e4ca7b71614775eb64d1
parentBuild(flake): Update (diff)
downloadnixos-server-f7a4052cf74987ba1c25a0128039ed1545d9e300.tar.gz
nixos-server-f7a4052cf74987ba1c25a0128039ed1545d9e300.zip
Feat(system/disks): Add disko with impermanence
Diffstat (limited to '')
-rw-r--r--flake.nix18
-rw-r--r--system/disks/default.nix65
-rw-r--r--system/disks/impermanence.nix15
-rw-r--r--system/file_system_layouts/default.nix49
4 files changed, 98 insertions, 49 deletions
diff --git a/flake.nix b/flake.nix
index 3af5b41..644fa4b 100644
--- a/flake.nix
+++ b/flake.nix
@@ -10,6 +10,18 @@
       inputs.systems.follows = "systems";
     };
 
+    # modules
+    disko = {
+      url = "github:nix-community/disko";
+      inputs = {
+        nixpkgs.follows = "nixpkgs";
+      };
+    };
+    impermanence = {
+      url = "github:nix-community/impermanence";
+      inputs = {
+      };
+    };
     simple-nixos-mailserver = {
       url = "gitlab:simple-nixos-mailserver/nixos-mailserver/nixos-23.05";
       inputs = {
@@ -21,7 +33,10 @@
   outputs = {
     self,
     nixpkgs,
+    # modules
     simple-nixos-mailserver,
+    impermanence,
+    disko,
     ...
   } @ attrs: let
     system = "x86_64-linux";
@@ -36,6 +51,8 @@
         {
           mailserver = import ./system/mail {inherit (pkgs) lib;};
         }
+        disko.nixosModules.default
+        impermanence.nixosModules.impermanence
       ];
     };
     devShells."${system}" = {
@@ -54,3 +71,4 @@
   };
 }
 # vim: ts=2
+
diff --git a/system/disks/default.nix b/system/disks/default.nix
new file mode 100644
index 0000000..b5e53e4
--- /dev/null
+++ b/system/disks/default.nix
@@ -0,0 +1,65 @@
+{
+  config,
+  lib,
+  ...
+}:
+with lib; let
+  cfg = config.system.disks;
+  defaultMountOptions = ["compress-force=zstd:15"];
+in {
+  imports = [ ./impermanence.nix];
+
+  options.system.disks = {
+    disk = mkOption {
+      type = lib.types.path;
+      example = literalExpression "/dev/disk/by-id/ata-WDC_WD10SDRW-11A0XS0_WD-WXP2A901KJN5";
+      description = lib.mdDoc "Path to the disk";
+    };
+  };
+
+  config = {
+    disko.devices = {
+      disk.main = {
+        device = cfg.disk;
+        content = {
+          type = "btrfs";
+          extraArgs = ["-f" "--label nixos"]; # f: Override existing partitions
+          subvolumes = {
+            "nix" = {
+              mountpoint = "/nix";
+              mountOptions = defaultMountOptions;
+            };
+            "persistent-storage" = {
+              mountpoint = "/srv";
+              mountOptions = defaultMountOptions;
+            };
+            "persistent-storage@snapshots" = {
+              mountpoint = "/srv/.snapshots";
+              mountOptions = defaultMountOptions;
+            };
+            "boot" = {
+              mountpoint = "/boot";
+              mountOptions = defaultMountOptions;
+            };
+          };
+        };
+      };
+      nodev = {
+        "/" = {
+          fsType = "tmpfs";
+          mountOptions = ["defaults" "size=2G" "mode=755"];
+        };
+      };
+    };
+    fileSystems = {
+      "/srv" = {
+        neededForBoot = true;
+      };
+      "/boot" = {
+        neededForBoot = true;
+      };
+    };
+  };
+}
+# vim: ts=2
+
diff --git a/system/disks/impermanence.nix b/system/disks/impermanence.nix
new file mode 100644
index 0000000..6da011a
--- /dev/null
+++ b/system/disks/impermanence.nix
@@ -0,0 +1,15 @@
+{...}: {
+  environment.persistence = {
+    "/srv" = {
+      hideMounts = true;
+      directories = [
+        "/etc/nixos"
+        "/var/log"
+        "/var/lib/postgresql"
+      ];
+      files = [
+        "/etc/machine-id"
+      ];
+    };
+  };
+}
diff --git a/system/file_system_layouts/default.nix b/system/file_system_layouts/default.nix
deleted file mode 100644
index fe7fc3f..0000000
--- a/system/file_system_layouts/default.nix
+++ /dev/null
@@ -1,49 +0,0 @@
-{
-  modulesPath,
-  config,
-  lib,
-  ...
-}:
-with lib; let
-  cfg = config.system.fileSystemLayouts;
-in {
-  options.system.fileSystemLayouts = {
-    mainDisk = mkOption {
-      type = lib.types.path;
-      example = literalExpression "/dev/disk/by-uuid/0442cb6d-f13a-4635-b487-fa76189774c5";
-      description = lib.mdDoc "Path to the main disk";
-    };
-  };
-  config = {
-    fileSystems = {
-      "/" = {
-        device = "tmpfs";
-        fsType = "tmpfs";
-        options = ["defaults" "size=2G" "mode=755"];
-      };
-      "/nix" = {
-        device = cfg.mainDisk;
-        fsType = "btrfs";
-        options = ["subvol=nix" "compress-force=zstd"];
-      };
-      "/srv" = {
-        device = cfg.mainDisk;
-        fsType = "btrfs";
-        options = ["subvol=storage" "compress-force=zstd"];
-      };
-      "/boot" = {
-        device = cfg.mainDisk;
-        options = ["subvol=boot" "compress-force=zstd"];
-      };
-
-      "/etc/nixos" = {
-        device = "/srv/nix-config";
-        options = ["bind"];
-      };
-      "/var/lib/postgresql" = {
-        device = "/srv/postgresql";
-        options = ["bind"];
-      };
-    };
-  };
-}