Skip to content

Commit

Permalink
Move battery options to non-asus specific folder
Browse files Browse the repository at this point in the history
  • Loading branch information
fidgetingbits committed Jun 4, 2024
1 parent 753176b commit e8f916c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
2 changes: 1 addition & 1 deletion asus/ally/rc71l/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
../../../common/gpu/amd
../../../common/pc/laptop
../../../common/pc/laptop/ssd
../../battery.nix
../../../common/pc/laptop/battery.nix
];

# 6.5 adds many fixes and improvements for the Ally
Expand Down
2 changes: 1 addition & 1 deletion asus/rog-strix/g513im/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
../../../common/gpu/nvidia/prime.nix
../../../common/pc/laptop
../../../common/pc/ssd
../../battery.nix
../../../common/pc/laptop/battery.nix
];

hardware.nvidia.prime = {
Expand Down
2 changes: 1 addition & 1 deletion asus/rog-strix/g733qs/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
../../../common/gpu/nvidia/prime.nix
../../../common/pc/laptop
../../../common/pc/ssd
../../battery.nix
../../../common/pc/laptop/battery.nix
];

# fixing audio by overriding pins as suggested in
Expand Down
35 changes: 31 additions & 4 deletions asus/battery.nix → common/pc/laptop/battery.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{ config, pkgs, lib, ... }:
{
config,
pkgs,
lib,
...
}:
let
p = pkgs.writeScriptBin "charge-upto" ''
echo ''${0:-100} > /sys/class/power_supply/BAT?/charge_control_end_threshold
Expand All @@ -7,7 +12,7 @@ let
in

{
options.hardware.asus.battery = {
options.hardware.battery = {
chargeUpto = lib.mkOption {
description = "Maximum level of charge for your battery, as a percentage.";
default = 100;
Expand All @@ -19,11 +24,33 @@ in
type = lib.types.bool;
};
};
imports = (
map
(
option:
lib.mkRemovedOptionModule [
"hardware"
"asus"
"battery"
option
] "The hardware.asus.battery.* options were removed in favor of `hardware.battery.*`."
)
[
"chargeUpto"
"enableChargeUptoScript"
]
);
config = {
environment.systemPackages = lib.mkIf cfg.enableChargeUptoScript [ p ];
systemd.services.battery-charge-threshold = {
wantedBy = [ "local-fs.target" "suspend.target" ];
after = [ "local-fs.target" "suspend.target" ];
wantedBy = [
"local-fs.target"
"suspend.target"
];
after = [
"local-fs.target"
"suspend.target"
];
description = "Set the battery charge threshold to ${toString cfg.chargeUpto}%";
startLimitBurst = 5;
startLimitIntervalSec = 1;
Expand Down

0 comments on commit e8f916c

Please sign in to comment.