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-04 16:31:26 +0200
commit1c4672d602de2a6022f759996025cb7df0237862 (patch)
tree4a7c996693d167e1885db7046227c6d3acc7ad6f
parentFix(system/services/nix-sync): Remove slash from cachePath (diff)
downloadnixos-server-1c4672d602de2a6022f759996025cb7df0237862.tar.gz
nixos-server-1c4672d602de2a6022f759996025cb7df0237862.zip
Feat(system/file_system_layout): Add impermanence
-rw-r--r--flake.lock16
-rw-r--r--flake.nix9
-rw-r--r--system/file_system_layouts/default.nix15
-rw-r--r--system/file_system_layouts/impermanence.nix16
4 files changed, 46 insertions, 10 deletions
diff --git a/flake.lock b/flake.lock
index 0aab10b..b4b2b61 100644
--- a/flake.lock
+++ b/flake.lock
@@ -52,6 +52,21 @@
         "type": "github"
       }
     },
+    "impermanence": {
+      "locked": {
+        "lastModified": 1684264534,
+        "narHash": "sha256-K0zr+ry3FwIo3rN2U/VWAkCJSgBslBisvfRIPwMbuCQ=",
+        "owner": "nix-community",
+        "repo": "impermanence",
+        "rev": "89253fb1518063556edd5e54509c30ac3089d5e6",
+        "type": "github"
+      },
+      "original": {
+        "owner": "nix-community",
+        "repo": "impermanence",
+        "type": "github"
+      }
+    },
     "nixpkgs": {
       "locked": {
         "lastModified": 1688287271,
@@ -101,6 +116,7 @@
     "root": {
       "inputs": {
         "flake-utils": "flake-utils",
+        "impermanence": "impermanence",
         "nixpkgs": "nixpkgs",
         "simple-nixos-mailserver": "simple-nixos-mailserver",
         "systems": "systems"
diff --git a/flake.nix b/flake.nix
index eff0f44..edfb3c4 100644
--- a/flake.nix
+++ b/flake.nix
@@ -10,6 +10,12 @@
       inputs.systems.follows = "systems";
     };
 
+    # modules
+    impermanence = {
+      url = "github:nix-community/impermanence";
+      inputs = {
+      };
+    };
     simple-nixos-mailserver = {
       url = "gitlab:simple-nixos-mailserver/nixos-mailserver/nixos-23.05";
       inputs = {
@@ -21,7 +27,9 @@
   outputs = {
     self,
     nixpkgs,
+    # modules
     simple-nixos-mailserver,
+    impermanence,
     ...
   } @ attrs: let
     system = "x86_64-linux";
@@ -33,6 +41,7 @@
       modules = [
         ./hosts/server1/configuration.nix
         simple-nixos-mailserver.nixosModule
+        impermanence.nixosModules.impermanence
       ];
     };
     devShells."${system}" = {
diff --git a/system/file_system_layouts/default.nix b/system/file_system_layouts/default.nix
index fe7fc3f..d038632 100644
--- a/system/file_system_layouts/default.nix
+++ b/system/file_system_layouts/default.nix
@@ -1,5 +1,4 @@
 {
-  modulesPath,
   config,
   lib,
   ...
@@ -7,6 +6,10 @@
 with lib; let
   cfg = config.system.fileSystemLayouts;
 in {
+  imports = [
+    ./impermanence.nix
+  ];
+
   options.system.fileSystemLayouts = {
     mainDisk = mkOption {
       type = lib.types.path;
@@ -30,20 +33,12 @@ in {
         device = cfg.mainDisk;
         fsType = "btrfs";
         options = ["subvol=storage" "compress-force=zstd"];
+        neededForBoot = true;
       };
       "/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"];
-      };
     };
   };
 }
diff --git a/system/file_system_layouts/impermanence.nix b/system/file_system_layouts/impermanence.nix
new file mode 100644
index 0000000..da38791
--- /dev/null
+++ b/system/file_system_layouts/impermanence.nix
@@ -0,0 +1,16 @@
+{...}: {
+  environment.persistence = {
+    "/srv" = {
+      hideMounts = true;
+      directories = [
+        "/etc/nixos"
+        "/var/log"
+        "/var/lib/postgresql"
+        "/var/lib/acme"
+      ];
+      files = [
+        "/etc/machine-id"
+      ];
+    };
+  };
+}