-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpowersave.nix
77 lines (62 loc) · 2.01 KB
/
powersave.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
{ config, pkgs, lib, ... }:
{
powerManagement = {
enable = true;
powertop.enable = true;
scsiLinkPolicy = "med_power_with_dipm";
cpuFreqGovernor = "powersave";
};
boot.kernel.sysctl = {
"vm.dirty_writeback_centisecs" = 6000;
"vm.swappiness" = 40;
};
# https://www.reddit.com/r/linux/comments/lhgx9/how_can_i_reduce_my_power_consumption/
boot.kernelParams = [
"pcie_aspm=force"
"i915.i915_enable_rc6=1"
"i915.i915_enable_fbc=1"
"i915.lvds_downclock=1"
];
systemd.services.powersave = {
description = "Power Save scripts";
wantedBy = [ "multi-user.target" ];
script =
''
set_and_echo() {
file="$1"
value="$2"
original="$(cat $file)"
if [ "$original" != "$value" ]; then
echo "$value" > $file || true
current="$(cat $file)"
echo "Changed $file from $original to $current"
fi
}
# https://wiki.archlinux.org/title/Power_management
for i in $(find /sys/devices/system/cpu/cpufreq/policy? -name energy_performance_preference -writable);
do
set_and_echo $i balance_power
done
# https://www.kernel.org/doc/html/latest/admin-guide/pm/intel_epb.html
for i in $(find /sys/devices/system/cpu/cpu*/power/ -name energy_perf_bias -writable);
do
set_and_echo $i balance-power
done
# https://www.kernel.org/doc/html/latest/admin-guide/pm/intel_pstate.html
set_and_echo /sys/devices/system/cpu/intel_pstate/energy_efficiency 1
set_and_echo /sys/devices/system/cpu/intel_pstate/hwp_dynamic_boost 1
'';
serviceConfig.Type = "oneshot";
};
services.udev = {
extraRules =
''
SUBSYSTEM=="pci", ATTR{power/control}="auto"
SUBSYSTEM=="usb", TEST=="power/control", ATTR{power/control}="auto"
'';
};
#hardware.bluetooth.powerOnBoot = false;
#hardware.bluetooth.enable = false;
boot.blacklistedKernelModules = [ "iwlwifi" ];
# services.thermald.enable = true;
}