snowfall migration wip homepc done

This commit is contained in:
Aleksandr Lebedev 2025-08-09 17:07:55 +02:00
parent ed08a98651
commit 25774148e4
37 changed files with 1943 additions and 1447 deletions

View file

@ -0,0 +1,88 @@
{
config,
namespace,
pkgs,
...
}: let
cfg = config.${namespace}.hardware.battery;
battery-path = "/sys/class/power_supply/${cfg.batteryName}";
get-battery-level = "${pkgs.writeShellScriptBin "get-battery-level" ''
cat ${battery-path}/capacity 2>/dev/null || echo "N/A"
''}/bin/get-battery-level";
get-status = "${pkgs.writeShellScriptBin "get-status" ''
cat ${battery-path}/status 2>/dev/null || echo "Unknown"
''}/bin/get-status";
get-icon = "${pkgs.writeShellScriptBin "get-icon" ''
BATTERY_LEVEL=$(${get-battery-level})
STATUS=$(${get-status})
if [[ "$BATTERY_LEVEL" == "N/A" ]]; then
ICON="󰂑 "
elif [[ "$STATUS" == "Charging" ]]; then
if [[ $BATTERY_LEVEL -ge 90 ]]; then
ICON="󰂋 "
elif [[ $BATTERY_LEVEL -ge 80 ]]; then
ICON="󰂊 "
elif [[ $BATTERY_LEVEL -ge 70 ]]; then
ICON="󰢞 "
elif [[ $BATTERY_LEVEL -ge 60 ]]; then
ICON="󰂉 "
elif [[ $BATTERY_LEVEL -ge 50 ]]; then
ICON="󰢝 "
elif [[ $BATTERY_LEVEL -ge 40 ]]; then
ICON="󰂈 "
elif [[ $BATTERY_LEVEL -ge 30 ]]; then
ICON="󰂇 "
elif [[ $BATTERY_LEVEL -ge 20 ]]; then
ICON="󰂆 "
elif [[ $BATTERY_LEVEL -ge 10 ]]; then
ICON="󰢜 "
else
ICON="󰢜 "
fi
else
if [[ $BATTERY_LEVEL -ge 90 ]]; then
ICON="󰂂 "
elif [[ $BATTERY_LEVEL -ge 70 ]]; then
ICON="󰂀 "
elif [[ $BATTERY_LEVEL -ge 50 ]]; then
ICON="󰁾 "
elif [[ $BATTERY_LEVEL -ge 30 ]]; then
ICON="󰁼 "
elif [[ $BATTERY_LEVEL -ge 10 ]]; then
ICON="󰁺 "
else
ICON="󰁺 "
fi
fi
echo "$ICON"
''}/bin/get-icon";
get-remaining-time = "${pkgs.writeShellScriptBin "get-remaining-time" ''
REMAINING_ENERGY=$(cat ${battery-path}/${cfg.remainingEnergy})
POWER_USAGE=$(cat ${battery-path}/${cfg.powerUsage})
if [[ -n "$REMAINING_ENERGY" && -n "$POWER_USAGE" && "$POWER_USAGE" -ne 0 ]]; then
TIME_LEFT=$(((REMAINING_ENERGY / POWER_USAGE)))
MINUTES_LEFT=$(((( (REMAINING_ENERGY * 60) / POWER_USAGE )) - (TIME_LEFT * 60)))
echo "$TIME_LEFT h $MINUTES_LEFT min"
else
echo ""
fi
''}/bin/get-remaining-time";
in {
${namespace}.hardware.battery.scripts = {
icon = get-icon;
status = get-status;
time = get-remaining-time;
level = get-battery-level;
labelAdaptive = "${pkgs.writeShellScriptBin "labelAdaptive" ''
if [[ "$(${get-status})" == "Charging" ]]; then
echo "$(${get-battery-level})% $(${get-icon})"
else
echo "$(${get-remaining-time}) $(${get-icon})"
fi
''}/bin/labelAdaptive";
labelPercent = "${pkgs.writeShellScriptBin "labelPercent" ''
echo "$(${get-battery-level})% $(${get-icon})"
''}/bin/labelPercent";
};
}

View file

@ -0,0 +1,38 @@
{
lib,
pkgs,
namespace,
config,
...
}:
with lib;
with lib.${namespace}; let
cfg = config.${namespace}.hardware.battery;
in {
options.${namespace}.hardware.battery = with types; {
enable = mkBoolOpt false "If you have a battery in your hardware, enable this";
batteryName = mkOpt str "BAT1" ''
Put your battery name here. You can find it at "/sys/class/power_supply/"
'';
remainingEnergy = mkOpt str "charge_now" ''
File in your battery, that tells the current amount of energy
'';
powerUsage = mkOpt str "current_now" ''
File in your battery, that tells, how much energy your hardware is using
'';
scripts = {
icon = mkOpt' str "";
status = mkOpt' str "";
time = mkOpt' str "";
level = mkOpt' str "";
labelAdaptive = mkOpt' str "";
labelPercent = mkOpt' str "";
};
};
config = mkIf cfg.enable (import ./batteryStatus.nix {
inherit config;
inherit namespace;
inherit pkgs;
});
}