Battery charging limit / threshold for Gnome

Battey Health Charging Gnome Extension

  • Creating this post just to bring awareness to NixOS Gnome users, regarding Gnome extension to set Charging threshold / limit various laptops make/models.

https://extensions.gnome.org/extension/5724/battery-health-charging/

  • Lately with the help of NixOS user (Thanks to the users), the extension addressed issue of not working with NixOS, and now the extension is compatible and can be installed without any additional configuration required by NixOS

  • Using Battery Health Charging extension, some laptop models are supported out of the box, while others model that are not supported by native linux kernel need to install dependencies, either 3rd party kernel module or packages.

  • The below link for readme of extension Github pages, contains a list of laptop make/model and dependencies, if required. It also contains command-line to change threshold which can be helpful for if you want to change it without extension by using commandline only. Please check it out for more information. Although I am not sure about the procedure or configuration needed to install these dependencies if required on NixOS.

https://maniacx.github.io/Battery-Health-Charging/device-compatibility

Quick Settings and Extension Preference

I have seem lots of users in different forums asking for a GUI way to change battery charging limit/threshold and in most case the post gets locked in 3-4 days without the correct solution and I am unable to answer them, so I am creating this post. Most of user are even unaware that enthusiast have developed kernel modules and packages to change charging threshold.
Hope whoever needs this, finds this post.

List of supported laptop.

  • Asus
  • LG
  • Samsung
  • Sony
  • Huawei
  • Toshiba
  • System76
  • Lenovo (Ideapad, Legion)
  • Thinkpad
  • Panasonic
  • Acer (dependencies: kernel module)
  • MSI (dependencies: kernel module)
  • Tuxedo (dependencies: kernel module)
  • Slimbook (dependencies: kernel module)
  • Tuxedo IntelQC71 (dependencies: kernel module)
  • XMG IntelQC71 (dependencies: kernel module)
  • Eluktronics IntelQC71 (dependencies: kernel module)
  • Gigabyte Aero/Aorus (dependencies: kernel module)
  • Dell (dependencies: custom package libsmbios)
  • Dell (dependencies: custom package Dell Command Center)
  • Apple Macbook Intel-series chip (dependencies: kernel module)
  • Apple Macbook M-series chip (dependencies: custom kernel)
  • Razer (dependencies: custom package razer-cli)
  • Framework (dependencies: kernel module)

Additionally seeking assistance with translation contributions.
Thank you.

5 Likes

Very nice application, but on my Dell it searches for tools from the libsmbios project. it needs a symbolic link like this:
sudo ln -s /run/current-system/sw/bin/smbios-battery-ctl /usr/sbin/

I am still new to nixos. I guess there is some way to declare that in the configuration.nix instead of doing it manually in the cli.

I am also not familiar with Nix-OS. There was a request from a NixOS user, due incompatibility with polkit rules, and it was fixed. That was the only time I uised nixos on a Virtual Machine.

I did not take into account that for Dell and Razer with rely on packages like libsmbios, dell control center and razer-cli, since all packages are not at their default location this would be an issue.

Yes, we probably need to come up with a nix configuration, to symlink the path.
If you manage to do so ping me here.
I will also attempt to make this in my free time, but since I am unfamiliar it my take longer.

Solution would be using the program from PATH rather than from the hardcoded path:

I guess the hardcoded path can serve as a fallback in case /usr/sbin is not on PATH.

But the cctk path is non-standard so there is no portable method to find it. And Nixpkgs does not even have it packaged, so that will be a bigger problem.

By the way, there is a proposal to eventually integrate this feature into UPower and gnome-control-center.

1 Like

dell-command-configure is there, FWIW

Ah, you are right.

$ exa -T $(nix-build -A dell-command-configure)
/nix/store/j79h87ivqqm0gxdzirxxkm9bh8qjvq1w-dell-command-configure-4.8.0-494
β”œβ”€β”€ bin
β”‚  β”œβ”€β”€ cctk
β”‚  └── dchcfg
└── lib
   β”œβ”€β”€ libdchapi.so.9
   β”œβ”€β”€ libdchbas.so.9
   β”œβ”€β”€ libdchcfl.so.9
   β”œβ”€β”€ libdchesm.so.9
   β”œβ”€β”€ libdchipm.so.9
   β”œβ”€β”€ libdchtvm.so.9
   β”œβ”€β”€ libhapiintf.so
   └── libsmbios_c.so.2

