Files
nix/modules/nixos/tmpsys.nix

64 lines
1.3 KiB
Nix
Raw Normal View History

2025-04-20 11:40:22 +08:00
2025-04-20 12:15:50 +08:00
{ config, pkgs, username, inputs, lib, ... }:
2025-04-20 11:40:22 +08:00
{
imports = [
inputs.impermanence.nixosModules.impermanence
];
2025-04-20 12:11:32 +08:00
2025-04-20 11:40:22 +08:00
# 启用 tmpfs 作为根文件系统
2025-04-20 12:15:50 +08:00
fileSystems."/" = lib.mkForce {
2025-04-20 11:40:22 +08:00
device = "none";
fsType = "tmpfs";
2025-04-20 17:11:04 +08:00
options = [ "relatime" "mode=755" ];
2025-04-20 11:40:22 +08:00
};
2025-04-20 12:15:50 +08:00
# 将 /nix 目录绑定到持久化存储
2025-04-20 12:17:07 +08:00
fileSystems."/nix" = lib.mkForce {
2025-04-20 12:16:41 +08:00
device = "/dev/disk/by-label/nixos"; # 需要根据实际情况修改
2025-04-20 12:11:32 +08:00
fsType = "btrfs";
2025-04-20 17:05:37 +08:00
options = [ "compress-force=zstd" ];
2025-04-20 12:15:50 +08:00
2025-04-20 12:11:32 +08:00
};
2025-04-20 11:40:22 +08:00
# 配置持久化存储
environment.persistence."/nix/persistent" = {
hideMounts = true;
directories = [
2025-04-20 12:15:50 +08:00
"/etc/nixos"
"/etc/NetworkManager/system-connections"
"/var/log"
"/var/lib"
"/root"
2025-04-20 11:40:22 +08:00
];
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"
];
};
};
}