# What CachyOS adds on top of plain Arch: its kernel and the cachyos-settings # package (sysctl, udev rules, systemd defaults), ported file by file. The CachyOS # file each part comes from is named next to it, so they can be compared when # CachyOS changes something. # # Not ported, because it does nothing on this machine: the laptop audio power # saving and touchpad rules, the old-Radeon (SI/CIK) amdgpu options, and # debuginfod. Snapper root snapshots are replaced by NixOS generations: every # rebuild is a boot menu entry you can go back to. { inputs, lib, pkgs, ... }: let # cachyos-settings: /usr/bin/game-performance. Runs a game with the # "performance" power profile held, and the screensaver inhibited. Use it as # a Steam launch option: game-performance %command% game-performance = pkgs.writeShellApplication { name = "game-performance"; runtimeInputs = [ pkgs.power-profiles-daemon pkgs.systemd ]; text = '' if ! powerprofilesctl list | grep -q 'performance:'; then exec "$@" fi if [ -n "''${GAME_PERFORMANCE_SCREENSAVER_ON:-}" ]; then exec powerprofilesctl launch -p performance \ -r "Launched with CachyOS game-performance utility" -- "$@" else exec systemd-inhibit --why "CachyOS game-performance is running" powerprofilesctl launch \ -p performance -r "Launched with CachyOS game-performance utility" -- "$@" fi ''; }; # cachyos-settings: /usr/bin/dlss-swapper. Steam launch option: # dlss-swapper %command% dlss-swapper = pkgs.writeShellScriptBin "dlss-swapper" '' export PROTON_ENABLE_NGX_UPDATER=1 export DXVK_NVAPI_DRS_NGX_DLSS_RR_OVERRIDE=on export DXVK_NVAPI_DRS_NGX_DLSS_SR_OVERRIDE=on export DXVK_NVAPI_DRS_NGX_DLSS_FG_OVERRIDE=on export DXVK_NVAPI_DRS_NGX_DLSS_RR_OVERRIDE_RENDER_PRESET_SELECTION=render_preset_latest export DXVK_NVAPI_DRS_NGX_DLSS_SR_OVERRIDE_RENDER_PRESET_SELECTION=render_preset_latest exec "$@" ''; in { # --- Kernel ---------------------------------------------------------------- # The overlay pins the kernel to the nixpkgs it was built with, so the build # doesn't change with this system's nixpkgs. nixpkgs.overlays = [ inputs.nix-cachyos-kernel.overlays.pinned ]; # git.granstrm.com builds the kernel, its modules and the NVIDIA driver every # night the kernel changes (flake.nix's `ci`), and serves them from its # binary cache. nix.settings = { substituters = [ "https://cache.git.granstrm.com" ]; trusted-public-keys = [ "cache.git.granstrm.com-1:Y6BjEJMQZ02kt2oOJ/99RU+NTDZDsBY8tqIiypq1ong=" ]; }; # Same build as linux-cachyos on CachyOS's znver4 repo: EEVDF scheduler, # 1000 Hz, full preemption, Clang ThinLTO, tuned for Zen 4 (also right for # this Zen 5 CPU, as on CachyOS). boot.kernelPackages = pkgs.cachyosKernels.linuxPackages-cachyos-latest-lto-zen4; boot.kernelParams = [ "nowatchdog" # cachyos-settings: udev/rules.d/30-zram.rules turns zswap off once zram is # up; it is always up here, so it is simply off from boot. "zswap.enabled=0" ]; # modprobe.d/blacklist.conf boot.blacklistedKernelModules = [ "iTCO_wdt" "sp5100_tco" ]; # modules-load.d/ntsync.conf: Wine/Proton's NT synchronization primitives. boot.kernelModules = [ "ntsync" ]; boot.extraModprobeConfig = '' # modprobe.d/nvidia.conf options nvidia NVreg_InitializeSystemMemoryAllocations=0 # cachyos-iw-set-regdomain: the Wi-Fi regulatory domain, from the time zone. options cfg80211 ieee80211_regdom="NO" ''; # --- sysctl.d/70-cachyos-settings.conf -------------------------------------- boot.kernel.sysctl = { # 150 rather than the file's 100: 30-zram.rules raises it to 150 as soon as # zram is active, which on CachyOS is always. "vm.swappiness" = 150; "vm.vfs_cache_pressure" = 50; "vm.dirty_bytes" = 268435456; "vm.page-cluster" = 0; "vm.dirty_background_bytes" = 67108864; "vm.dirty_writeback_centisecs" = 1500; "kernel.nmi_watchdog" = 0; "kernel.unprivileged_userns_clone" = 1; "kernel.printk" = "3 3 3 3"; "kernel.kptr_restrict" = 2; "net.core.netdev_max_backlog" = 4096; "fs.file-max" = 2097152; }; # --- udev rules --------------------------------------------------------------- services.udev.extraRules = '' # 60-ioschedulers.rules ACTION=="add|change", KERNEL=="sd[a-z]*", ATTR{queue/rotational}=="1", ATTR{queue/scheduler}="bfq" ACTION=="add|change", KERNEL=="sd[a-z]*|mmcblk[0-9]*", ATTR{queue/rotational}=="0", ATTR{queue/scheduler}="mq-deadline" ACTION=="add|change", KERNEL=="nvme[0-9]*", ATTR{queue/rotational}=="0", ATTR{queue/scheduler}="kyber" # 40-hpet-permissions.rules, 99-cpu-dma-latency.rules KERNEL=="rtc0", GROUP="audio" KERNEL=="hpet", GROUP="audio" DEVPATH=="/devices/virtual/misc/cpu_dma_latency", OWNER="root", GROUP="audio", MODE="0660" # 50-sata.rules ACTION=="add", SUBSYSTEM=="scsi_host", KERNEL=="host*", ATTR{link_power_management_supported}=="1", ATTR{link_power_management_policy}=="*", ATTR{link_power_management_policy}="max_performance" # 71-nvidia.rules: runtime power management for the NVIDIA GPU. ACTION=="add|bind", SUBSYSTEM=="pci", DRIVERS=="nvidia", ATTR{vendor}=="0x10de", ATTR{class}=="0x03[0-9]*", TEST=="power/control", ATTR{power/control}="auto" ACTION=="remove|unbind", SUBSYSTEM=="pci", DRIVERS=="nvidia", ATTR{vendor}=="0x10de", ATTR{class}=="0x03[0-9]*", TEST=="power/control", ATTR{power/control}="on" ''; # --- tmpfiles.d --------------------------------------------------------------- systemd.tmpfiles.rules = [ # thp.conf, thp-shrinker.conf "w! /sys/kernel/mm/transparent_hugepage/defrag - - - - defer+madvise" "w! /sys/kernel/mm/transparent_hugepage/khugepaged/max_ptes_none - - - - 409" # coredump.conf "e /var/lib/systemd/coredump - - - 3d" ]; # --- systemd ------------------------------------------------------------------ # system.conf.d/00-timeout.conf, 10-limits.conf systemd.settings.Manager = { DefaultTimeoutStartSec = "15s"; DefaultTimeoutStopSec = "10s"; DefaultLimitNOFILE = "2048:2097152"; }; # user.conf.d/00-timeout.conf, 10-limits.conf systemd.user.settings.Manager = { DefaultTimeoutStartSec = "15s"; DefaultTimeoutStopSec = "10s"; DefaultLimitNOFILE = "1024:1048576"; }; # journald.conf.d/00-journal-size.conf services.journald.settings.Journal.SystemMaxUse = "50M"; # timesyncd.conf.d/10-timesyncd.conf services.timesyncd = { servers = [ "time.cloudflare.com" ]; fallbackServers = [ "time.google.com" "0.nixos.pool.ntp.org" "1.nixos.pool.ntp.org" ]; }; # system/user@.service.d/delegate.conf: lets user services (and ananicy) # manage their own CPU, I/O and memory controllers. systemd.services."user@".serviceConfig.Delegate = "cpu cpuset io memory pids"; # system/rtkit-daemon.service.d/override.conf security.rtkit.enable = true; systemd.services.rtkit-daemon.serviceConfig.LogLevelMax = "info"; # systemd-oomd per-slice defaults (system.slice.d, user-.slice.d, # session.slice.d). systemd.oomd.enable = true; systemd.slices = { "system".sliceConfig = { ManagedOOMSwap = "kill"; ManagedOOMMemoryPressure = "kill"; ManagedOOMMemoryPressureLimit = "80%"; }; "user-".sliceConfig = { ManagedOOMSwap = "kill"; ManagedOOMMemoryPressure = "kill"; ManagedOOMMemoryPressureLimit = "80%"; }; }; systemd.user.slices.session.sliceConfig.ManagedOOMPreference = "omit"; # system/pci-latency.service + /usr/bin/pci-latency systemd.services.pci-latency = { description = "Adjust latency timers for PCI peripherals"; wantedBy = [ "multi-user.target" ]; serviceConfig.Type = "oneshot"; path = [ pkgs.pciutils ]; script = '' setpci -v -s '*:*' latency_timer=20 setpci -v -s '0:0' latency_timer=0 setpci -v -d "*:*:04xx" latency_timer=80 ''; }; # security/limits.d/20-audio.conf security.pam.loginLimits = [ { domain = "@audio"; item = "rtprio"; type = "-"; value = "99"; } { domain = "@audio"; item = "nice"; type = "-"; value = "-11"; } ]; hardware.wirelessRegulatoryDatabase = true; # --- CachyOS services --------------------------------------------------------- # ananicy-cpp with CachyOS's rules: renices games, compilers, browsers etc. services.ananicy = { enable = true; package = pkgs.ananicy-cpp; rulesProvider = pkgs.ananicy-rules-cachyos; }; # bpftune: auto-tunes network and other kernel settings (enabled on CachyOS). services.bpftune.enable = true; # sched-ext schedulers, as CachyOS's scx-scheds. Off there too (scx_loader was # disabled); to try one: # services.scx = { enable = true; scheduler = "scx_lavd"; }; # power-profiles-daemon, with the profile you had set on CachyOS. services.power-profiles-daemon.enable = true; # Started with the daemon itself (wanting it from multi-user.target makes an # ordering cycle). Skipped where there is no performance profile, e.g. in a VM. systemd.services.power-profile-performance = { description = "Select the performance power profile"; after = [ "power-profiles-daemon.service" ]; bindsTo = [ "power-profiles-daemon.service" ]; wantedBy = [ "power-profiles-daemon.service" ]; serviceConfig.Type = "oneshot"; path = [ pkgs.power-profiles-daemon ]; script = '' if powerprofilesctl list | grep -q 'performance:'; then powerprofilesctl set performance fi ''; }; environment.systemPackages = [ game-performance dlss-swapper ]; }