Quick start: your first template in five minutes

Updated 5 November 2026

Three examples, from simple to useful. Each one is complete: create, apply, check.

Example 1. Changing one parameter without touching the file

Suppose you need to set the default editor for all users. The file /etc/profile.d/editor.sh already exists - the system creates it, and editing it by hand is pointless: changes will be lost when the package is reinstalled.

Create a template file in the local storage (you need superuser privileges):

/var/calculate/templates/editor.sh

# Calculate env=install ac_install_merge==on path=/etc/profile.d comment=#
export EDITOR="nano"

Here is what it says:

  • env=install ac_install_merge==on - apply the template during package configuration. The action variable belongs to the install module, so it is written together with env=install: without it the engine replies Variable ac_install_merge not found and the template is not merged. A top-level file in the user storage must carry such a variable; without it the template is omitted;
  • path=/etc/profile.d - where to put the result; the file name comes from the template name (editor.sh);
  • comment=# - since no format is specified, the file is treated as "raw" and written in full; the comment character is needed so the utilities can add the control record on top without breaking the bash syntax.

If the template reads variables of a specific module (#-os_install_*-#), you add env=[HTML_REMOVED] to the template header; here the body reads no variables, so env= is superfluous. See Template syntax for how it works.

Now apply the templates of this package:

cl-core-setup -n baselayout

Check the result - the file contains your export and a note of which template it came from:

cat /etc/profile.d/editor.sh
#------------------------------------------------------------------------------
# Modified Calculate Utilities 3.7.6.8
# Processed template files:
# /var/db/repos/calculate/profiles/templates/2_ac_install_merge/sys-apps/baselayout/editor.sh
# /var/calculate/templates/editor.sh
# To modify this file, create a /etc/profile.d/editor.sh.clt template.
#------------------------------------------------------------------------------
export EDITOR="nano"

The control record is not decoration: the utilities use it to recognize the file as theirs, and at the next merge they replace only their own part, leaving the rest untouched.

Example 2. Surgical edit of a package configuration file

For files in familiar formats you do not need to copy the content - specify the format, and the template will describe only the parameters to change. Suppose you need to enable packet forwarding. In Calculate kernel settings are tuned with drop-in files in /etc/sysctl.d, and they belong to the sys-apps/openrc package - the templates of the distribution itself are built exactly the same way:

/var/calculate/templates/merge/.calculate_directory

# Calculate env=install ac_install_merge==on append=skip

/var/calculate/templates/merge/calculate_forward.conf

# Calculate format=procmail mergepkg(sys-apps/openrc)!= path=/etc/sysctl.d
net.ipv4.ip_forward = 1

There are two files here, and both are needed. In the user storage each top-level item is checked separately from the nested ones: if a directory has no action variable of its own, it will be skipped with all its contents - in the verbose output you will only see Skipped directories:. So the directory header must contain env=install ac_install_merge==on; this variable also applies to the files inside the directory, so you do not need to repeat it in the template itself. And append=skip is needed so the directory does not become a template itself: without it a directory /[HTML_REMOVED] (here /merge) would be created in the system and would stay in the root as junk.

mergepkg(sys-apps/openrc)!= associates the template with a package: it will run when sys-apps/openrc is configured and will not interfere when anything else is configured. Existing files are not rewritten: the utility changes only the record you specified, and your other settings stay in place.

The check is the same - apply the templates of the package:

cl-core-setup -n openrc

Then check the result:

grep ip_forward /etc/sysctl.d/calculate_forward.conf

Example 3. Overriding through .clt - without the template storage

The shortest way to change the setting of a specific file is to put the template next to it, with the .clt extension. It inherits the path and the name from its location: /etc/conf.d/consolefont.clt configures /etc/conf.d/consolefont.

/etc/conf.d/consolefont.clt

# Calculate format=openrc
consolefont="ter-v12n"

path=, name= and env=install are not needed here - the path, the name and the package are derived from the location of the template itself and from ownership of the targeted file. Also not needed is ac_install_merge==on: .clt applies during a package update even without it. Written explicitly, it is an ordinary condition - and with the variable off the template will be omitted. A regular package update applies it:

emerge -a1 openrc

grep ^consolefont /etc/conf.d/consolefont
consolefont="ter-v12n"

Whether a .clt changes the file in place depends on the state of the target. If the configuration file differs from what is recorded in the package file list (it was edited by hand or recreated), the engine preserves your version and puts the result alongside - in ._cfg0000_consolefont - while the target stays unchanged. On an untouched file, the same template changes the target in place. The equery b <file> and qcheck <package> commands help you identify which package the file belongs to and whether there are divergences.

Do not copy the whole file into a .clt: without format= it will be a "raw" template that overwrites the configuration completely and leaves no control record. Two lines with the format are enough.

Grouping templates: a directory is also a template

When there are several templates, the shared conditions go into the directory header. It is stored in the .calculate_directory file and is inherited by everything inside:

/var/calculate/templates/merge/.calculate_directory

# Calculate append=skip env=install ac_install_merge==on
  • env=install ac_install_merge==on no longer needs repeating in every template inside;
  • append=skip means the directory itself is not transferred into the system (otherwise the utilities would create /merge).

The files inside become shorter:

/var/calculate/templates/merge/ncurses.sh

# Calculate mergepkg(sys-libs/ncurses)!= path=/etc/profile.d comment=#
export LDFLAGS="${LDFLAGS} -ltinfo"

Making sure everything is right

Templates are tied to the package manager: a file created by a template for a package is registered as one of the package's files and passes the checksum check. Take /etc/profile.d/editor.sh - it is created by the editor.sh template from the calculate repository:

equery f sys-apps/baselayout | grep profile.d
/etc/profile.d
/etc/profile.d/editor.sh
equery b /etc/profile.d/editor.sh
sys-apps/baselayout-2.18-r1 (/etc/profile.d/editor.sh)
qcheck sys-apps/baselayout
Checking sys-apps/baselayout ...
 MTIME: /etc/mtab
  * 41 out of 42 files are good

The MTIME: /etc/mtab line is not a template error: this file changes at system boot, and qcheck honestly reports the time divergence. If the divergence concerns a file created by your template, the usual culprit is the binding of the template to the package: mergepkg()/pkg() is not specified, and the file ended up in "configuring the whole system" rather than among the package's files. This is covered in Life of a file after the template.

Next