fixup power config

This commit is contained in:
Grimmauld 2024-05-02 15:04:38 +02:00
parent 388a6da603
commit ecfbf9a557
Signed by: Grimmauld
GPG key ID: C2946668769F91FB
7 changed files with 89 additions and 57 deletions

View file

@ -48,7 +48,8 @@ let
+ (optionalString (value.pos != null) " position ${value.pos}") + (optionalString (value.pos != null) " position ${value.pos}")
) )
cfg.screens; cfg.screens;
in '' in
''
for pid in $(${pkgs.procps}/bin/pgrep sway -x) for pid in $(${pkgs.procps}/bin/pgrep sway -x)
do do
uid=$(id -u $(${pkgs.procps}/bin/ps -o user= -p $pid)) uid=$(id -u $(${pkgs.procps}/bin/ps -o user= -p $pid))
@ -111,6 +112,12 @@ in
sway_conf = lib.concatLines ( sway_conf = lib.concatLines (
(build_conf cfg.sway.config) (build_conf cfg.sway.config)
++ lib.optional cfg.sway.bar.enable bar_config ++ lib.optional cfg.sway.bar.enable bar_config
++ (lib.mapAttrsToList
(name: value:
"output ${value.id} mode ${value.mode}"
+ (lib.optionalString (value.pos != null) " position ${value.pos}")
)
cfg.screens)
); );
conf_path = "sway.conf"; conf_path = "sway.conf";

View file

@ -1,6 +1,6 @@
{ {
imports = [ imports = [
./laptop.nix ./laptop.nix
# ./tlp.nix ./tlp.nix
]; ];
} }

View file

