Files
nix-config/hosts/idols-ai/default.nix
T
Ryan Yin a091fe1aca docs(hosts): refresh the ai screenshots and correct its hardware notes
- replace the btop screenshot with the 2026-10-06 annotated capture
  (btop + fastfetch + the strata/llama.cpp serving logs); the old
  2026-10-01 file is gone, so the README link moves to the new name
- drop the Helix/AI-agents screenshot and its README reference
- fix stale hardware descriptions: the hosts/README.md inventory row and
  the idols-ai header comment still said i5-13600KF, and the zswap pool
  comment sized its percentages against the old 96G of RAM (now 128G)
- record the hardware history: the platform was rebuilt on 2026-04-27
  (PR #257/#258) onto the Colorful CVN Z890 ARK FROZEN + Core Ultra 7
  270K Plus, replacing the MSI board and i5-13600KF the host was added
  with in 2023-05; the 2x48G kit predates that rebuild, the 2x16G kit
  was added 2026-10-06
- make the DIMM bring-up order mandatory and record its failure mode:
  with the 48G pair in first, or all four DIMMs from the start, the
  board does not POST
- gloss the Chinese BIOS labels in English, marked as translations of
  the labels rather than the firmware's own English wording

Left alone on purpose: the 96G swapfile in hosts/idols-ai/disko-fs.nix.
It was grown from 20G to 1x-RAM on 2026-10-02 (a26ab3be), when the host
still had 96G; resizing it again means re-running disko on the machine,
so that stays a separate decision.
2026-10-06 22:32:34 +08:00

163 lines
6.1 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 + Core Ultra 7 270K Plus + RTX 4090 GPU,
# 128G DDR5-4800 (mixed 4-DIMM, see MIXED-MEMORY.md), 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
# Include the results of the hardware scan.
./hardware-configuration.nix
./hardware-intel.nix
./hardware-nvidia.nix
./preservation.nix
./secureboot.nix
./restic.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 (~13G on 128G): the module default 25% (~32G) 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;
# Permit the desktop user to access Intel accelerator devices for local ASR.
users.users.${myvars.username}.extraGroups = [ "render" ];
# systemd-journal - cap disk usage
# https://www.freedesktop.org/software/systemd/man/latest/journald.conf.html
services.journald.settings.Journal = {
SystemMaxUse = "10G";
RuntimeMaxUse = "256M";
};
# Monitor SSD/NVMe SMART attributes so a drive going bad is visible before it
# fails, and so there is data behind the relaxed NVMe power-management
# settings in hardware-configuration.nix. smartd autodetects devices and
# reports to the journal (mail notifications stay off without an MTA).
services.smartd.enable = true;
# QEMU/KVM(HostCpuOnly) for local VMs.
environment.systemPackages = [ pkgs.qemu_kvm ];
# Re-evaluate after the Insta360 Link firmware or the kernel's uvcvideo changes.
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 mihomo's TUN auto-detect briefly loses its
# outbound interface, leaving routing broken until mihomo 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";
};
# Dynamic DNS takeover: sing-tun normally asks resolved to use the TUN DNS
# address through resolvectl. That built-in call is not usable from nixpkgs'
# DynamicUser+hardened unit: the D-Bus socket is blocked, and resolve1's
# SetLinkDNS/SetLinkDomains methods require privileged authorization. Without
# it, resolved's upstream queries bypass dns-hijack and leave via the NIC.
# Run the takeover as a privileged lifecycle hook instead. ExecStopPost also
# runs on crashes, so a dead mihomo leaves the network usable.
# The '+' prefix escapes the unit's sandbox; without it, resolvectl's D-Bus
# connect fails and a failed ExecStartPost kills the otherwise healthy service.
systemd.services.mihomo.serviceConfig = {
ExecStartPost = lib.mkDefault "+${pkgs.systemd}/bin/resolvectl dns ${iface} 127.0.0.1:1053";
ExecStopPost = lib.mkDefault "+${pkgs.systemd}/bin/resolvectl revert ${iface}";
};
# 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?
}