Skip to content

Install system-sleep hooks executable so systemd runs them - #7699

Closed
ya-luotao wants to merge 3 commits into
omacom:quattrofrom
ya-luotao:fix-sleep-hook-executable-bit
Closed

ya-luotao wants to merge 3 commits into
omacom:quattrofrom
ya-luotao:fix-sleep-hook-executable-bit

Conversation

@ya-luotao

@ya-luotao ya-luotao commented Aug 21, 2026 •

Copy link
Copy Markdown

Fixes #7618.

omarchy hibernation setup copies default/systemd/system-sleep/keyboard-backlight into /usr/lib/systemd/system-sleep/ with cp -p. The source ships with mode 644, so the installed hook is 644 too, and systemd-sleep(8) silently skips non-executable files in that directory. The hook that is supposed to zero the keyboard backlight before hibernate therefore never runs on any install that has run hibernation setup.

omarchy-toggle-hybrid-gpu installs force-igpu the same way (cp -p, same 644 source), so it has the same defect: the hook meant to force integrated mode after sleep never runs either. The stale #4793 noticed this for force-igpu back in February.

Fix

  • bin/omarchy-hibernation-setup, bin/omarchy-toggle-hybrid-gpu: replace sudo cp -p with sudo install -m755, so the installed hook is executable regardless of the mode the source ships with (the packaged copy under /usr/share/omarchy/default/... is 644 today: omarchy-settings installs it with install -Dm644, so the repo mode bit does not carry into the package).
  • Mark both hooks executable in the repo as well, so git-checkout installs match.
  • migrations/1787336732.sh: repair already-affected installs by making the installed keyboard-backlight and force-igpu executable in place. Neither install path reaches the new install -m755 on an affected machine — hibernation setup exits early once the resume hook is configured, and the GPU toggle only installs force-igpu when switching into Integrated mode, which is the mode those users are already in — so the migration is what fixes existing machines. It only touches a hook that is present and non-executable, so a second user on the same machine no-ops.
    • force-igpu forces Integrated mode after every sleep, so the migration only activates it when supergfxctl -g (queried the way the toggle does) reports Integrated. The toggle removes the hook on its way to Hybrid, but a mode change made directly through supergfxctl leaves the inert copy behind, and that copy must stay inert. No answer from supergfxd leaves the hook as it is. keyboard-backlight only fires on pre hibernate and is repaired unconditionally.
  • test/shell.d/sleep-hook-executable-migration-test.sh covers the migration.

