Files
nix/modules/nixos/tmpsys.nix
2025-04-20 12:17:07 +08:00

69 lines
1.4 KiB
Nix

{ config, pkgs, username, inputs, lib, ... }:
{
imports = [
inputs.impermanence.nixosModules.impermanence
];
# 系统启动时确保持久化目录存在
system.activationScripts.persistent-dirs.text = ''
mkdir -p /nix/persistent
'';
# 启用 tmpfs 作为根文件系统
fileSystems."/" = lib.mkForce {
device = "none";
fsType = "tmpfs";
options = [ "defaults" "size=2G" "mode=755" ];
};
# 将 /nix 目录绑定到持久化存储
fileSystems."/nix" = lib.mkForce {
device = "/dev/disk/by-label/nixos"; # 需要根据实际情况修改
fsType = "btrfs";
options = [ "bind" ];
};
# 配置持久化存储
environment.persistence."/nix/persistent" = {
hideMounts = true;
directories = [
"/etc/nixos"
"/etc/NetworkManager/system-connections"
"/var/log"
"/var/lib"
"/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"
];
};
};
}