-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnixos.pkr.hcl
97 lines (79 loc) · 2.21 KB
/
nixos.pkr.hcl
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
packer {
required_plugins {
qemu = {
version = "~> 1"
source = "github.com/hashicorp/qemu"
}
}
}
### Variables
variable "version" {
type = string
default = "24.05"
description = "NixOS Version"
}
variable "arch" {
type = string
default = "x86_64"
description = "Host Architecture"
}
variable "iso_checksum" {
type = string
#default = "file:https://channels.nixos.org/nixos-21.05/latest-nixos-minimal-x86_64-linux.iso.sha256"
default = "none"
description = "ISO Checksum"
}
variable "linode_upload" {
type = bool
default = false
description = "Enables image upload to Linode via preconfigured linode-cli"
}
### Locals
locals {
name = "nixos-${var.version}-${var.arch}-{{ isotime \"20060102\" }}"
filename = "${local.name}.raw"
output_dir = "build"
}
### Builders
source "qemu" "nixos" {
accelerator = "kvm"
boot_command = [
"<wait40>",
"export HTTP_BASE=http://{{.HTTPIP}}:{{.HTTPPort}}<enter>",
"curl -L $HTTP_BASE/install.sh | sudo --preserve-env=HTTP_BASE bash<enter>",
]
boot_wait = "10s"
disk_cache = "unsafe"
disk_interface = "virtio-scsi"
disk_size = "3072M"
format = "raw"
iso_checksum = "${var.iso_checksum}"
iso_urls = [
"latest-nixos-minimal-${var.arch}-linux.iso",
"https://channels.nixos.org/nixos-${var.version}/latest-nixos-minimal-${var.arch}-linux.iso"
]
memory = "1536"
http_directory = "src"
output_directory = local.output_dir
communicator = "none"
ssh_timeout = "30m"
#ssh_username = "nixos"
#ssh_password = "nixos"
shutdown_timeout = "10m"
vm_name = local.filename
}
build {
sources = [
"source.qemu.nixos"
]
# Linode requires gzip compressed raw image
post-processor "compress" {
output = "${local.output_dir}/${local.filename}.gz"
compression_level = "9"
# keep_input_artifact = false
}
# OPTIONAL: Upload to Linode via linode-cli
post-processor "shell-local" {
command = "if [ '${var.linode_upload}' = 'true' ]; then linode-cli image-upload --label ${local.name} ${local.output_dir}/${local.filename}.gz; fi"
}
}