about summary refs log tree commit diff stats
path: root/modules/system/impermanence
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-05-20 16:10:21 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-05-20 16:14:26 +0200
commit368cb6b0d25db2ae23be42ad51584de059997e51 (patch)
tree3282e45d3ebced63c8498a47e83a255c35de620b /modules/system/impermanence
parentrefactor(hm): Rename to `modules/home` (diff)
downloadnixos-config-368cb6b0d25db2ae23be42ad51584de059997e51.tar.gz
nixos-config-368cb6b0d25db2ae23be42ad51584de059997e51.zip
refactor(sys): Modularize and move to `modules/system` or `pkgs`
Diffstat (limited to 'modules/system/impermanence')
-rw-r--r--modules/system/impermanence/default.nix55
1 files changed, 55 insertions, 0 deletions
diff --git a/modules/system/impermanence/default.nix b/modules/system/impermanence/default.nix
new file mode 100644
index 00000000..dca30083
--- /dev/null
+++ b/modules/system/impermanence/default.nix
@@ -0,0 +1,55 @@
+{
+  config,
+  lib,
+  ...
+}: let
+  cfg = config.soispha.impermanence;
+in {
+  options.soispha.impermanence = {
+    enable = lib.mkEnableOption "persisting directories and files with impermanence";
+
+    directories = lib.mkOption {
+      type = lib.types.listOf lib.types.str;
+      default =
+        [
+          "/etc/nixos"
+          "/var/log"
+          "/var/lib/systemd"
+        ]
+        ++ lib.optional config.networking.networkmanager.enable "/etc/NetworkManager"
+        ++ lib.optional config.boot.lanzaboote.enable "/etc/secureboot"
+        ++ lib.optional config.hardware.bluetooth.enable "/var/lib/bluetooth"
+        ++ lib.optional config.virtualisation.waydroid.enable "/var/lib/waydroid"
+        ++ lib.optional config.services.postgresql.enable "/var/lib/postgresql";
+
+      defaultText = lib.literalExpression ''
+        [
+          "/etc/nixos"
+          "/var/log"
+          "/var/lib/systemd"
+        ]
+        ++ lib.optional config.networking.networkmanager.enable "/etc/NetworkManager"
+        ++ lib.optional config.boot.lanzaboote.enable "/etc/secureboot"
+        ++ lib.optional config.hardware.bluetooth.enable "/var/lib/bluetooth"
+        ++ lib.optional config.virtualisation.waydroid.enable "/var/lib/waydroid"
+        ++ lib.optional config.services.postgresql.enable "/var/lib/postgresql"
+      '';
+      description = "The directories to persist";
+    };
+  };
+
+  config = lib.mkIf cfg.enable {
+    # needed for the hm impermanence config
+    programs.fuse.userAllowOther = true;
+
+    environment.persistence = {
+      "/srv" = {
+        hideMounts = true;
+        inherit (cfg) directories;
+        files = [
+          "/etc/machine-id"
+        ];
+      };
+    };
+  };
+}