1
0
Fork 0
mirror of https://github.com/NixOS/nixos-hardware synced 2024-11-26 21:09:42 +01:00

Move battery options to non-asus specific folder

This commit is contained in:
fidgetingbits 2024-06-03 23:36:38 +08:00
parent 753176b57b
commit 9c4a5c3cf3
No known key found for this signature in database
6 changed files with 73 additions and 41 deletions

View file

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

View file

@ -1,37 +0,0 @@
{ config, pkgs, lib, ... }:
let
p = pkgs.writeScriptBin "charge-upto" ''
echo ''${0:-100} > /sys/class/power_supply/BAT?/charge_control_end_threshold
'';
cfg = config.hardware.asus.battery;
in
{
options.hardware.asus.battery = {
chargeUpto = lib.mkOption {
description = "Maximum level of charge for your battery, as a percentage.";
default = 100;
type = lib.types.int;
};
enableChargeUptoScript = lib.mkOption {
description = "Whether to add charge-upto to environment.systemPackages. `charge-upto 75` temporarily sets the charge limit to 75%.";
default = true;
type = lib.types.bool;
};
};
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" ];
description = "Set the battery charge threshold to ${toString cfg.chargeUpto}%";
startLimitBurst = 5;
startLimitIntervalSec = 1;
serviceConfig = {
Type = "oneshot";
Restart = "on-failure";
ExecStart = "${pkgs.runtimeShell} -c 'echo ${toString cfg.chargeUpto} > /sys/class/power_supply/BAT?/charge_control_end_threshold'";
};
};
};
}

View file

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

View file

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

View file

@ -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;
serviceConfig = {
Type = "oneshot";
Restart = "on-failure";
ExecStart = "${pkgs.runtimeShell} -c 'echo ${toString cfg.chargeUpto} > ${interfaces}'";
};
};
};
}

View file

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