Verification

  • bash -n on the two scripts and both hooks.
  • Simulated install -m755 <hook> <dir>/ locally: lands under the hook's basename, mode 755, content byte-identical to the source, and overwrites an existing 644 copy with 755.
  • bash test/shell.d/sleep-hook-executable-migration-test.sh passes: 644 hooks become 755 through sudo chmod, force-igpu stays inert in Hybrid mode or when supergfxd does not answer (with the toggle's three-attempt query), a missing hook is left absent, and an already-repaired machine triggers no sudo call.
  • ./test/cli and the full ./test/shell — not runnable on my macOS dev box: ./test/cli fails at "main help includes hardware group" on quattro before and after this change (hardware group discovery needs Linux), and ./test/shell hangs on tests that need the running desktop, so the suites are not informative here.

🤖 Generated with Claude Code

https://claude.ai/code/session_01KdrqXrL4pbdS9CjdHxfCYF

omarchy-hibernation-setup and omarchy-toggle-hybrid-gpu copied the
keyboard-backlight and force-igpu hooks into /usr/lib/systemd/system-sleep/
with cp -p, preserving the source's 644 mode. systemd-sleep only executes
executable files in that directory, so both hooks were silently skipped.

Use install -m755 so the installed hooks are executable regardless of the
source mode, and mark the hooks executable in the repo as well.

Fixes omacom#7618

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KdrqXrL4pbdS9CjdHxfCYF
Copilot AI balanced review requested due to automatic review settings August 21, 2026 18:28

Copilot AI left a comment

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.

Copilot wasn't able to review any files in this pull request.


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: db2e2b26f7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".


# Ensure keyboard backlight doesn't prevent sleep
sudo cp -p "$OMARCHY_PATH/default/systemd/system-sleep/keyboard-backlight" /usr/lib/systemd/system-sleep/
sudo install -m755 "$OMARCHY_PATH/default/systemd/system-sleep/keyboard-backlight" /usr/lib/systemd/system-sleep/

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Install the repair before the already-configured return

On the existing installations this change is intended to repair, /etc/mkinitcpio.conf.d/omarchy_resume.conf already contains HOOKS+=(resume), so the check at lines 34–47 exits before this new install -m755 command runs. Consequently, re-running omarchy hibernation setup leaves the previously installed keyboard-backlight hook at mode 0644 and systemd continues skipping it; perform this repair before the early return or within that branch.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good catch — the PR description was wrong about re-running setup being enough. Rather than adding a second install in the already-configured branch, 8e5ed6f adds migrations/1787336732.sh, which makes an installed non-executable keyboard-backlight (and force-igpu) executable in place. It runs on the next omarchy update regardless of the early return, and no-ops once the hook is already 755.

# Force igpu mode after system sleep (or dgpu could get activated)
sudo mkdir -p /usr/lib/systemd/system-sleep
sudo cp -p "$OMARCHY_PATH/default/systemd/system-sleep/force-igpu" /usr/lib/systemd/system-sleep/
sudo install -m755 "$OMARCHY_PATH/default/systemd/system-sleep/force-igpu" /usr/lib/systemd/system-sleep/

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Migrate already-installed integrated-GPU hooks

Existing users who selected Integrated mode already have a 0644 /usr/lib/systemd/system-sleep/force-igpu from the old cp -p, but this new installation command only runs in the "Hybrid" branch. Their current mode is reported as Integrated, so invoking the toggle instead enters the opposite branch and removes the hook while switching to Hybrid; merely updating or running the command once therefore does not repair their inactive hook. Add a one-time repair for an existing force-igpu installation rather than requiring two mode changes and reboots.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Agreed — users already in Integrated mode would have needed two mode changes and two reboots. 8e5ed6f adds migrations/1787336732.sh, which fixes an installed non-executable force-igpu in place with chmod 755 on the next omarchy update, with no mode toggle involved. A missing hook (Hybrid-mode machines) is left alone.

Installing the hooks with install -m755 only helps machines that run
hibernation setup or the GPU toggle again, and neither path reaches the
install on an affected machine: hibernation setup exits early once the
resume hook is configured, and the GPU toggle only installs force-igpu
when switching into Integrated mode, which is the mode those users are
already in. Make the installed copies executable in place instead.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KdrqXrL4pbdS9CjdHxfCYF

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

https://github.com/basecamp/omarchy/blob/8e5ed6ffc10f631d5f692e29eba8b6c543e11ad0/default/systemd/system-sleep/force-igpu#L1
P1 Badge Keep the packaged force-igpu hook inactive in Hybrid mode

On a machine configured for Hybrid mode, installing this release can activate force-igpu even though omarchy-toggle-hybrid-gpu deliberately removes that hook when switching to Hybrid (bin/omarchy-toggle-hybrid-gpu:42-47). The packaging map shows that omarchy-settings installs this source at /usr/lib/systemd/system-sleep/force-igpu (docs/file-layout.md:110,127-128), so making the source executable—or subsequently applying the migration's unconditional chmod 755—makes systemd run it after every sleep; its post branch then invokes supergfxctl -m Integrated, unexpectedly disabling the configured hybrid/dedicated GPU. Keep the packaged conditional hook inactive and only make an existing copy executable when /etc/supergfxd.conf confirms Integrated mode.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

force-igpu switches the GPU back to Integrated after every sleep, so it
must only be live on a machine that is still in Integrated mode. The
toggle removes the hook on its way to Hybrid, but a mode change made
directly through supergfxctl leaves the inert copy behind, and waking it
up would flip the GPU under the user. Ask supergfxd the way the toggle
does before making that hook executable, and leave it alone when there
is no answer.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KdrqXrL4pbdS9CjdHxfCYF
@ya-luotao

Copy link
Copy Markdown
Author

Re the second Codex review ("Keep the packaged force-igpu hook inactive in Hybrid mode"):

The packaging premise is not right. omarchy-settings does not install force-igpu (or keyboard-backlight) into /usr/lib/systemd/system-sleep/; checked the built packages on pkgs.omarchy.org/edge/x86_64 (omarchy-settings-4.0.0-1 and omarchy-settings-dev-4.0.0.r1791.ged7bae4-1): that directory holds unmount-fuse only, and the other two ship solely as 644 sources under /usr/share/omarchy/default/systemd/system-sleep/. Only omarchy-toggle-hybrid-gpu installs force-igpu, and only on the way into Integrated mode. docs/file-layout.md:127-128 said otherwise and was the source of the confusion; #7720 corrects it.

The residual case is real, though: someone who left Integrated mode straight through supergfxctl -m Hybrid rather than the toggle still has a stale 644 force-igpu, and an unconditional chmod would activate it. 5003d6b makes the migration query supergfxctl -g the way the toggle does and only activates force-igpu when the answer is Integrated; no answer leaves the hook as it is. keyboard-backlight only fires on pre hibernate, so it stays unconditional.

@ya-luotao

Copy link
Copy Markdown
Author

Closing: superseded by #10425 (feb0557, "Harden ownership of installed sleep hooks"). Both omarchy-hibernation-setup and omarchy-toggle-hybrid-gpu now publish the hooks with install -m 0755, and migrations/1788662350.sh repairs already-installed legacy 0644 copies in place, which covers everything this PR set out to fix.

@ya-luotao ya-luotao closed this Sep 10, 2026
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.

hibernation setup installs keyboard-backlight system-sleep hook non-executable, so it never runs

2 participants