From 38d8eea71fd62157ae324f6a3753b490340c4c77 Mon Sep 17 00:00:00 2001 From: Michael Hoang Date: Thu, 28 Dec 2023 09:02:05 +1100 Subject: [PATCH] terraform/install: support `build_on_remote` --- terraform/install/main.tf | 2 ++ terraform/install/run-nixos-anywhere.sh | 9 ++++++++- terraform/install/variables.tf | 14 ++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/terraform/install/main.tf b/terraform/install/main.tf index ac55c93..02e6da0 100644 --- a/terraform/install/main.tf +++ b/terraform/install/main.tf @@ -18,6 +18,8 @@ resource "null_resource" "nixos-remote" { target_host = var.target_host extra_files_script = var.extra_files_script no_reboot = var.no_reboot + build_on_remote = var.build_on_remote + flake = var.flake }, var.extra_environment) command = "${path.module}/run-nixos-anywhere.sh ${join(" ", local.disk_encryption_key_scripts)}" quiet = var.debug_logging diff --git a/terraform/install/run-nixos-anywhere.sh b/terraform/install/run-nixos-anywhere.sh index 06a84a9..86f72fa 100755 --- a/terraform/install/run-nixos-anywhere.sh +++ b/terraform/install/run-nixos-anywhere.sh @@ -17,7 +17,14 @@ fi if [[ ${no_reboot-} == "true" ]]; then args+=("--no-reboot") fi -args+=("--store-paths" "${nixos_partitioner}" "${nixos_system}") +if [[ ${build_on_remote-} == "true" ]]; then + args+=("--build-on-remote") +fi +if [[ -n ${flake-} ]]; then + args+=("--flake" "${flake}") +else + args+=("--store-paths" "${nixos_partitioner}" "${nixos_system}") +fi tmpdir=$(mktemp -d) cleanup() { diff --git a/terraform/install/variables.tf b/terraform/install/variables.tf index d3e2291..60bd9cd 100644 --- a/terraform/install/variables.tf +++ b/terraform/install/variables.tf @@ -8,12 +8,14 @@ variable "kexec_tarball_url" { variable "nixos_partitioner" { type = string description = "nixos partitioner and mount script" + default = "" } # To make this re-usable we maybe should accept a store path here? variable "nixos_system" { type = string description = "The nixos system to deploy" + default = "" } variable "target_host" { @@ -83,3 +85,15 @@ variable "no_reboot" { description = "Do not reboot the machine after installation" default = false } + +variable "build_on_remote" { + type = bool + description = "Build the closure on the remote machine instead of building it locally and copying it over" + default = false +} + +variable "flake" { + type = string + description = "The flake to install the system from" + default = "" +}