move power-profiles script to package

This commit is contained in:
Adithya 2023-04-06 02:05:55 +05:30
parent 90999017a1
commit 43e9c908bc
Signed by: adtya
GPG key ID: 48FC9915FFD326D0
3 changed files with 42 additions and 49 deletions

View file

@ -65,51 +65,5 @@ in
;; ;;
esac''; 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
'';
};
}; };
} }

View file

@ -1,16 +1,19 @@
{ lib, stdenvNoCC, makeWrapper, libnotify, rofi-wayland }: { lib, stdenvNoCC, makeWrapper, libnotify, rofi-wayland, power-profiles-daemon, cpupower }:
stdenvNoCC.mkDerivation { stdenvNoCC.mkDerivation {
pname = "scripts"; pname = "scripts";
version = "1.0";
src = ./.; src = ./.;
nativeBuildInputs = [ makeWrapper ]; nativeBuildInputs = [ makeWrapper ];
buildInputs = [ ]; buildInputs = [ libnotify rofi-wayland power-profiles-daemon cpupower ];
installPhase = '' installPhase = ''
mkdir -p $out/bin mkdir -p $out/bin
cp power-menu.sh $out/bin/power-menu cp power-menu.sh $out/bin/power-menu
chmod +x $out/bin/power-menu chmod +x $out/bin/power-menu
wrapProgram $out/bin/power-menu --prefix PATH : ${lib.makeBinPath [ libnotify rofi-wayland ]} 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 ]}
''; '';
} }

View file

@ -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