iac/tofu/cloud-init/nixos.yaml.tftpl
Sergei Poljanski 796331815d
All checks were successful
nixos / nixos (push) Successful in 34s
tofu: rename from terraform, state in its own bucket, Loki buckets
The infrastructure is applied with OpenTofu; name it so. terraform/
becomes tofu/, the files end in .tofu (OpenTofu 1.8+ prefers them), the
local variables file is secrets.auto.tfvars, and both servers carry
managed_by=opentofu (an in-place label change).

The state moved to new buckets asxpio-tofu-main/-repl, key
tofu/state/tofu.tfstate, with `tofu init -migrate-state`; a plan against
it shows no changes. The old asxpio-terraform-* buckets stay, renamed
in the config with moved blocks, until the new state has been used for
a while.

asxpio-loki-main, created by hand, is adopted with an import block, and
a new asxpio-loki-repl in fsn1 receives it in the daily replica, which
now also copies the new state bucket instead of the old one.

What keeps the Terraform name is OpenTofu's own: the `terraform {}`
block and .terraform.lock.hcl.

Assisted-by: Claude:opus-5-5
2026-11-17 09:42:53 +04:00

44 lines
1.8 KiB
Text

#cloud-config
# First boot of the Debian image: convert it to NixOS in place with
# nixos-infect, then reboot. The result is a bare NixOS that keeps the
# image's partitions and the SSH host keys, with root's authorized_keys
# taken from the server's ssh_keys. Everything else comes from the flake:
#
# nixos-rebuild switch --flake ../nixos#${hostname} --target-host root@<ip>
#
# Log: /var/log/nixos-infect.log (after the reboot under /old-root).
hostname: ${hostname}
fqdn: ${hostname}.${domain}
manage_etc_hosts: true
ssh_deletekeys: false
write_files:
# Corrections to what nixos-infect generates, for this bootstrap
# generation only: the takeover of the old root (NIXOS_LUSTRATE) exists
# only in the scripted initrd; without an interface the IPv4 default
# route is never added (the gateway is not on the /32's link); and the
# private network gets an address but no route.
- path: /etc/nixos/bootstrap.nix
content: |
{ lib, ... }: {
boot.initrd.systemd.enable = false;
networking.defaultGateway = lib.mkForce {
address = "172.31.1.1";
interface = "eth0";
};
networking.interfaces.enp7s0.ipv4.routes = [
{ address = "${private_gateway}"; prefixLength = 32; }
{ address = "${private_net}"; prefixLength = ${private_prefix}; via = "${private_gateway}"; }
];
}
runcmd:
# Debian keeps /tmp in RAM; nixos-infect puts its swap file there
- >-
umount -l /tmp;
curl -fsSL -o /root/nixos-infect
https://raw.githubusercontent.com/elitak/nixos-infect/${infect_rev}/nixos-infect
&& echo "${infect_sha256} /root/nixos-infect" | sha256sum -c
&& PROVIDER=hetznercloud NIX_CHANNEL=${nix_channel} NIXOS_IMPORT=./bootstrap.nix
bash -x /root/nixos-infect > /var/log/nixos-infect.log 2>&1