nix-builder-autoscaler/agent/nix_builder_autoscaler/bootstrap/userdata.py

28 lines
833 B
Python
Raw Permalink Normal View History

"""EC2 user-data template rendering for builder instance bootstrap."""
2026-02-27 11:59:16 +01:00
from __future__ import annotations
import textwrap
2026-02-27 11:59:16 +01:00
def render_userdata(slot_id: str, ssm_param: str = "/nix-builder/ts-authkey") -> str:
"""Render user-data that seeds AMI bootstrap inputs only.
The AMI's buildbot-ami-bootstrap service consumes this env file and handles
SSM fetch + tailscale-autoconnect config generation.
2026-02-27 11:59:16 +01:00
"""
return textwrap.dedent(f"""\
#!/usr/bin/env bash
set -euo pipefail
SLOT_ID="{slot_id}"
SSM_PARAM="{ssm_param}"
# Seed AMI bootstrap inputs only; buildbot-ami-bootstrap reads this file.
cat > /etc/nix-builder-bootstrap-env <<EOF
SLOT_ID="$SLOT_ID"
TS_SSM_PARAM="$SSM_PARAM"
EOF
chmod 600 /etc/nix-builder-bootstrap-env
""")