-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnixos.pkr.hcl
More file actions
105 lines (93 loc) · 3.03 KB
/
nixos.pkr.hcl
File metadata and controls
105 lines (93 loc) · 3.03 KB
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
98
99
100
101
102
103
104
105
locals {
# renovate: datasource=custom.html depName=nixos versioning=regex:^(?<major>[0-9]+)\.(?<minor>[0-9]+)\.(?<patch>[0-9]+)\.[0-9a-f]+$ extractVersion=(^|/)nixos-minimal-(?<version>[^/]+)-x86_64-linux\.iso$ registryUrl=https://channels.nixos.org/nixos-25.11
nixos_build = "25.11.7702.48652e9d5aea"
}
local "nixos_channel" {
expression = regex("^[0-9]+\\.[0-9]+", local.nixos_build)
}
local "nixos_iso_url" {
expression = "https://releases.nixos.org/nixos/${local.nixos_channel}/nixos-${local.nixos_build}/nixos-minimal-${local.nixos_build}-x86_64-linux.iso"
}
# https://github.com/hashicorp/go-getter/issues/396
data "http" "nixos_iso_checksum" {
url = "${local.nixos_iso_url}.sha256"
}
source "qemu" "nixos" {
iso_url = "${local.nixos_iso_url}"
iso_checksum = "sha256:${split(" ", data.http.nixos_iso_checksum.body)[0]}"
vga = "virtio"
cpus = 2
memory = 8192
headless = var.headless
shutdown_command = "sudo shutdown -P now"
qmp_enable = var.headless
disk_discard = "unmap"
ssh_timeout = "1h"
ssh_username = "root"
ssh_password = "vagrant"
boot_wait = "1m"
boot_command = [
"sudo passwd root<enter><wait>",
"vagrant<enter><wait>",
"vagrant<enter><wait>",
]
efi_firmware_code = local.efi_firmware_code
efi_firmware_vars = local.efi_firmware_vars
qemuargs = [["-cpu", "host"], ["-serial", "stdio"]]
machine_type = var.machine_type
}
build {
sources = [
"source.qemu.nixos"
]
provisioner "shell" {
inline = [
"parted /dev/vda -- mklabel gpt",
"parted /dev/vda -- mkpart primary 512MB -8GB",
"parted /dev/vda -- mkpart primary linux-swap -8GB 100%",
"parted /dev/vda -- mkpart ESP fat32 1MB 512MB",
"parted /dev/vda -- set 3 esp on",
"mkfs.btrfs -L nixos /dev/vda1",
"mkswap -L swap /dev/vda2",
"swapon /dev/vda2",
"mkfs.fat -F 32 -n boot /dev/vda3",
"mount -o discard /dev/disk/by-label/nixos /mnt",
"mkdir -p /mnt/boot/efi",
"mount /dev/disk/by-label/boot /mnt/boot/efi",
"nixos-generate-config --root /mnt",
]
}
provisioner "file" {
sources = [
"${path.root}/nix/bootloader.nix",
"${path.root}/nix/vagrant-hostname.nix",
"${path.root}/nix/vagrant-network.nix",
"${path.root}/nix/vagrant.nix",
]
destination = "/mnt/etc/nixos/"
}
provisioner "file" {
content = templatefile("${path.root}/nix/configuration.nix", { path = path, state_version = local.nixos_channel })
destination = "/mnt/etc/nixos/configuration.nix"
}
provisioner "shell" {
inline = [
"nixos-install",
"echo 'nix-env --delete-generations old; nix-collect-garbage -d; fstrim -av --quiet-unsupported' | nixos-enter"
]
}
post-processors {
post-processor "vagrant" {
vagrantfile_template = "Vagrantfile"
include = flatten([
local.ovmf_include,
"output-${source.name}/efivars.fd",
])
compression_level = 9
}
post-processor "vagrant-registry" {
box_tag = "gnome-shell-box/${source.name}"
version = local.version
}
}
}