refactor nixos config

This commit is contained in:
2025-12-12 21:42:42 +03:00
parent 732f6f89a5
commit 737b10813b
14 changed files with 158 additions and 135 deletions
+66
View File
@@ -0,0 +1,66 @@
# # Возможно проблемы с оптимизацией USB (лагает клавиатура/мышь)
{ config, lib, vars, ... }:
let
cfg = config.custom;
hasBattery = lib.any (x: lib.strings.hasPrefix "BAT" x)
(builtins.attrNames (builtins.readDir "/sys/class/power_supply"));
in {
options.custom = {
battery.enable = lib.mkOption {
default = hasBattery;
description = "Enable better battery support";
type = lib.types.bool;
};
};
# config = lib.mkIf cfg.battery.enable {
config = {
boot.kernelParams = [ "amd_pstate=active" ];
powerManagement.powertop.enable =
true; # enable powertop auto tuning on startup.
services.system76-scheduler.settings.cfsProfiles.enable =
true; # Better scheduling for CPU cycles - thanks System76!!!
# services.thermald.enable =
# true; # Enable thermald, the temperature management daemon. (only necessary if on Intel CPUs)
services.power-profiles-daemon.enable =
false; # Disable GNOMEs power management
services.tlp = {
enable = true; # Enable TLP (better than gnomes internal power manager)
settings = {
CPU_BOOST_ON_AC = 1;
CPU_BOOST_ON_BAT = 0;
CPU_HWP_DYN_BOOST_ON_AC = 1;
CPU_HWP_DYN_BOOST_ON_BAT = 0;
CPU_SCALING_GOVERNOR_ON_AC = "performance";
CPU_SCALING_GOVERNOR_ON_BAT = "powersave";
CPU_SCALING_MIN_FREQ_ON_BAT = 0;
CPU_ENERGY_PERF_POLICY_ON_AC = "performance";
CPU_ENERGY_PERF_POLICY_ON_BAT = "power";
AMDGPU_ABM_LEVEL_ON_AC = 0;
AMDGPU_ABM_LEVEL_ON_BAT = 0;
PLATFORM_PROFILE_ON_AC = "performance";
PLATFORM_PROFILE_ON_BAT = "low-power";
PCIE_ASPM_ON_BAT = "powersupersave";
SATA_LINKPWR_ON_AC = "med_power_with_dipm";
SATA_LINKPWR_ON_BAT = "min_power";
RUNTIME_PM_ON_AC = "on";
RUNTIME_PM_ON_BAT = "auto";
SOUND_POWER_SAVE_ON_AC = 0;
SOUND_POWER_SAVE_ON_BAT = 1;
SOUND_POWER_SAVE_CONTROLLER = "Y";
CPU_MAX_PERF_ON_AC = 100;
CPU_MAX_PERF_ON_BAT = 50;
NMI_WATCHDOG = 0;
USB_AUTOSUSPEND = 0;
USB_BLACKLIST_BTUSB = 0;
START_CHARGE_THRESH_BAT0 = 0;
STOP_CHARGE_THRESH_BAT0 = 1;
};
};
};
}
+104
View File
@@ -0,0 +1,104 @@
{ inputs, config, lib, pkgs, ... }: {
#@# modules/low-power.nix: setup to maximize on-battery lifetime
#@# contains:
options = {
nyx.low-power.enable =
lib.mkEnableOption "enables low profile optimizations to reduce watt use";
};
config = lib.mkIf config.nyx.low-power.enable {
#@# * steam, lutris etc.
boot = {
kernelParams = [
"pcie_aspm.policy=powersupersave"
"amd_pstate=passive" # use schedutil scaling for Ryzen 7940HS
"mitigations=auto"
];
extraModprobeConfig = ''
# AMD iGPU tuning
options amdgpu dc=1
options amdgpu deep_color=1
options amdgpu aspm=1
# Force dGPU off by default to save power (only use when explicitly requested)
options amdgpu runpm=1
'';
};
networking.networkmanager.wifi.powersave = true;
programs.sway.xwayland.enable = false;
services.pipewire.jack.enable = false;
powerManagement.enable = true;
powerManagement.cpuFreqGovernor = "schedutil";
services.power-profiles-daemon.enable = false;
services.tlp = {
enable = true;
settings = {
TLP_DEFAULT_MODE = "BAT";
CPU_SCALING_GOVERNOR_ON_AC = "schedutil";
CPU_SCALING_GOVERNOR_ON_BAT = "schedutil";
CPU_ENERGY_PERF_POLICY_ON_AC = "balance_power";
CPU_ENERGY_PERF_POLICY_ON_BAT = "power";
PCIE_ASPM_ON_AC = "default";
PCIE_ASPM_ON_BAT = "powersupersave";
RUNTIME_PM_ON_AC = "auto";
RUNTIME_PM_ON_BAT = "auto";
USB_AUTOSUSPEND = "1";
WIFI_PWR_ON_AC = "on";
WIFI_PWR_ON_BAT = "on";
DEVICES_TO_DISABLE_ON_BAT = "bluetooth";
DEVICES_TO_DISABLE_ON_STARTUP = "bluetooth";
DISK_IDLE_SECS_ON_AC = "60";
DISK_IDLE_SECS_ON_BAT = "30";
SATA_LINKPWR_ON_AC = "med_power_with_dipm";
SATA_LINKPWR_ON_BAT = "min_power";
SOUND_POWER_SAVE_ON_AC = "1";
SOUND_POWER_SAVE_ON_BAT = "1";
PLATFORM_PROFILE_ON_AC = "balanced";
PLATFORM_PROFILE_ON_BAT = "low-power";
};
};
powerManagement.powertop.enable = true;
services.thermald.enable = true;
services.switcherooControl.enable = true;
hardware = {
opengl = {
enable = true;
extraPackages = with pkgs; [ mesa ];
};
amdgpu.overdrive.enable = lib.mkForce false;
};
services.printing.enable = false;
hardware.bluetooth.enable = lib.mkForce false;
services.avahi.enable = false;
services.fwupd.enable = true;
services.locate.enable = false;
services.journald.extraConfig = ''
SystemMaxUse=200M
RuntimeMaxUse=100M
MaxRetentionSec=1month
'';
# programs.ssh.startAgent = true;
services.openssh.enable = lib.mkForce false;
# libvirt
# nsncd (?)
#
services.tailscale.enable = lib.mkForce false;
programs.java.enable = lib.mkForce false;
services.upower.enable = lib.mkForce false;
services = {
xserver.windowManager.fvwm2.gestures = lib.mkForce false;
libinput.enable = lib.mkForce false;
};
hardware.opentabletdriver.enable = lib.mkForce false;
programs.kdeconnect.enable = lib.mkForce false;
services.mullvad-vpn.enable = lib.mkForce false;
virtualisation = {
docker.enable = lib.mkForce false;
libvirtd.enable = lib.mkForce false;
};
};
}