Skip to content

fix(matic): hibernate on battery lid close - #2094

Merged
shunkakinoki merged 1 commit into
mainfrom
codex/matic-hibernate-default
Jul 17, 2026
Merged

fix(matic): hibernate on battery lid close#2094
shunkakinoki merged 1 commit into
mainfrom
codex/matic-hibernate-default

Conversation

@shunkakinoki

@shunkakinoki shunkakinoki commented Jul 17, 2026

Copy link
Copy Markdown
Owner

Summary

  • change Matic's battery lid-close action from suspend to hibernate
  • keep the existing AC-powered lid-close behavior unchanged
  • update the focused lid-policy regression spec

Why

Matic should preserve the session to disk when its lid closes on battery instead of using suspend.

Validation

  • shellspec spec/matic_lid_policy_spec.sh
  • make nix-format-check
  • evaluated nixosConfigurations.matic.config.services.logind.settings.Login.HandleLidSwitch as hibernate

The full Matic build was attempted but cannot realize an x86_64-linux Docker derivation from this aarch64-darwin host.


Summary by cubic

Switch Matic’s battery lid-close action from suspend to hibernate to save the session to disk. AC-powered behavior remains unchanged, and the lid-policy regression test now expects HandleLidSwitch = "hibernate".

Written for commit e35994f. Summary will update on new commits.

Review in cubic

@indent-zero

indent-zero Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor
PR Summary

Changes the matic host's on-battery lid-close behavior from suspend to hibernate so closing the lid unplugged fully powers down state to disk instead of holding it in RAM. AC-power behavior (Hyprland handles the lid event via HandleLidSwitchExternalPower = "ignore") is unchanged, and the ShellSpec is updated to assert the new value.

  • named-hosts/matic/default.nix: switched services.logind.settings.Login.HandleLidSwitch from "suspend" to "hibernate" and updated the comment.
  • spec/matic_lid_policy_spec.sh: updated the battery-lid assertion to grep for the new "hibernate" literal.

Issues

2 potential issues found:

  • Even once swap/resume is wired up, the LUKS root auto-unlocks via TPM2 (boot.initrd.luks.devices.*.crypttabExtraOpts = [ "tpm2-device=auto" ]), so the hibernation image on that volume will be transparently decrypted at next boot — hibernation offers little at-rest protection over suspend on this host unless swap is separately keyed or PCR-bound differently. Trigger: any attacker with physical access after hibernation is enabled. → Autofix
  • Matic has no swap and no resume= kernel parameter (hardware-configuration.nix sets swapDevices = [ ], no resume config in hosts/ either), so HandleLidSwitch = "hibernate" will fail — logind will refuse to hibernate and closing the lid on battery will leave the laptop awake with the lid shut, risking thermal/battery issues. → Autofix

CI Checks

Waiting for CI checks...


⚡ Autofix All Issues

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@cursor

cursor Bot commented Jul 17, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@mesa-dot-dev

mesa-dot-dev Bot commented Jul 17, 2026

Copy link
Copy Markdown

You do not have enough credits to review this pull request. Please purchase more credits to continue.

@shunkakinoki
shunkakinoki merged commit cb3069a into main Jul 17, 2026
28 of 30 checks passed
@shunkakinoki
shunkakinoki deleted the codex/matic-hibernate-default branch July 17, 2026 22:15
@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 81c26311-deb1-431f-8a47-fad5d6a1b66c

📥 Commits

Reviewing files that changed from the base of the PR and between a96d270 and e35994f.

📒 Files selected for processing (2)
  • named-hosts/matic/default.nix
  • spec/matic_lid_policy_spec.sh

Disabled knowledge base sources:

  • Linear integration is disabled

You can enable these sources in your CodeRabbit configuration.


📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Laptops now hibernate instead of suspend when the lid is closed while running on battery.
  • Bug Fixes

    • Updated validation to confirm the revised battery lid-close behavior.
    • Lid-close handling when connected to external power remains unchanged.

Walkthrough

Matic’s systemd-logind configuration now hibernates when the lid closes on battery. The corresponding specification expects "hibernate" instead of "suspend"; external-power handling remains unchanged.

Changes

Matic lid policy

Layer / File(s) Summary
Hibernate battery lid-close behavior
named-hosts/matic/default.nix, spec/matic_lid_policy_spec.sh
The battery lid-close action changed from suspension to hibernation, and the specification was updated to assert the new setting while retaining the external-power behavior test.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Possibly related PRs

Poem

A bunny shuts the laptop tight,
On battery, dreams begin tonight.
No sudden snooze, no chilly fright—
Hibernate softly, tucked from light.
The tests now hop in step just right.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/matic-hibernate-default

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

# Suspend on battery lid close; on AC, Hyprland locks on the lid switch event.
services.logind.settings.Login.HandleLidSwitch = "suspend";
# Hibernate on battery lid close; on AC, Hyprland locks on the lid switch event.
services.logind.settings.Login.HandleLidSwitch = "hibernate";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hibernate has no backing swap on this host. named-hosts/matic/hardware-configuration.nix:44 declares swapDevices = [ ], and there is no boot.resumeDevice, no swap file, and no resume=/resume_offset= entry in boot.kernelParams (see named-hosts/matic/default.nix:58-63) — grepping swap|resume|hibernat across named-hosts/matic/ and hosts/ returns only the fprintd-resume unit and this new line.

When systemd-logind receives the lid-close event it will call hibernate.target, which systemd refuses with Not enough swap space for hibernation / Sleep verb "hibernate" not supported. Net effect on battery: closing the lid does nothing — the machine stays awake in your bag. That's a regression from the previous suspend behavior and a real thermal/battery risk.

Fix direction: either revert to suspend (or suspend-then-hibernate), or land the hibernation prerequisites first — e.g. add a swap partition/file sized for RAM plus boot.resumeDevice = "/dev/disk/by-uuid/..." (and resume_offset if using a swap file), ideally on an encrypted volume separate from the TPM2-auto-unlocked root.

# Suspend on battery lid close; on AC, Hyprland locks on the lid switch event.
services.logind.settings.Login.HandleLidSwitch = "suspend";
# Hibernate on battery lid close; on AC, Hyprland locks on the lid switch event.
services.logind.settings.Login.HandleLidSwitch = "hibernate";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heads-up on the security model: the root LUKS device auto-unlocks via TPM2 (named-hosts/matic/default.nix:44-47), which means whatever swap you end up putting the hibernation image on will also be transparently decrypted on next boot. If part of the motivation for moving to hibernate was "safer to leave the laptop shut for long periods," that's not really gained on this host versus suspend + LUKS — you'd want the hibernation swap on a separately-keyed encrypted volume (or bound to different PCRs / require a passphrase on resume) to get a real benefit. Latent today; becomes relevant the moment hibernation actually starts working.

@mesa-dot-dev

mesa-dot-dev Bot commented Jul 17, 2026

Copy link
Copy Markdown

Mesa Description

TL;DR

Changed Matic's lid-close action from suspend to hibernate when on battery power to preserve sessions to disk, leaving AC-powered behavior unchanged.

What changed?

  • named-hosts/matic/default.nix: Configured the system lid switch behavior to hibernate instead of suspend when running on battery.
  • spec/matic_lid_policy_spec.sh: Updated test specifications to assert that the battery lid-close action is set to hibernate instead of suspend.

Description generated by Mesa. Update settings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant