Skip to content

package

The package module manages system packages. It automatically detects the host’s package manager.

package "nginx" state="present"
package "vim" state="present"
package "telnet" state="absent"
Parameter Type Description
(positional) string Package name
state string "present" (install, the default) or "absent" (remove)
Manager Distributions
apt Debian, Ubuntu
dnf Fedora, RHEL 8+
yum CentOS, RHEL 7
pacman Arch Linux
apk Alpine Linux
zypper openSUSE
nix NixOS

The package manager is detected automatically based on the target host’s OS.

Before installing, package refreshes the package index (apt-get update, dnf makecache, pacman -Sy, …). If the refresh fails, for example because one repository is unreachable or has a bad key, the install still runs, since the package may come from a repository that works:

  • The install fails: the error names the failed refresh first, with its command, exit code and output, then the install’s error.
  • The install succeeds: the task’s output starts with a warning: line describing the failed refresh.

Removing a package does not refresh the index.

For installing Nix packages on non-NixOS distributions, use the nix module instead.

On NixOS, package installs into the invoking user’s profile (via nix-env), not system-wide configuration in /etc/nixos/configuration.nix. For system-wide installs, edit the NixOS configuration directly or use the nix module with an explicit profile=.

The module checks if the package is already installed (or already absent) before acting. No action is taken if the current state matches the desired state.

Every module’s rules side by side: Idempotency & Drift.

step "Install web stack" {
package "nginx" state="present"
package "certbot" state="present"
package "curl" state="present"
}
step "Remove unused" {
package "telnet" state="absent"
}