A Terraform provider for deploying NixOS configurations with Packer.
- Build a NixOS configuration with a Terraform wrapped version of
nix-build
. - Build a machine image from this configuration with a Terraform wrapped version of Packer.
- Deploy this image with Terraform.
Compared to other approaches this has a few benefits:
- If the NixOS or Packer configuration changes,
terraform apply
will detect it and redeploy. - Machine images make redeploying instances of the same configuration fast.
- Adding support for a new cloud provider only requires writing a Packer builder plugin, a NixOS module, and a Packer template.
A nixpkgs
style derivation is in default.nix
. The derivation has an unlisted
dependency on having a packer
in your PATH
with access to the
packer-provisioner-fakessh
plugin and any other provider specific plugins used.
To try out the plugin with AWS, run
nix-shell shell.nix
The website directory contains terraform-website compatible markdown files.
| Provider | Packer template | packer-builder-delete-
| NixOS module |
| ........ | :.............: | :......................: | :..........: |
| vultr
| ✔️ | ✔️ | ✔️ |
The provider uses the usual go test
command for testing:
- Creating NixOS images can be slow, so consider disabling the timeout with
-timeout 0
. - Most of the tests require
TF_ACC=true
to run. - Set
TF_LOG=INFO
or higher to view command output.
The location of the share directory can be overridden with the
TERRAFORM_PACKERNIX_SHARE
environment variable. This directory is expected to
contain the following directories from the repository root.
nixos/modules
: Cloud provider specific configuration.nixos/template
: Template files for the OS data source.packer
: Packer template generator Nix functions.
The packer
directory is also expected to be added to the Nix store with name
packer
, so running
nix-store --recursive --add-fixed sha256 "$TERRAFORM_PACKERNIX_SHARE/packer"
may be necessary.
All Go source files (files with extension .go
) in this repository are licensed
under the Mozilla Public License 2.0.
All Nix source files (files with extension .nix
) in this repository, all shell
scripts (files with extension .sh
) in this repository, and all files under the
pkgs
directory are licensed under the MIT License.
All test data files (files under a testdata
directory) in this repository not
covered by the previous two paragraphs and the provider documentation (files
under the root website
directory and files with extension .md
in the top
level directory) are licensed under the CC0 License 1.0 Universal.