added stuff

This commit is contained in:
vali 2024-04-09 23:11:33 +02:00
commit 236b8c2a6b
907 changed files with 70990 additions and 0 deletions

View file

@ -0,0 +1,7 @@
{
imports = [
./power
./touchpad.nix
];
}

View file

@ -0,0 +1,75 @@
{
config,
lib,
pkgs,
...
}: let
inherit (lib) mkIf mkDefault;
dev = config.modules.device;
acceptedTypes = ["laptop" "hybrid"];
in {
imports = [./monitor.nix];
config = mkIf (builtins.elem dev.type acceptedTypes) {
hardware.acpilight.enable = true;
environment.systemPackages = with pkgs; [
acpi
powertop
];
services = {
# handle ACPI events
acpid.enable = true;
# allows changing system behavior based upon user-selected power profiles
power-profiles-daemon.enable = true;
# temperature target on battery
undervolt = {
tempBat = 65; # deg C
package = pkgs.undervolt;
};
# superior power management
auto-cpufreq = {
enable = true;
settings = let
MHz = x: x * 1000;
in {
battery = {
governor = "powersave";
scaling_min_freq = mkDefault (MHz 1200);
scaling_max_freq = mkDefault (MHz 1800);
turbo = "never";
};
charger = {
governor = "performance";
scaling_min_freq = mkDefault (MHz 1800);
scaling_max_freq = mkDefault (MHz 3800);
turbo = "auto";
};
};
};
# DBus service that provides power management support to applications.
upower = {
enable = true;
percentageLow = 15;
percentageCritical = 5;
percentageAction = 3;
criticalPowerAction = "Hibernate";
};
};
boot = {
kernelModules = ["acpi_call"];
extraModulePackages = with config.boot.kernelPackages; [
acpi_call
cpupower
];
};
};
}

View file

@ -0,0 +1,40 @@
{
inputs',
pkgs,
lib,
...
}: let
inherit (builtins) readFile;
inherit (lib.modules) mkForce;
inherit (lib.strings) makeBinPath;
dependencies = with pkgs;
[
coreutils
power-profiles-daemon
inotify-tools
jaq
]
++ [
inputs'.hyprland.packages.hyprland
];
in {
config = {
# Power state monitor. Switches Power profiles based on charging state.
# Plugged in - performance
# Unplugged - power-saver
systemd.services."power-monitor" = {
description = "Power Monitoring Service";
environment.PATH = mkForce "/run/wrappers/bin:${makeBinPath dependencies}";
script = readFile ./scripts/power_monitor.sh;
serviceConfig = {
Type = "simple";
Restart = "on-failure";
};
wants = ["power-profiles-daemon.service"];
wantedBy = ["default.target"];
};
};
}

View file

