From 54f7e868ee30afd7e282a903738ee25011dd87bd Mon Sep 17 00:00:00 2001 From: alex Date: Sun, 20 Apr 2025 12:11:32 +0800 Subject: [PATCH] fix --- modules/nixos/tmpsys.nix | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/modules/nixos/tmpsys.nix b/modules/nixos/tmpsys.nix index bc571f8..f76ddcb 100644 --- a/modules/nixos/tmpsys.nix +++ b/modules/nixos/tmpsys.nix @@ -5,6 +5,11 @@ inputs.impermanence.nixosModules.impermanence ]; + # 系统启动时确保持久化目录存在 + system.activationScripts.persistent-dirs.text = '' + mkdir -p /nix/persistent + ''; + # 启用 tmpfs 作为根文件系统 fileSystems."/" = lib.mkForce{ device = "none"; @@ -12,6 +17,20 @@ options = [ "defaults" "size=2G" "mode=755" ]; }; + # 将 /nix 存储在持久化分区 + fileSystems."/nix" = lib.mkForce{ + device = "/nix/persistent/nix"; + fsType = "btrfs"; + options = [ "compress-force=zstd" ]; + }; + + # 建议的 fstab 配置 + fileSystems."/nix/persistent" = { + device = "/dev/disk/by-label/nixos-persistent"; # 需要根据实际情况修改 + fsType = "btrfs"; + neededForBoot = true; + }; + # 配置持久化存储 environment.persistence."/nix/persistent" = { # 不在文件管理器中显示这些挂载点 @@ -61,23 +80,6 @@ }; }; - # 系统启动时确保持久化目录存在 - system.activationScripts.persistent-dirs.text = '' - mkdir -p /nix/persistent - ''; - # 建议的 fstab 配置 - fileSystems."/nix/persistent" = { - device = "/dev/disk/by-label/nixos-persistent"; # 需要根据实际情况修改 - fsType = "ext4"; - neededForBoot = true; - }; - - # 将 /nix 存储在持久化分区 - fileSystems."/nix" = { - device = "/nix/persistent/nix"; - fsType = "btrfs"; - options = [ "bind" ]; - }; }