So we could require people to install pkgs.dell-command-configure and pkgs.libsmbios have both picked up from PATH, only falling back to the hardcoded paths.

And for people installing the extension from Nixpkgs, we could even patch the paths to avoid the need for manual installation. Although, since this does not allow expressing optional dependencies, relying on PATH will probably be better, to avoid bloating the closure size.

hardcoded path is needed as it is also a way to detect if libsmbios or dell command center is installed and use appropriate commands.

But I can add a hardcoded path for NixOS too (If they dont change)

https://github.com/maniacx/Battery-Health-Charging/commit/5d2fdb4502d1332d7b1a73ad29cd15b0a90b96ca

I do not have dell but I have do have NixOS running on VM but I cannot test this.

This will work only if the following path for smbios-battery-ctl doesnt change. Meaning if libsmbios is installed on NixOS the path should always be
run/current-system/sw/bin/smbios-battery-ctl

Also I am not sure regarding cctk path? is this correct?
/run/current-system/sw/bin/command-configure/opt/dell/dcc/cctk

Let me know if the paths are correct or if they can change in certain situation or they are always at the same path…

@ NeuerUser Can you test the extension in branch NixOS-Dell on Github? Remove any symlinks added.

The whole point of Nix is that there is no global filesystem hierarchy. /run/current-system/sw/bin would work when the programs are installed through environment.systemPackages NixOS option but we also have users that install programs to their home profile, or even use Nix on other Linux distros.

The only portable way would then would be something like the following – look for the program on PATH for Nix and, if it does not exist, look on the fallback path:

const CCTK_PATH: string|null = GLib.find_program_in_path('cctk') ?? GLib.find_program_in_path('/opt/dell/dcc/cctk');

GLib.find_program_in_path returns null when the program does not exist or is not executable.

It would be /run/current-system/sw/bin/cctk. The package trees for packages installed using environment.systemPackages NixOS option will be partly linked to /run/current-system/sw. And dell-command-configure package has the the programs directly in $out/bin – as much as Nix does not have global FHS-like hierarchy, Nixpkgs usually enforces it locally in package output tree.

Thanks @jtojnar
I implemented your suggestion. Check for program in PATH and uses it relative_path,
if not check for Absolute path and use Absolute path.

So for NixOS it will just use.

smbios-battery-ctl --set-charging-mode='adaptive'
cctk --PrimaryBattChargeCfg=Adaptive

https://github.com/maniacx/Battery-Health-Charging/commit/3e9ff89e7cbfc2a05a38ee39cde820c75d45cb90

Let me know if this works, so that I can merge it with the main branch

Thanks a lot for adding this so fast.

I’m still very new to nixos, so have no idea how-to build packages from source and to replace the ones from the nixos repo. So, sorry, but I cannot test it. :man_shrugging:

If you mean building and installin extension from source.
In github choose branch nixos and download/and extract. You will see a folder β€œBattery-Health-Charging-nixos”

Correct method

  1. Open folder, Right-click > Open in Console and type ./install.sh.
  2. It might ask to install gettext, if gettext is missing. You can install it running command
    nix-env -iA nixos.**gettext**.
    After installing gettext run extesnsion installer again using ./install.sh
  3. Logout and Re-login, conitnue using extension

If you mean building libsmbios or cctk from source, than I am afraid even I do not know.

No problem. I understand if cannot test. But if you do manage to test it kindly update me. Thank you

@NeuerUser I have already released the an updated compatible version on gnome extension.

Great. I tested the new version, removed the symlink, and everything works. Thanks a lot!

The extension, ver 51 does not seem to detect smbios-battery-ctl in the path.

Both the extension and smbios-battery-ctl are installed through nixpkgs.

Hello Lyndeno.
Sorry for late reply. What is happening with the extension? are you seeing any error message?

Can you run the command smbios-battery-ctl --version just to make sure it is in path?

No error message, no driver/device specific config tab showing up.

I am not at my computer currently, but can confirm that I can run smbios-battery-ctl from the command line without any special steps. So it should be in PATH.

The quick settings button also does not show up

I am NixOS noob, I just install it in a Vm just to debug issue with NixOS.
All this time I was using Battery Health Charging extension installing from Github.
I tried nix-env -iA nixos.gnomeExtensions.baattery-health-charging
it install an run as a system extension.
and it is still on version 37. How do I update it to the latest one

I am running nixos-unstable, which is currently running battery-health-charging version 51. This isn’t working.

I do not know how to backport extension updates to the stable channel.