Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move battery options to non-asus specific folder #965

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
37 changes: 0 additions & 37 deletions asus/battery.nix

This file was deleted.

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
69 changes: 69 additions & 0 deletions common/pc/laptop/battery.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
config,
pkgs,
lib,
...
}:
let
# This interface works for most Asus, Lenovo Thinkpad, LG, System76, and Toshiba laptops
# A list of supported laptop models/vendors supporting the following interface can be found
# at https://linrunner.de/tlp/settings/bc-vendors.html
# If your laptop isn't supported, considering installing and using the tlp package's setcharge command instead
interfaces = "/sys/class/power_supply/BAT?/charge_control_end_threshold";
charge-upto-script = pkgs.writeScriptBin "charge-upto" ''
echo ''${1:-100} >${interfaces}
'';
cfg = config.hardware.battery;
in

{
options.hardware.battery = {
chargeUpto = lib.mkOption {
description = "Maximum level of charge for your battery, as a percentage. Applies threshold to all installed batteries";
default = 100;
type = lib.types.int;
};
enableChargeUptoScript = lib.mkOption {
description = "Whether to add charge-upto script to environment.systemPackages. `charge-upto 75` temporarily sets the charge limit to 75%.";
default = true;
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 [ charge-upto-script ];
systemd.services.battery-charge-threshold = {
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;
fidgetingbits marked this conversation as resolved.
Show resolved Hide resolved
serviceConfig = {
Type = "oneshot";
Restart = "on-failure";
ExecStart = "${pkgs.runtimeShell} -c 'echo ${toString cfg.chargeUpto} > ${interfaces}'";
};
};
};
}
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
apple-macbook-pro-14-1 = import ./apple/macbook-pro/14-1;
apple-macmini-4-1 = import ./apple/macmini/4;
apple-t2 = import ./apple/t2;
asus-battery = import ./asus/battery.nix;
asus-ally-rc71l = import ./asus/ally/rc71l;
asus-fx504gd = import ./asus/fx504gd;
asus-fa507nv = import ./asus/fa507nv;
Expand Down Expand Up @@ -259,6 +258,7 @@
common-pc-hdd = import ./common/pc/hdd;
common-pc-laptop = import ./common/pc/laptop;
common-pc-laptop-acpi_call = import ./common/pc/laptop/acpi_call.nix;
common-pc-laptop-battery = import ./common/pc/laptop/battery.nix;
common-pc-laptop-hdd = import ./common/pc/laptop/hdd;
common-pc-laptop-ssd = import ./common/pc/ssd;
common-pc-ssd = import ./common/pc/ssd;
Expand Down
Loading