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"Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
| (positional) | string | Package name |
state | string | "present" (install) or "absent" (remove) |
Supported Package Managers
Section titled “Supported Package Managers”| 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.
For installing Nix packages on non-NixOS distributions, use the nix module instead.
On NixOS,
packageinstalls into the invoking user’s profile (vianix-env), not system-wide configuration in/etc/nixos/configuration.nix. For system-wide installs, edit the NixOS configuration directly or use thenixmodule with an explicitprofile=.
Idempotency
Section titled “Idempotency”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.
Example
Section titled “Example”step "Install web stack" { package "nginx" state="present" package "certbot" state="present" package "curl" state="present"}
step "Remove unused" { package "telnet" state="absent"}