NixOS Drains my Laptop Battery in 10 min

Hi Guys,

I just installed NIxoS on my Thinkpad X1 Carbon that is 3 years old. My battery drains within 10 min if its unplugged. I used to have Manjaro installed and my battery would last an hour or more, with Nixos i barely have enough time to make a coffee before my battery is almost drained.

Please point me in the right direction to see what config i need to change to get the battery utilization to be more manageable.

thanks

Take a look at GitHub - NixOS/nixos-hardware: A collection of NixOS modules covering hardware quirks. it has some configurations for various X1 editions and laptops in general.

Even 1 hour battery life is not a lot for any decent laptop. Unless you max screen brightness, compile on all core with a 100% load or something like that. Should be several hours of normal workloads.

10 min sounds more like your battery is dead.

1 Like

What is your idle power draw? With display brightness <70%, you should have single-digit watts of power draw on a modern laptop.

Is power management enabled for SATA, PCIe and the various components (WiFi, Bluetooth, sound, etc.)?

how do i check all these things so i can answer you guys? please put some console commands i can type in to print out this info

I am inclined to say: you are running Linux, you need to know how to look up such things.

If you have upower on your system, you can get a readout of the battery by upower -d. It will also give you your current power draw.

More basically your battery has a lot of stuff that you can just cat if you like. It most likely lives under /sys/class/power_supply/BAT0/

1 Like
Device: /org/freedesktop/UPower/devices/line_power_AC
  native-path:          AC
  power supply:         yes
  updated:              Wed 15 Nov 2023 11:03:50 AM CET (12 seconds ago)
  has history:          no
  has statistics:       no
  line-power
    warning-level:       none
    online:              no
    icon-name:          'ac-adapter-symbolic'

Device: /org/freedesktop/UPower/devices/battery_BAT0
  native-path:          BAT0
  vendor:               LGC
  model:                5B10W13930
  serial:               3444
  power supply:         yes
  updated:              Wed 15 Nov 2023 11:04:00 AM CET (2 seconds ago)
  has history:          yes
  has statistics:       yes
  battery
    present:             yes
    rechargeable:        yes
    state:               discharging
    warning-level:       none
    energy:              50.2 Wh
    energy-empty:        0 Wh
    energy-full:         50.94 Wh
    energy-full-design:  51 Wh
    energy-rate:         7.223 W
    voltage:             15.982 V
    charge-cycles:       3752
    time to empty:       6.9 hours
    percentage:          98%
    capacity:            99.8824%
    technology:          lithium-polymer
    icon-name:          'battery-full-symbolic'
  History (charge):
    1700042640	98.000	discharging
  History (rate):
    1700042640	7.223	discharging

Device: /org/freedesktop/UPower/devices/line_power_ucsi_source_psy_USBC000o001
  native-path:          ucsi-source-psy-USBC000:001
  power supply:         yes
  updated:              Wed 15 Nov 2023 10:39:35 AM CET (1467 seconds ago)
  has history:          no
  has statistics:       no
  line-power
    warning-level:       none
    online:              no
    icon-name:          'ac-adapter-symbolic'

Device: /org/freedesktop/UPower/devices/line_power_ucsi_source_psy_USBC000o002
  native-path:          ucsi-source-psy-USBC000:002
  power supply:         yes
  updated:              Wed 15 Nov 2023 11:03:49 AM CET (13 seconds ago)
  has history:          no
  has statistics:       no
  line-power
    warning-level:       none
    online:              no
    icon-name:          'ac-adapter-symbolic'

Device: /org/freedesktop/UPower/devices/DisplayDevice
  power supply:         yes
  updated:              Wed 15 Nov 2023 11:04:00 AM CET (2 seconds ago)
  has history:          no
  has statistics:       no
  battery
    present:             yes
    state:               discharging
    warning-level:       none
    energy:              50.2 Wh
    energy-full:         50.94 Wh
    energy-rate:         7.223 W
    charge-cycles:       N/A
    time to empty:       6.9 hours
    percentage:          98%
    icon-name:          'battery-full-symbolic'

Daemon:
  daemon-version:  1.90.0
  on-battery:      yes
  lid-is-closed:   no
  lid-is-present:  yes
  critical-action: PowerOff

my battery is not that great for sure, but the level of discharge im seeing with nixos ive never seen before. 2 days ago i was on manjaro, battery would last 1 hr or so. now that i installed nixos, i get maybe 10 min

notice the timestamps

