mirror of
https://github.com/ryan4yin/nix-config.git
synced 2026-11-13 12:13:46 +01:00
* feat(idols-ai): persist /var/tmp and small state dirs, wipe /var/tmp at boot Move the strata model staging area (~3G) off the root tmpfs onto the persistent btrfs volume to free RAM, preserve btrbk/cups/logrotate state, and wipe /var/tmp at boot so it only accumulates between reboots. * chore(idols-ai): add nosuid,nodev to root tmpfs and tmp btrfs mounts Hardens /, /tmp and /snapshots; safe because /dev, /run, /nix and /run/setuid-programs are separate mounts, so nothing there needs suid bits or device nodes. * chore(idols-ai): add noatime to the @tmp btrfs mount Temp files do not need access times; matches the @nix subvolume style and saves btrfs metadata writes. * chore(idols-ai): harden the /var/tmp bind mount with nosuid,nodev World-writable staging data should not honor suid bits or device nodes, same as /tmp and /snapshots. * fix(idols-ai): preserve logrotate state as a file, fix persisted dir ownership - /var/lib/logrotate.status is a regular file, not a directory: move it from preservation directories to files. A missing state entry makes logrotate treat every log as freshly rotated, so it must survive reboots. - keep /var/lib/btrbk owned by btrbk:btrbk 0750 so preservation does not override the btrbk module's rule with root:root. - set /var/tmp mode 1777 explicitly instead of relying on systemd's tmp.conf ordering. - rewrite comments to describe the paths generically. * chore(idols-ai): cap journal, wipe coredumps at boot, persist upower/noctalia - services.journald.settings.Journal: SystemMaxUse=10G, RuntimeMaxUse=256M, matching the cap already set on idols-kana/idols-ruby. - wipe /var/lib/systemd/coredump at boot: it lives in the persisted /var/lib/systemd and crash dumps can contain secrets copied from memory. - persist /var/lib/upower (device battery history) and ~/.local/state/noctalia (shell settings, notification/clipboard history).
129 lines
4.8 KiB
Nix
129 lines
4.8 KiB
Nix
# Disko layout for idols-ai on nvme1n1 (target disk after migration).
|
|
# Same structure as current nvme0n1: ESP + LUKS + btrfs with ephemeral root (tmpfs).
|
|
#
|
|
# Destroy, format & mount (wipes disk; from nixos-installer: cd nix-config/nixos-installer):
|
|
# nix run github:nix-community/disko -- --mode destroy,format,mount ../hosts/idols-ai/disko-fs.nix
|
|
# Mount only (after first format):
|
|
# nix run github:nix-community/disko -- --mode mount ../hosts/idols-ai/disko-fs.nix
|
|
#
|
|
# Override device when installing, e.g.:
|
|
# nixos-install --flake .#ai --option disko.devices.disk.nixos-ai.device /dev/nvme1n1
|
|
{
|
|
# Ephemeral root; preservation mounts /persistent for state.
|
|
fileSystems."/persistent".neededForBoot = true;
|
|
|
|
disko.devices = {
|
|
# Ephemeral root; relatime and mode=755 so systemd does not set 777.
|
|
nodev."/" = {
|
|
fsType = "tmpfs";
|
|
mountOptions = [
|
|
"nosuid" # Ignore setuid bit; no suid binaries live on the root tmpfs
|
|
"nodev" # Ignore device files; nothing here needs to be a device node
|
|
"size=4G"
|
|
"relatime" # Update inode access times relative to modify/change time
|
|
"mode=755"
|
|
];
|
|
};
|
|
|
|
disk.nixos-ai = {
|
|
type = "disk";
|
|
device = "/dev/disk/by-id/nvme-KINGBANK_KP260_CN092BH3203917";
|
|
content = {
|
|
type = "gpt";
|
|
partitions = {
|
|
# EFI system partition; must stay unencrypted for UEFI to load the bootloader.
|
|
ESP = {
|
|
priority = 1;
|
|
name = "ESP";
|
|
start = "1M";
|
|
end = "600M";
|
|
type = "EF00"; # EF00 = ESP in GPT
|
|
content = {
|
|
type = "filesystem";
|
|
format = "vfat";
|
|
mountpoint = "/boot";
|
|
mountOptions = [
|
|
"fmask=0177" # File mask: 777-177=600 (owner rw-, group/others ---)
|
|
"dmask=0077" # Directory mask: 777-077=700 (owner rwx, group/others ---)
|
|
"noexec,nosuid,nodev" # Security: no execution, ignore setuid, no device nodes
|
|
];
|
|
};
|
|
};
|
|
# Root partition: LUKS encrypted, then btrfs with subvolumes.
|
|
root = {
|
|
size = "100%";
|
|
content = {
|
|
type = "luks";
|
|
name = "nixos-luks"; # Mapper name; match boot.initrd.luks
|
|
settings = {
|
|
allowDiscards = true; # TRIM for SSDs; slightly less secure, better performance
|
|
};
|
|
# Add boot.initrd.luks.devices so initrd prompts for passphrase at boot
|
|
initrdUnlock = true;
|
|
# cryptsetup luksFormat options
|
|
extraFormatArgs = [
|
|
"--type luks2"
|
|
"--cipher aes-xts-plain64"
|
|
"--hash sha512"
|
|
"--iter-time 5000"
|
|
"--key-size 256"
|
|
"--pbkdf argon2id"
|
|
"--use-random" # Block until enough entropy from /dev/random
|
|
];
|
|
extraOpenArgs = [
|
|
"--timeout 10"
|
|
];
|
|
content = {
|
|
type = "btrfs";
|
|
extraArgs = [ "-f" ]; # Force overwrite if filesystem already exists
|
|
subvolumes = {
|
|
# Top-level subvolume (id 5); used for btrfs send/receive and snapshots
|
|
"/" = {
|
|
mountpoint = "/btr_pool";
|
|
mountOptions = [ "subvolid=5" ];
|
|
};
|
|
"@nix" = {
|
|
mountpoint = "/nix";
|
|
mountOptions = [
|
|
"compress-force=zstd:1" # Save space and reduce I/O on SSD
|
|
"noatime"
|
|
];
|
|
};
|
|
"@persistent" = {
|
|
mountpoint = "/persistent";
|
|
mountOptions = [
|
|
"compress-force=zstd:1"
|
|
];
|
|
};
|
|
"@snapshots" = {
|
|
mountpoint = "/snapshots";
|
|
mountOptions = [
|
|
"nosuid"
|
|
"nodev"
|
|
"compress-force=zstd:1"
|
|
];
|
|
};
|
|
"@tmp" = {
|
|
mountpoint = "/tmp";
|
|
mountOptions = [
|
|
"nosuid"
|
|
"nodev"
|
|
"noatime" # Temp files don't need access times; saves btrfs metadata writes
|
|
"compress-force=zstd:1"
|
|
];
|
|
};
|
|
# Swap subvolume read-only; disko creates swapfile and adds swapDevices
|
|
"@swap" = {
|
|
mountpoint = "/swap";
|
|
swap.swapfile.size = "96G";
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
};
|
|
}
|