Who and when merges templates
Updated 11 November 2026
A template is not applied "whenever you like" but at the moment of a specific action. The action variables ac_* determine which templates to merge this time: the utility sets them, and the templates check them in the header. Therefore, the top-level directory of the template tree is conventionally named after the action: N_ac_[HTML_REMOVED].
The actual set of directories in the calculate tree:
1_ac_install_disk 6_ac_desktop_profile 2_ac_install_merge 6_ac_install_config 3_ac_install_live 6_ac_install_configure 5_ac_ad_client 6_ac_install_flash 5_ac_client_configure 6_ac_install_patch 6_ac_backup_create 6_ac_install_pxe 6_ac_backup_restore 6_ac_install_unmerge 6_ac_backup_service 6_ac_update_sync 6_ac_builder_container 7_ac_server_ldif 6_ac_builder_iso 7_ac_server_setup 6_ac_builder_prepare 9_ac_install_merge 6_ac_builder_setup deprecated 6_ac_builder_squash
The set depends on the repository revision: deprecated and some of the 6_ac_builder_* may be missing from it. You get the full and current list from ls /var/db/repos/calculate/profiles/templates/.
The numeric prefix in the event directory name sets the order relative to the other directories; the file order inside a single directory is described on the page about template directories. The action itself is chosen by the header in .calculate_directory, not by the directory name.
Main events
Configuring a package
The 2_ac_install_merge, 9_ac_install_merge and 6_ac_install_unmerge events - these occur during the installation, update and removal of a package: emerge. This is implemented with Portage hooks - fragments of profile.bashrc that live in /var/lib/calculate/profile.bashrc.d/ and are themselves generated by templates. This is where templates of the form [HTML_REMOVED]/[HTML_REMOVED]/… work, and the condition mergepkg([HTML_REMOVED]/[HTML_REMOVED])!= проверяет, что настраивается этот пакет.
An important detail that explains half of the "why was it not applied" questions: the package's templates are merged only if the package is in the caches /var/lib/calculate/calculate-core/cache/merge-setup.list (configuration) or merge-patch.list (patches). These lists are updated at the installation/removal phases by /usr/libexec/calculate/cl-pkg-cache. If the package is not in the cache, there is no application either, even if the template is written correctly.
Modifying package sources
The 6_ac_install_patch event runs before compilation, and the templates of this event apply patches (usually format=diff). If a merge fails, the build may be interrupted.
Updating the system and syncing the Portage tree
The 6_ac_update_sync event is called by the update action. cl-update runs it, and during the synchronization of the Portage tree it is the Calculate sync module in portage: for repositories with sync-type = calculate it runs cl-core --method update --repositories <name> --sync-only on --skip-eix-update -T none. These are "migrations": directories with date names (2026/20261103), which are applied only once, and a typical template checks the overlay revision through ini(overlay-calculate.remerge)<#-cl_pass_file-#>. The condition ac_update_sync==on is satisfied during the synchronization and profile change actions, when the package being configured is not specified. The variable belongs to the update module and is read-only: you cannot set it manually, the action itself sets it, which is why you write it in the header together with the module - env=update ac_update_sync==on, the shipped 6_ac_update_sync directory is arranged exactly this way, with # Calculate append=skip env=update ac_update_sync==on.
Installing and booting the system
The 1_ac_install_disk, 3_ac_install_live, 6_ac_install_flash and 6_ac_install_pxe events - configuring the system being installed (cl-install), the live image, booting from USB-Flash and booting over the network.
User profile
The 6_ac_desktop_profile event runs when the user logs in to a session (via cl-desktop), and also when a package is installed on a working system - then the already created profile is configured further. The ur_* variables and the ~ path take part in this event, while the clt layer is not used.
Specific configurator
The 6_ac_install_configure, 5_ac_client_configure and 7_ac_server_setup events - actions by configuration type: network, sound, bootloader, locale, session, themes, video (cl-setup-network, cl-setup-locale, … - see cl-core --list-methods). The condition in the template usually checks cl_setup==[HTML_REMOVED] together with ac_install_configure==on.
Domain
5_ac_ad_client covers joining the machine to the domain and leaving it.
Building an image
6_ac_builder_* covers the builder actions (iso, squash, container, prepare, setup).
The same run can enable several events
This is a common source of surprises. The ac_install_merge and ac_install_live variables are enabled at the same time if you run package configuration directly on an already installed system (cl-core-setup …, cl-setup-system): ac_install_live is not "LiveCD only". Inside the Portage chroot (during a package build) the live mode is turned off, while merge remains. Hence the practical rule: if the template is specifically about the live image, you must place it in 3_ac_install_live and rely on the environment differences, rather than counting on the "installer" event.
ac_install_disk is set when the action is a system installation (and not flash/pxe).
Manual run
The most common way to check your template:
cl-core-setup -n [HTML_REMOVED]
- -v - verbose output with a list of the applied templates and errors; for core_setup it is on by default, so in examples you can leave the flag out;
- -c [HTML_REMOVED] - the package category; you do not have to specify it. Name collisions across categories are rare, and
cl-core-setup -n baselayoutis enough. -c comes in handy to tell such cases apart; and know the other side: with a wrong category not a single template is applied, and without any error message - the check will simply show an empty result; - --pkg-path
[HTML_REMOVED]- direct the results to a directory without changing the configuration files themselves (see preview); the directory must exist, otherwise you getError in parameter --pkg-path. Careful: the preview still changes the package manager database - the merged paths are written into the package file list (CONTENTS) as real ones: one such run adds several lines toCONTENTSthat were not in theequery f <package>output. Save that output before the trial, and after it compare with the currentCONTENTSand remove the lines that appeared; - -T - choose the template layers from a fixed set:
calculate,distros,local,remote,clt;nonedisables the selection entirely.
The list of available actions: cl-core --list-methods.
Selective disabling of templates
Templates can be merged selectively - that is, merging can be disabled for individual packages rather than for all of them at once. Four variables in the [main] section of the /etc/calculate/calculate.env file serve this purpose:
- cl_setup_skip_merge - templates for system settings (for example, 2_ac_install_merge) and for migration directories;
- cl_setup_skip_patch - templates that apply patches to package sources (6_ac_install_patch);
- cl_setup_skip_profile - user profile templates (6_ac_desktop_profile);
- cl_setup_skip_sync - templates for migration directories during portage synchronization (
cl-update -s).
The variable is chosen by the directory that contains the template, not by its format. During portage synchronization (cl-update -s), a migration template from 6_ac_update_sync is disabled by an entry in either of the two variables - cl_setup_skip_merge or cl_setup_skip_sync; the latter appeared in Calculate Utilities 3.8.2.32 and serves exactly that purpose. When configuring a specific package, the same template is disabled by cl_setup_skip_merge alone. Disabling does not depend on the template format: a migration written as a patch (format=diff) is disabled the same way.
The value is a comma-separated list of entries of the form package:location. Glob characters are allowed in the package name, so sys-kernel/*-sources is accepted. The location is the name of a template layer: calculate, container, local, remote, clt or * (any layer). Both parts of the entry are required, separated by a colon; spaces after commas are allowed. The current layer names are shown by cl-variable --value main.cl_template_location and cl-variable --value main.cl_template_clt_path.
cat /etc/calculate/calculate.env
[main] # do not apply patches to kernel source packages cl_setup_skip_patch = sys-kernel/*-sources:calculate # disable the system settings templates of the bootloader, dracut and portage, # including the portage migration from 6_ac_update_sync cl_setup_skip_merge = sys-boot/grub:calculate, sys-kernel/dracut:calculate, sys-apps/portage:calculate # disable the calculate-utils migration templates only during cl-update -s cl_setup_skip_sync = sys-apps/calculate-utils:calculate
An entry applies only when both of its parts match - the package and the layer; if either of them does not match, the templates are applied as usual. The package name is taken from the merge() condition in the template header, or, if it is empty, from the path to the template directory; the layer is the one from which the processing is performed. The second part of the entry is checked against the actual location of the template: for a [HTML_REMOVED]/[HTML_REMOVED]/ directory inside /var/calculate/templates, the layer is local, not calculate.
See also
- The template was not applied and said nothing: diagnostics
- Template directories and storage layers
- Template variables - what ac_* is and where to view the values.