@ -3,7 +3,7 @@ let
cfg = config.grimmShared; cfg = config.grimmShared;
inherit (lib) optionals optional optionalString concatLines getExe; inherit (lib) optionals optional optionalString concatLines getExe;
inherit (config.boot.kernelPackages) x86_energy_perf_policy cpupower; inherit (config.boot.kernelPackages) x86_energy_perf_policy cpupower;
enable_perf_policy = (lib.elem system x86_energy_perf_policy.meta.platforms) && false; enable_perf_policy = (lib.elem system x86_energy_perf_policy.meta.platforms);
powersave = with pkgs; writeShellScriptBin "powersave-mode" (concatLines ([ powersave = with pkgs; writeShellScriptBin "powersave-mode" (concatLines ([
"${getExe cpupower} frequency-set -g powersave -u 2000000" # clock speed "${getExe cpupower} frequency-set -g powersave -u 2000000" # clock speed
@ -20,6 +20,10 @@ let
"${getExe x86_energy_perf_policy} 0" # performance preference "${getExe x86_energy_perf_policy} 0" # performance preference
"${getExe x86_energy_perf_policy} --turbo-enable 1" # enable turbo "${getExe x86_energy_perf_policy} --turbo-enable 1" # enable turbo
] ++ optional cfg.sway.enable "init-screens-max")); ] ++ optional cfg.sway.enable "init-screens-max"));
auto = let inherit (pkgs) tlp; in pkgs.writeShellScriptBin "auto-mode" ''
${tlp}/bin/run-on-ac ${getExe performance}
${tlp}/bin/run-on-bat ${getExe powersave}
'';
in in
{ {
config = with cfg; lib.mkIf (enable && laptop_hardware.enable) { config = with cfg; lib.mkIf (enable && laptop_hardware.enable) {
@ -30,10 +34,16 @@ in
cpupower cpupower
powersave powersave
performance performance
auto
] ++ optionals graphical [ ] ++ optionals graphical [
tlpui tlpui
] ++ optional enable_perf_policy x86_energy_perf_policy; ] ++ optional enable_perf_policy x86_energy_perf_policy;
services.acpid = {
enable = true;
acEventCommands = getExe auto;
};
powerManagement.scsiLinkPolicy = lib.mkIf (!config.services.tlp.enable) "min_power"; powerManagement.scsiLinkPolicy = lib.mkIf (!config.services.tlp.enable) "min_power";
powerManagement.cpuFreqGovernor = lib.mkDefault "normal"; powerManagement.cpuFreqGovernor = lib.mkDefault "normal";

View file

@ -1,9 +1,11 @@
# Do not modify this file! It was generated by nixos-generate-config # Do not modify this file! It was generated by nixos-generate-config
# and may be overwritten by future invocations. Please make changes # and may be overwritten by future invocations. Please make changes
# to /etc/nixos/configuration.nix instead. # to /etc/nixos/configuration.nix instead.
{ config, lib, pkgs, modulesPath, ... }: let { config, lib, pkgs, modulesPath, ... }:
let
cpus = "12"; cpus = "12";
in { in
{
imports = imports =
[ [
(modulesPath + "/installer/scan/not-detected.nix") (modulesPath + "/installer/scan/not-detected.nix")

View file

@ -32,7 +32,8 @@ in
config = with pkgs; let config = with pkgs; let
inherit (lib) getExe; inherit (lib) getExe;
in { in
{
definitions = { definitions = {
mod = "Mod4"; mod = "Mod4";
left = "h"; left = "h";
@ -153,21 +154,33 @@ in
XF86MonBrightnessDown = "exec ${getExe brightnessctl} s 10-%"; XF86MonBrightnessDown = "exec ${getExe brightnessctl} s 10-%";
XF86Explorer = "exec $term --command ${getExe ranger}"; XF86Explorer = "exec $term --command ${getExe ranger}";
XF86Search = "exec ${getExe searchclip}"; XF86Search = "exec ${getExe searchclip}";
XF86HomePage = let open = pkgs.writeShellScriptBin "open_or_switch_browser" '' XF86HomePage =
let
open = pkgs.writeShellScriptBin "open_or_switch_browser" ''
browser=$(xdg-settings get default-web-browser | sed "s/\.desktop//") browser=$(xdg-settings get default-web-browser | sed "s/\.desktop//")
swaymsg [app_id="$browser"] focus || deskwhich $browser | xargs gio launch swaymsg [app_id="$browser"] focus || deskwhich $browser | xargs gio launch
''; in "exec ${getExe open}"; '';
XF86Tools = let open = pkgs.writeShellScriptBin "open_or_switch_spotify" '' in
"exec ${getExe open}";
XF86Tools =
let
open = pkgs.writeShellScriptBin "open_or_switch_spotify" ''
# FIXME: spotify is being weird # FIXME: spotify is being weird
while IFS= read -r pid; do while IFS= read -r pid; do
swaymsg [pid=$pid] focus && exit 0 swaymsg [pid=$pid] focus && exit 0
done <<< $(pgrep spotify -u "$(whoami)") done <<< $(pgrep spotify -u "$(whoami)")
deskwhich spotify | xargs gio launch deskwhich spotify | xargs gio launch
''; in "exec ${getExe open}"; # for some reason tools = audio media on my keyboard?? '';
XF86Mail = let open = pkgs.writeShellScriptBin "open_or_switch_mail" '' in
"exec ${getExe open}"; # for some reason tools = audio media on my keyboard??
XF86Mail =
let
open = pkgs.writeShellScriptBin "open_or_switch_mail" ''
desk=$(xdg-settings get default-url-scheme-handler mailto | sed "s/\.desktop//") desk=$(xdg-settings get default-url-scheme-handler mailto | sed "s/\.desktop//")
swaymsg [app_id="$desk"] focus || deskwhich $desk | xargs gio launch swaymsg [app_id="$desk"] focus || deskwhich $desk | xargs gio launch
''; in "exec ${getExe open}"; '';
in
"exec ${getExe open}";
# XF86Bluetooth = "exec blueman-manager"; # XF86Bluetooth = "exec blueman-manager";
}; };
autolaunch = with pkgs; [ autolaunch = with pkgs; [