The energy-rate: 7.223 W for basically doing nothing is okayish, I’d say. Also you can see that it estimates time to empty: 6.9 hours at that rate. Now of course once you draw 16 Watts that changes the equation.

1 Like

Something is broken with your Laptop. The reporting says that even in the last screenshot, when you draw a quite high 15W of power, it should last 2.4hours until empty. In the (I assume) idle case with 7W of power draw, it reported 7 hours. If your battery is done for after 10 minutes, then your battery controller that produces these numbers has quite the wrong idea of your battery state.

I’m also running on a X1 Carbon (Gen 9) that is close to three years old and while the battery life is not stellar, I never bothered to optimize it and it still runs for close to two hours even under very high loads (live synthesizer sessions) and a lot longer under light load.

2 Likes

so what next steps do u recommend? is the battery controller wack or is the battery dead? 2 days ago on arch/manjaro it was at least lasting an hour. or is there some setting on nixos that can get me back to the 1hr battery mark?

Use powertop to see what is sucking up the juice.

You need to monitor power draw in real-time. I recommend powertop. If it’s not single-digit at idle, look into what’s causing that at that moment. If your 50Wh battery is drained in an hour, you must be drawing an average of 50W which is quite a lot.

It can also show you C-states for cores and package. Here you want to be in the highest one your platform supports for minimal idle draw. If C-state residency is not >80%, your CPU or peripherals are likely actively doing something and you might want to look into whether they should be doing that.

Btw, does your laptop have a dedicated GPU?

Having read through this thread, it sounds to me that you can’t trust the power reporting, neither with NixOS nor Manjaro. As others have pointed out, it just doesn’t seem reasonable that a software flaw could drain an entire healthy battery in one hour, let alone ten minutes. That leaves two options: that the physical battery is almost dead, and/or that the reported power level is incorrect and causing the laptop to shut down prematurely.

The motherboard’s setup screen from a laptop that recent should show a battery level on it, alongside the UEFI/BIOS and other boot settings. I would suggest that you:

  • Use the laptop (running NixOS) with the power cable until it’s fully charged

  • Unplug the power and use it normally until it turns itself off due to low power

  • Attempt to turn it back on, but into the ‘SETUP’ screen rather than booting into NixOS

  • Read the battery level from that screen

If the battery is reported to be something like 30% or higher, then you have a software problem relating to power reporting in NixOS, probably coming from the Linux kernel itself.

If the battery is reported to be lower than about 30%, then you have a dying battery or hardware power reporting failure. In either case, you’ll almost certainly need to replace the battery.

I hope this helps! In conclusion, I think it’s very likely the problem is a hardware issue or incompatible Linux kernel version. I don’t think NixOS or Manjaro is specifically at fault.

2 Likes

(I have workstation with a Manjaro install and it feels significantly snappier than my NixOS install on the same computer).

If you have the time it would be cool if you could make space for a Manjaro install again to see if its still kinder on the battery.

@ Chris_B

interesting, depends on the tweaks and mods u add. if its stock standard nixos, then there’s absolutely NOTHING special about nixos except its a real pain to configure at first. do you have a git-hub repo or something?

I haven’t manually added any mods AFAIK. It feels like the base kernel in NixOS is maybe optimized for a different kind of machine than I’m running (Xeon + Nvidia). I still prefer to use NixOS just for the sense of order. :slight_smile:

Might open a separate thread trying to figure out the performance difference when I have more time. Don’t want to hijack this one.

It might be because installer sets powerManagement.cpuFreqGovernor = "powersave";
You might want change “powersave” to “ondemand” or “performance”
See: NixOS Search

Also linux-zen kernel helps responsiveness under heavy load you can use zen kernel by setting boot.kernelPackages = pkgs.linuxPackages_zen;

The “base kernel” is not optimised for any specific machine. It’s mostly the default upstream kernel config.

I don’t know what Manjaro does but I doubt they do it differently.

Yup, that’s why I changed it: installer/nixos-generate-config: don't set powersave cpuFreqGovernor by Atemu · Pull Request #262574 · NixOS/nixpkgs · GitHub

Shouldn’t be an issue starting with the following release.

I highly recommend unsetting this setting.

3 Likes

I already had my cpuFreqGovernor set to “performance”. Tried activating zen packages as @Alper-Celik suggested but not sure I notice a difference.

Running the “cheese” GNOME webcam app under NixOS has it at ~0.5 frames per second. In Manjaro it’s at least 15 FPS. Not that I really use it. Zoom/Jitsi run fine under NixOS. So yeah, it’s not that urgent in my case.