Global Transaction Hooks
How to automate system maintenance tasks using path-based transaction hooks.
Zoi features a powerful global transaction hook system designed to automate system maintenance tasks. Similar to alpm-hooks, these allow you to define actions that run exactly once at the end of a package operation (install, upgrade, or remove) based on which files were modified.
Why Use Global Hooks?
In a standard package manager, if you install 50 packages that all contain fonts, you might end up running fc-cache 50 times. Zoi's global hooks solve this by:
- Deduplication: Matching modified paths across all packages in a transaction and running the associated command once.
- Decoupling: Allowing system administrators to define maintenance logic without modifying individual package definitions.
- Efficiency: Ensuring system caches (like font caches, desktop databases, or ldconfig) are updated only when necessary.
Hook Definition (.hook.yaml)
Hooks are defined using simple YAML files. They can be placed in:
- System:
/etc/zoi/hooks/ - User:
~/.zoi/hooks/ - Extensions: Distributed via Zoi Extensions.
Example: update-icon-cache.hook.yaml
name: update-icon-cache
description: Rebuilds GTK icon caches when icon themes are installed or removed.
platforms: ["linux"]
trigger:
# Trigger if any package touches files below these directories
dirs:
- "usr/share/icons"
- "usr/local/share/icons"
# Only trigger for these operations
operation: ["install", "upgrade", "remove"]
action:
when: PostTransaction
exec: |
if command -v gtk-update-icon-cache >/dev/null 2>&1; then
for dir in /usr/share/icons/* /usr/local/share/icons/*; do
[ -d "$dir" ] && [ -f "$dir/index.theme" ] && gtk-update-icon-cache -q -t -f "$dir"
done
fiSchema Reference
| Field | Type | Description |
|---|---|---|
name | string | A unique name for the hook. |
description | string | A short summary of what the hook does. |
platforms | list | (Optional) List of supported platforms (e.g. ["linux"]). |
trigger.dirs | list | A list of directory paths. If any modified file is inside one of these directories, the hook triggers. |
trigger.paths | list | A list of glob patterns. If any modified file matches, the hook triggers. |
trigger.operation | list | (Optional) Restrict to specific operations: install, upgrade, remove. |
action.when | enum | When to run: PostTransaction (currently supported). |
action.exec | string | The shell command to execute. |
trigger.dirs is preferred for directory-wide maintenance triggers such as icon themes. trigger.paths remains useful when a hook should only match specific filenames or extensions, such as usr/share/applications/*.desktop.
Builtin Hooks
Zoi ships with several essential builtin hooks for Linux systems:
update-icon-cache: Runsgtk-update-icon-cacheonce when files under icon theme directories are modified.update-font-cache: Runsfc-cache -fvwhen fonts are modified.update-desktop-database: Runsupdate-desktop-database -qwhen.desktopfiles are modified.ldconfig: Runsldconfigwhen shared libraries (.sofiles) are modified.
Overriding Hooks
Zoi follows a hierarchical loading order. If a hook in your user directory (~/.zoi/hooks/) has the same name as a builtin or system hook, your user hook will take precedence and override the others. This allows you to easily customize or disable standard system behaviors.
2026 © All Rights Reserved.
- All the content is available under CC BY-SA 4.0, expect where otherwise stated.
- Source code is available on GitLab, licensed under Apache 2.0.
Last updated on
