summaryrefslogtreecommitdiffstats
path: root/doc/packages/packer.section.md
blob: 7dbe4dfe37758b5fd64bda6a4b095ce40126da7d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# Packer {#sec-packer}

[Packer](https://www.packer.io) is a tool for creating identical machine images
for multiple platforms from a single source configuration.

## Using Packer with plugins {#sec-packer-with-plugins}

Packer's functionality is extended through
[plugins](https://developer.hashicorp.com/packer/docs/plugins). Rather than
letting Packer download plugins at runtime, you can build a Packer wrapper that
bundles the plugins you need with `packer.withPlugins`.

`packer.withPlugins` takes a function that receives the set of available plugins
and returns the list of plugins to include:

```nix
packer.withPlugins (ps: [ ps.docker ])
```

This produces a `packer` executable wrapped with the `PACKER_PLUGIN_PATH`
environment variable set, so the selected plugins are available without a
separate `packer plugins install` step.

For example, to get a development shell with Packer and the Docker plugin:

```nix
{
  pkgs ? import <nixpkgs> { },
}:

pkgs.mkShell {
  packages = [
    (pkgs.packer.withPlugins (ps: [ ps.docker ]))
  ];
}
```

Multiple plugins can be selected at once:

```nix
packer.withPlugins (ps: [
  ps.docker
  ps.qemu
])
```

## Listing available plugins {#sec-packer-list-plugins}

The packaged plugins are exposed as the `packer.plugins` attribute set. To list
every plugin available in your version of Nixpkgs, query its attribute names:

```ShellSession
$ nix eval nixpkgs#packer.plugins --apply builtins.attrNames
[ "docker" "qemu" ]
```

Without flakes:

```ShellSession
$ nix-env -f '<nixpkgs>' -qaP -A packer.plugins
packer.plugins.docker  packer-plugin-docker-1.1.2
packer.plugins.qemu    packer-plugin-qemu-1.1.4
```

The attribute name (for example `docker` or `qemu`) is what you pass to
`packer.withPlugins`.

Notes:

- `mkPackerPlugin` currently only supports `fetchFromGitHub` as the fetcher.