From 43e9c908bc5cfc0c61b19d5217488f8cea669792 Mon Sep 17 00:00:00 2001 From: Adithya Nair Date: Thu, 6 Apr 2023 02:05:55 +0530 Subject: [PATCH] move power-profiles script to package --- home/scripts.nix | 46 ------------------------------ packages/scripts/default.nix | 9 ++++-- packages/scripts/power-profiles.sh | 36 +++++++++++++++++++++++ 3 files changed, 42 insertions(+), 49 deletions(-) create mode 100644 packages/scripts/power-profiles.sh diff --git a/home/scripts.nix b/home/scripts.nix index 6723f71..366c1a9 100644 --- a/home/scripts.nix +++ b/home/scripts.nix @@ -65,51 +65,5 @@ in ;; esac''; }; - "scripts/power_profile.sh" = - let - sudo = "/run/wrappers/bin/sudo"; - cpupower = "${osConfig.boot.kernelPackages.cpupower}/bin/cpupower"; - powerprofilesctl = "${pkgs.power-profiles-daemon}/bin/powerprofilesctl"; - in - { - executable = true; - text = '' - #!/bin/sh - - set -eu - - POWER_PROFILE_FILE="$HOME/.cache/power_profile" - POWER_PROFILE="powersave" - - if [ -f "$POWER_PROFILE_FILE" ]; then - POWER_PROFILE="$(<$POWER_PROFILE_FILE)" - fi - - case "$1" in - "toggle") - if [ "$POWER_PROFILE" == "powersave" ]; then - ${sudo} ${cpupower} frequency-set --governor performance > /dev/null - ${powerprofilesctl} set performance - POWER_PROFILE="performance" - elif [ "$POWER_PROFILE" == "performance" ]; then - ${sudo} ${cpupower} frequency-set --governor powersave > /dev/null - ${powerprofilesctl} set power-saver - POWER_PROFILE="powersave" - fi - echo $POWER_PROFILE > $POWER_PROFILE_FILE - ${notify-send} -u normal "Power Profile" "Switched to $POWER_PROFILE mode." - ;; - "icon") - if [ "$POWER_PROFILE" == "powersave" ]; then - echo "󰌪" - elif [ "$POWER_PROFILE" == "performance" ]; then - echo "󰓅" - fi - ;; - *) - ;; - esac - ''; - }; }; } diff --git a/packages/scripts/default.nix b/packages/scripts/default.nix index d198e82..0706f3c 100644 --- a/packages/scripts/default.nix +++ b/packages/scripts/default.nix @@ -1,16 +1,19 @@ -{ lib, stdenvNoCC, makeWrapper, libnotify, rofi-wayland }: +{ lib, stdenvNoCC, makeWrapper, libnotify, rofi-wayland, power-profiles-daemon, cpupower }: stdenvNoCC.mkDerivation { pname = "scripts"; - version = "1.0"; src = ./.; nativeBuildInputs = [ makeWrapper ]; - buildInputs = [ ]; + buildInputs = [ libnotify rofi-wayland power-profiles-daemon cpupower ]; installPhase = '' mkdir -p $out/bin cp power-menu.sh $out/bin/power-menu chmod +x $out/bin/power-menu wrapProgram $out/bin/power-menu --prefix PATH : ${lib.makeBinPath [ libnotify rofi-wayland ]} + + cp power-profiles.sh $out/bin/power-profiles + chmod +x $out/bin/power-profiles + wrapProgram $out/bin/power-profiles --prefix PATH : ${lib.makeBinPath [ libnotify power-profiles-daemon cpupower ]} ''; } diff --git a/packages/scripts/power-profiles.sh b/packages/scripts/power-profiles.sh new file mode 100644 index 0000000..343aede --- /dev/null +++ b/packages/scripts/power-profiles.sh @@ -0,0 +1,36 @@ +#!/bin/sh + +set -eu + +POWER_PROFILE_FILE="$HOME/.cache/power_profile" +POWER_PROFILE="powersave" + +if [ -f "$POWER_PROFILE_FILE" ]; then + POWER_PROFILE="$(<$POWER_PROFILE_FILE)" +fi + +case "$1" in + "toggle") + if [ "$POWER_PROFILE" == "powersave" ]; then + cpupower frequency-set --governor performance > /dev/null + powerprofilesctl set performance + POWER_PROFILE="performance" + elif [ "$POWER_PROFILE" == "performance" ]; then + cpupower frequency-set --governor powersave > /dev/null + powerprofilesctl set power-saver + POWER_PROFILE="powersave" + fi + echo $POWER_PROFILE > $POWER_PROFILE_FILE + notify-send -u normal "Power Profile" "Switched to $POWER_PROFILE mode." + ;; + "icon") + if [ "$POWER_PROFILE" == "powersave" ]; then + echo "󰌪" + elif [ "$POWER_PROFILE" == "performance" ]; then + echo "󰓅" + fi + ;; + *) + ;; +esac +