Skip to content

Commit 9c4a5c3

Browse files
committed
Move battery options to non-asus specific folder
1 parent 753176b commit 9c4a5c3

File tree

6 files changed

+73
-41
lines changed

6 files changed

+73
-41
lines changed

asus/ally/rc71l/default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
../../../common/gpu/amd
77
../../../common/pc/laptop
88
../../../common/pc/laptop/ssd
9-
../../battery.nix
9+
../../../common/pc/laptop/battery.nix
1010
];
1111

1212
# 6.5 adds many fixes and improvements for the Ally

asus/battery.nix

Lines changed: 0 additions & 37 deletions
This file was deleted.

asus/rog-strix/g513im/default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
../../../common/gpu/nvidia/prime.nix
77
../../../common/pc/laptop
88
../../../common/pc/ssd
9-
../../battery.nix
9+
../../../common/pc/laptop/battery.nix
1010
];
1111

1212
hardware.nvidia.prime = {

asus/rog-strix/g733qs/default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
../../../common/gpu/nvidia/prime.nix
66
../../../common/pc/laptop
77
../../../common/pc/ssd
8-
../../battery.nix
8+
../../../common/pc/laptop/battery.nix
99
];
1010

1111
# fixing audio by overriding pins as suggested in

common/pc/laptop/battery.nix

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
{
2+
config,
3+
pkgs,
4+
lib,
5+
...
6+
}:
7+
let
8+
# This interface works for most Asus, Lenovo Thinkpad, LG, System76, and Toshiba laptops
9+
# A list of supported laptop models/vendors supporting the following interface can be found
10+
# at https://linrunner.de/tlp/settings/bc-vendors.html
11+
# If your laptop isn't supported, considering installing and using the tlp package's setcharge command instead
12+
interfaces = "/sys/class/power_supply/BAT?/charge_control_end_threshold";
13+
charge-upto-script = pkgs.writeScriptBin "charge-upto" ''
14+
echo ''${1:-100} >${interfaces}
15+
'';
16+
cfg = config.hardware.battery;
17+
in
18+
19+
{
20+
options.hardware.battery = {
21+
chargeUpto = lib.mkOption {
22+
description = "Maximum level of charge for your battery, as a percentage. Applies threshold to all installed batteries";
23+
default = 100;
24+
type = lib.types.int;
25+
};
26+
enableChargeUptoScript = lib.mkOption {
27+
description = "Whether to add charge-upto script to environment.systemPackages. `charge-upto 75` temporarily sets the charge limit to 75%.";
28+
default = true;
29+
type = lib.types.bool;
30+
};
31+
};
32+
imports = (
33+
map
34+
(
35+
option:
36+
lib.mkRemovedOptionModule [
37+
"hardware"
38+
"asus"
39+
"battery"
40+
option
41+
] "The hardware.asus.battery.* options were removed in favor of `hardware.battery.*`."
42+
)
43+
[
44+
"chargeUpto"
45+
"enableChargeUptoScript"
46+
]
47+
);
48+
config = {
49+
environment.systemPackages = lib.mkIf cfg.enableChargeUptoScript [ charge-upto-script ];
50+
systemd.services.battery-charge-threshold = {
51+
wantedBy = [
52+
"local-fs.target"
53+
"suspend.target"
54+
];
55+
after = [
56+
"local-fs.target"
57+
"suspend.target"
58+
];
59+
description = "Set the battery charge threshold to ${toString cfg.chargeUpto}%";
60+
startLimitBurst = 5;
61+
startLimitIntervalSec = 1;
62+
serviceConfig = {
63+
Type = "oneshot";
64+
Restart = "on-failure";
65+
ExecStart = "${pkgs.runtimeShell} -c 'echo ${toString cfg.chargeUpto} > ${interfaces}'";
66+
};
67+
};
68+
};
69+
}

flake.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
apple-macbook-pro-14-1 = import ./apple/macbook-pro/14-1;
1616
apple-macmini-4-1 = import ./apple/macmini/4;
1717
apple-t2 = import ./apple/t2;
18-
asus-battery = import ./asus/battery.nix;
1918
asus-ally-rc71l = import ./asus/ally/rc71l;
2019
asus-fx504gd = import ./asus/fx504gd;
2120
asus-fa507nv = import ./asus/fa507nv;
@@ -259,6 +258,7 @@
259258
common-pc-hdd = import ./common/pc/hdd;
260259
common-pc-laptop = import ./common/pc/laptop;
261260
common-pc-laptop-acpi_call = import ./common/pc/laptop/acpi_call.nix;
261+
common-pc-laptop-battery = import ./common/pc/laptop/battery.nix;
262262
common-pc-laptop-hdd = import ./common/pc/laptop/hdd;
263263
common-pc-laptop-ssd = import ./common/pc/ssd;
264264
common-pc-ssd = import ./common/pc/ssd;

0 commit comments

Comments
 (0)