@ -0,0 +1,69 @@
#!/usr/bin/env bash
BAT=$(echo /sys/class/power_supply/BAT*)
BAT_STATUS="$BAT/status"
BAT_CAP="$BAT/capacity"
AC_PROFILE="performance"
BAT_PROFILE="balanced"
# low and critical battery levels
LOW_BAT_PERCENT=25
CRIT_BAT_PERCENT=5
# how long to wait before suspending
SUSPEND_WAIT=60s
# define the wait & suspend function
wait_and_suspend() {
sleep "$SUSPEND_WAIT"
# check if we're still discharging
if [[ $(cat "$BAT_STATUS") == "Discharging" ]]; then
systemctl suspend
fi
}
# wait a while if needed
[[ -z $STARTUP_WAIT ]] || sleep "$STARTUP_WAIT"
# start the monitor loop
prev=0
while true; do
# read the current state
if [[ $(cat "$BAT_STATUS") == "Discharging" ]]; then
profile=$BAT_PROFILE
else
profile=$AC_PROFILE
fi
# set the new profile
if [[ $prev != "$profile" ]]; then
echo -en "Setting power profile to ${profile}\n"
powerprofilesctl set $profile
fi
prev=$profile
if [[ $(cat "$BAT_CAP") -le $LOW_BAT_PERCENT && $BAT_STATUS == "Discharging" ]]; then
notify-send --urgency=critical --hint=int:transient:1 --icon=battery_empty "Battery Low" \
"Consider plugging in."
for i in $(hyprctl instances -j | jaq ".[].instance" -r); do
hyprctl -i "$i" --batch 'keyword decoration:blur:enabled false; keyword animations:enabled false'
done
fi
if [[ $(cat "$BAT_CAP") -le $CRIT_BAT_PERCENT && $BAT_STATUS == "Discharging" ]]; then
notify-send --urgency=critical --hint=int:transient:1 --icon=battery_empty "Battery Critically Low" \
"Computer will suspend in 60 seconds."
wait_and_suspend &
fi
if [[ $(cat "$BAT_CAP") -gt $LOW_BAT_PERCENT && $BAT_STATUS == "Charging" ]]; then
for i in $(hyprctl instances -j | jaq ".[].instance" -r); do
hyprctl -i "$i" --batch 'keyword decoration:blur:enabled true; keyword animations:enabled true'
done
fi
# wait for the next power change event
inotifywait -qq "$BAT_STATUS" "$BAT_CAP"
done

View file

