From e8b7cd6ad0382191afd3d57d00b86ba8e1563d00 Mon Sep 17 00:00:00 2001 From: Sense T Date: Sun, 25 Jun 2023 10:17:21 +0800 Subject: [PATCH] stateless rootfs --- global/default.nix | 1 + global/stateless-configuration.nix | 34 ++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 global/stateless-configuration.nix diff --git a/global/default.nix b/global/default.nix index f40bc5c..0943731 100644 --- a/global/default.nix +++ b/global/default.nix @@ -4,5 +4,6 @@ ./software-configuration.nix ./user-configuration.nix ./font-configuration.nix + ./stateless-configuration.nix ]; } \ No newline at end of file diff --git a/global/stateless-configuration.nix b/global/stateless-configuration.nix new file mode 100644 index 0000000..cc820fc --- /dev/null +++ b/global/stateless-configuration.nix @@ -0,0 +1,34 @@ +{ + # /nix/persistent 是你实际保存文件的地方 + environment.persistence."/nix/persistent" = { + # 不让这些映射的 mount 出现在文件管理器的侧边栏中 + hideMounts = true; + + # 你要映射的文件夹 + directories = [ + "/etc/NetworkManager/system-connections" + "/root" + "/var" + ]; + }; + + environment.variables.NIX_REMOTE = "daemon"; + + systemd.services.nix-daemon = { + environment = { + # 指定临时文件的位置 + TMPDIR = "/var/cache/nix"; + }; + serviceConfig = { + # 在 Nix Daemon 启动时自动创建 /var/cache/nix + CacheDirectory = "nix"; + }; + }; + + # Stateless rootfs + fileSystems."/" = { + device = "tmpfs"; + fsType = "tmpfs"; + options = [ "relatime" "mode=755" "nosuid" "nodev" ]; + }; +} \ No newline at end of file