about summary refs log tree commit diff
path: root/modules/persistence.nix
diff options
context:
space:
mode:
authorsefidel <contact@sefidel.net>2024-01-11 14:39:13 +0900
committersefidel <contact@sefidel.net>2024-01-12 00:18:45 +0900
commita0e13034700e6a697c1adac3050702a1d3ba0ecd (patch)
tree548dbde56bfaa84b0d9686effd2941810fa06fd9 /modules/persistence.nix
parenta670d5289903cd6236c3203fb1283f4e664e604c (diff)
downloadinfra-a0e13034700e6a697c1adac3050702a1d3ba0ecd.tar.gz
infra-a0e13034700e6a697c1adac3050702a1d3ba0ecd.zip
feat(modules)!: init persistence
Diffstat (limited to 'modules/persistence.nix')
-rw-r--r--modules/persistence.nix46
1 files changed, 46 insertions, 0 deletions
diff --git a/modules/persistence.nix b/modules/persistence.nix
new file mode 100644
index 0000000..4c11588
--- /dev/null
+++ b/modules/persistence.nix
@@ -0,0 +1,46 @@
+{ config, inputs, lib, ... }:
+
+
+with lib;
+let
+  cfg = config.modules.persistence;
+in
+{
+  imports = [
+    inputs.impermanence.nixosModules.impermanence
+  ];
+
+  options.modules.persistence = {
+    enable = mkEnableOption "impermanence persistence";
+
+    storagePath = lib.mkOption {
+      type = types.path;
+      description = ''
+        The path to persistent storage where the real
+        files and directories should be stored.
+      '';
+    };
+
+    directories = mkOption {
+      type = types.listOf types.str;
+    };
+  };
+
+  config = mkIf cfg.enable {
+    fileSystems.${cfg.storagePath}.neededForBoot = true;
+
+    environment.persistence.${cfg.storagePath}.directories = cfg.directories;
+
+    services.openssh.hostKeys = [
+      {
+        path = "${cfg.storagePath}/ssh/ssh_host_ed25519_key";
+        type = "ed25519";
+      }
+      {
+        path = "${cfg.storagePath}/ssh/ssh_host_rsa_key";
+        type = "rsa";
+        bits = 4096;
+      }
+    ];
+  };
+}