diff --git a/flake.nix b/flake.nix index 8c8ee6e..d06d57d 100644 --- a/flake.nix +++ b/flake.nix @@ -86,7 +86,7 @@ }; hyprland.url = "github:hyprwm/Hyprland"; - + impermanence.url = "github:nix-community/impermanence"; # TODO: Add any other flake you might need # hardware.url = "github:nixos/nixos-hardware"; diff --git a/modules/nixos/tmpsys.nix b/modules/nixos/tmpsys.nix new file mode 100644 index 0000000..6074ff0 --- /dev/null +++ b/modules/nixos/tmpsys.nix @@ -0,0 +1,82 @@ + +{ config, pkgs, username,inputs, lib, ... }: +{ + imports = [ + inputs.impermanence.nixosModules.impermanence + ]; + + # 启用 tmpfs 作为根文件系统 + fileSystems."/" = { + device = "none"; + fsType = "tmpfs"; + options = [ "defaults" "size=2G" "mode=755" ]; + }; + + # 配置持久化存储 + environment.persistence."/nix/persistent" = { + # 不在文件管理器中显示这些挂载点 + hideMounts = true; + + directories = [ + "/etc/nixos" # NixOS 配置文件 + "/etc/NetworkManager/system-connections" # 网络配置 + "/var/log" # 系统日志 + "/var/lib" # 系统数据 + "/root" # root 用户目录 + ]; + + files = [ + "/etc/machine-id" + "/etc/ssh/ssh_host_ed25519_key" + "/etc/ssh/ssh_host_ed25519_key.pub" + "/etc/ssh/ssh_host_rsa_key" + "/etc/ssh/ssh_host_rsa_key.pub" + ]; + + # 用户目录持久化配置 + users.${username} = { + directories = [ + # 应用配置 + ".config" + ".cache" + ".local" + ".ssh" + ".gnupg" + + # 开发相关 + ".vscode" + ".npm" + ".cargo" + + "data" + "doc" + ]; + + files = [ + ".bash_history" + ".zsh_history" + ".gitconfig" + ]; + }; + }; + + # 系统启动时确保持久化目录存在 + 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" ]; + }; +} + diff --git a/profiles/luna/default.nix b/profiles/luna/default.nix index e49e00b..6bc974d 100644 --- a/profiles/luna/default.nix +++ b/profiles/luna/default.nix @@ -20,6 +20,7 @@ in "${self}/modules/nixos/core.nix" "${self}/modules/nixos/user-group.nix" "${self}/modules/nixos/hyprland.nix" + "${self}/modules/nixos/tmpsys.nix" home-manager.nixosModules.home-manager {