Files
nix-config/hosts/idols-ai/default.nix
T
ryan4yin | 二花 f8d12ada24 feat(btrbk): make snapshots explicit, guarded, and stored in @snapshots (#271)
* feat(btrbk): make snapshots explicit and guarded

Replace the always-on, hardcoded module with modules.btrbk options (enable/volume/subvolume/snapshotDir/target/onCalendar), and assert the btrfs top-level subvolume is mounted so a missing mount fails evaluation instead of silently failing at runtime.

Store snapshots in the @snapshots subvolume (snapshot_dir=@snapshots) rather than next to the live subvolume, make the off-host target explicit and off by default, and document that local snapshots are not off-host backups.

Enable the feature explicitly on idols-ai, shoukei and the three kubevirt hosts; qemu-guest now disables it through the option. Add eval tests for shoukei and ai.

* feat(monitoring): alert on btrbk snapshot failure

Add HostBtrbkSnapshotFailed on node_systemd_unit_state for btrbk-btrbk.service, so a broken snapshot schedule alerts instead of only surfacing in the journal.
2026-09-19 11:43:11 +08:00

126 lines
4.2 KiB
Nix
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{
disko,
myvars,
lib,
pkgs,
...
}:
#############################################################
#
# Ai - my main computer, with NixOS + I5-13600KF + RTX 4090 GPU, for gaming & daily use.
#
#############################################################
let
hostName = "ai"; # Define your hostname.
inherit (myvars.networking) mainGateway mainGateway6 nameservers;
inherit (myvars.networking.hostsAddr.${hostName}) iface ipv4 ipv6;
ipv4WithMask = "${ipv4}/24";
ipv6WithMask = "${ipv6}/64";
in
{
imports = [
disko.nixosModules.default
# disks
./disko-fs.nix
./disko-fs-data.nix
./netdev-mount.nix
# Include the results of the hardware scan.
./hardware-configuration.nix
./hardware-intel.nix
./hardware-nvidia.nix
./preservation.nix
./secureboot.nix
# others
./ai
];
# Zram consumes physical memory for compression, which can cause a deadlock and system hang if the model size approaches the physical memory limit.
# Disable the whole module (zram device + its swappiness=180 sysctl tunings); this host uses a disk swapfile instead.
modules.zram.enable = false;
# zswap: compressed writeback cache in front of the disk swapfile.
# Keeps swapped cold anon pages compressed in RAM instead of the SSD, which frees more
# page cache for the ~78GB mmap'd LLM weights (mmap file pages never go through zswap).
# Safe here: disk swapfile remains the real backing store, no zram deadlock structure.
# - zstd: CPU is not the bottleneck here (llama.cpp peaks ~30% util); its ~2.5x ratio
# keeps ~5G more anon bytes in the capped pool than lz4, and ~5us decompress is noise
# vs the ~100us SSD fault it avoids.
# - 10% pool (~9G): the module default 25% (~23G) would compete with the weight cache.
boot.zswap = {
enable = true;
compressor = "zstd";
maxPoolPercent = 10;
};
services.sunshine.enable = true;
services.tuned.ppdSettings.main.default = lib.mkForce "performance";
modules.btrbk.enable = true;
powerManagement.resumeCommands = ''
# Insta360 Link may stay enumerated with a stalled UVC endpoint after S3 resume.
${pkgs.coreutils}/bin/sleep 1
${pkgs.usbutils}/bin/usbreset 2e1a:4c01 || true
'';
networking = {
inherit hostName;
# we use networkd instead
networkmanager.enable = false; # provides nmcli/nmtui for wifi adjustment
useDHCP = false;
};
networking.useNetworkd = true;
systemd.network.enable = true;
# networkd removes routing policy rules not defined in .network files
# (ManageForeignRoutingPolicyRules defaults to yes) each time it reconfigures
# a link. On S3 resume it reconfigures enp130s0, which wiped mihomo's
# (9000-9010) and Tailscale's rules and briefly broke routing. Keep foreign
# rules so the VPN/TUN rules survive.
systemd.network.config.networkConfig.ManageForeignRoutingPolicyRules = false;
systemd.network.networks."10-${iface}" = {
matchConfig.Name = [ iface ];
networkConfig = {
Address = [
ipv4WithMask
ipv6WithMask
];
DNS = nameservers;
DHCP = "ipv6"; # enable DHCPv6 only, so we can get a GUA.
IPv6AcceptRA = true; # for Stateless IPv6 Autoconfiguraton (SLAAC)
LinkLocalAddressing = "ipv6";
# r8169 drops carrier on S3 resume; without this, networkd tears down the
# static address/route and clash's TUN auto-detect briefly loses its
# outbound interface, leaving routing broken until clash is restarted.
IgnoreCarrierLoss = "10s";
};
routes = [
{
Destination = "0.0.0.0/0";
Gateway = mainGateway;
}
{
Destination = "::/0";
Gateway = mainGateway6;
GatewayOnLink = true; # it's a gateway on local link.
}
];
linkConfig.RequiredForOnline = "routable";
};
# This value determines the NixOS release from which the default
# settings for stateful data, like file locations and database versions
# on your system were taken. It‘s perfectly fine and recommended to leave
# this value at the release version of the first install of this system.
# Before changing this value read the documentation for this option
# (e.g. man configuration.nix or on https://nixos.org/nixos/options.html).
system.stateVersion = "25.11"; # Did you read the comment?
}