@ -0,0 +1,133 @@
let
MHz = x: x * 1000;
in {
config = {
services = {
tlp = {
enable = false;
settings = {
TLP_ENABLE = 1;
TLP_DEFAULT_MODE = "BAT";
# Timeout (in seconds) for the audio power saving mode (supports Intel HDA, AC97).
# A value of 1 is recommended for Linux desktop environments with PulseAudio,
# systems without PulseAudio may require 10. The value 0 disables power save.
SOUND_POWER_SAVE_ON_AC = 10;
SOUND_POWER_SAVE_ON_BAT = 10;
# SOUND_POWER_SAVE_CONTROLLER = "Y";
START_CHARGE_THRESH_BAT0 = 80;
STOP_CHARGE_THRESH_BAT0 = 95;
RESTORE_THRESHOLDS_ON_BAT = 1;
# battery care drivers
# NATACPI_ENABLE = 1;
# TPACPI_ENABLE = 1;
# TPSMAPI_ENABLE = 1;
# DISK_DEVICES = "nvme0n1 mmcblk0";
# DISK_APM_LEVEL_ON_AC = "254 254";
# DISK_APM_LEVEL_ON_BAT = "128 128";
# DISK_IDLE_SECS_ON_AC=0;
DISK_IDLE_SECS_ON_BAT = 5;
# Timeout (in seconds) for writing unsaved data in file system buffers to disk.
# MAX_LOST_WORK_SECS_ON_AC = 15;
# MAX_LOST_WORK_SECS_ON_BAT = 60;
# RADEON_DPM_PERF_LEVEL_ON_AC = "auto";
RADEON_DPM_PERF_LEVEL_ON_BAT = "low";
# RADEON_DPM_STATE_ON_AC = "performance";
# RADEON_DPM_STATE_ON_BAT = "battery";
RADEON_POWER_PROFILE_ON_AC = "high";
RADEON_POWER_PROFILE_ON_BAT = "low";
# NMI_WATCHDOG = 0;
# Sets Wi-Fi power saving mode. Adapter support depends on kernel and driver.
# WIFI_PWR_ON_AC = "off";
# WIFI_PWR_ON_BAT = "on";
# WOL_DISABLE = "Y";
# Select the platform profile to control system operating characteristics
# around power/performance levels, thermal and fan speed.
# PLATFORM_PROFILE_ON_AC = "performance";
# PLATFORM_PROFILE_ON_BAT = "low-power";
# <https://www.kernel.org/doc/html/latest/admin-guide/pm/cpufreq.html>
CPU_SCALING_GOVERNOR_ON_AC = "schedutil";
CPU_SCALING_GOVERNOR_ON_BAT = "powersave";
CPU_SCALING_MIN_FREQ_ON_AC = MHz 1400;
CPU_SCALING_MAX_FREQ_ON_AC = MHz 1700;
CPU_SCALING_MIN_FREQ_ON_BAT = MHz 1400;
CPU_SCALING_MAX_FREQ_ON_BAT = MHz 1600;
CPU_BOOST_ON_AC = 1;
CPU_BOOST_ON_BAT = 0;
# SCHED_POWERSAVE_ON_AC = 0;
# SCHED_POWERSAVE_ON_BAT = 1;
# Restores radio device state (builtin Bluetooth, Wi-Fi, WWAN) from previous shutdown on boot.
# RESTORE_DEVICE_STATE_ON_STARTUP = 0;
DEVICES_TO_DISABLE_ON_STARTUP = "bluetooth wwan";
DEVICES_TO_ENABLE_ON_STARTUP = "wifi";
# DEVICES_TO_DISABLE_ON_SHUTDOWN = "bluetooth wifi wwan";
# DEVICES_TO_ENABLE_ON_SHUTDOWN = "bluetooth wifi wwan";
# has precedence
DEVICES_TO_ENABLE_ON_AC = "";
DEVICES_TO_DISABLE_ON_BAT = "";
DEVICES_TO_DISABLE_ON_BAT_NOT_IN_USE = "bluetooth wwan";
DEVICES_TO_DISABLE_ON_LAN_CONNECT = "wwan";
DEVICES_TO_DISABLE_ON_WIFI_CONNECT = "";
DEVICES_TO_DISABLE_ON_WWAN_CONNECT = "wifi";
DEVICES_TO_ENABLE_ON_LAN_DISCONNECT = "wifi";
DEVICES_TO_ENABLE_ON_WIFI_DISCONNECT = "";
DEVICES_TO_ENABLE_ON_WWAN_DISCONNECT = "";
DEVICES_TO_ENABLE_ON_DOCK = "wifi bluetooth";
# DEVICES_TO_DISABLE_ON_DOCK = "";
DEVICES_TO_ENABLE_ON_UNDOCK = "";
DEVICES_TO_DISABLE_ON_UNDOCK = "bluetooth";
# RUNTIME_PM_ON_AC = "on";
# RUNTIME_PM_ON_BAT = "auto";
# RUNTIME_PM_DENYLIST = "11:22.3 44:55.6";
RUNTIME_PM_DRIVER_DENYLIST = "mei_me nouveau radeon psmouse";
# RUNTIME_PM_ENABLE="11:22.3";
# RUNTIME_PM_DISABLE="44:55.6";
# PCIE_ASPM_ON_AC = "default";
PCIE_ASPM_ON_BAT = "powersupersave";
# USB_AUTOSUSPEND = 1;
# USB_DENYLIST = "1111:2222 3333:4444";
# USB_EXCLUDE_AUDIO = 1;
# USB_EXCLUDE_BTUSB = 1;
# USB_EXCLUDE_PHONE = 1;
# USB_EXCLUDE_PRINTER = 1;
# USB_EXCLUDE_WWAN = 0;
# USB_ALLOWLIST="5555:6666 7777:8888";
# USB_AUTOSUSPEND_DISABLE_ON_SHUTDOWN = 0;
};
};
};
};
}

View file

@ -0,0 +1,27 @@
{
config = {
services = {
# Input settings for libinput
xserver.libinput = {
# enable libinput
enable = true;
# disable mouse acceleration
mouse = {
accelProfile = "flat";
accelSpeed = "0";
middleEmulation = false;
};
# touchpad settings
touchpad = {
naturalScrolling = true;
tapping = true;
clickMethod = "clickfinger";
horizontalScrolling = false;
disableWhileTyping = true;
};
};
};
};
}