about summary refs log tree commit diff
path: root/ops
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2023-03-01T13·56+0100
committerclbot <clbot@tvl.fyi>2023-03-03T14·53+0000
commitc3750079f75662a6d01a79c0a1c6335456b2d40a (patch)
tree32d554993e64dca4d1ac906dc12c6f5d1b28336f /ops
parent344c1193700370f4762ae709c076aae11ca50b18 (diff)
feat(ops/terraform): allow specifying an entrypoint for the attrset r/5871
This adds an additional parameter `entrypoint`, pointing to a .nix file
(or a directory containing a `default.nix` file) that's providing the
attribute path asked for.

If not set / kept at the default (empty string), it falls back to the
root dir of the repository as before.

Change-Id: I2e63114f21660c842153ac15424b3491d66624d2
Reviewed-on: https://cl.tvl.fyi/c/depot/+/8190
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
Autosubmit: flokli <flokli@flokli.de>
Diffstat (limited to 'ops')
-rw-r--r--ops/terraform/deploy-nixos/main.tf13
-rwxr-xr-xops/terraform/deploy-nixos/nixos-eval.sh7
2 files changed, 15 insertions, 5 deletions
diff --git a/ops/terraform/deploy-nixos/main.tf b/ops/terraform/deploy-nixos/main.tf
index 3ff7bfc3f3..d39610327a 100644
--- a/ops/terraform/deploy-nixos/main.tf
+++ b/ops/terraform/deploy-nixos/main.tf
@@ -24,6 +24,16 @@ variable "target_host" {
   type        = string
 }
 
+variable "entrypoint" {
+  description = <<EOT
+    Path to a .nix file (or directory containing `default.nix` file)
+    that provides the attrset specified in `closure`.
+    If unset, asks git for the root of the repository.
+  EOT
+  type        = string
+  default     = ""
+}
+
 variable "target_user" {
   description = "username on the target machine"
   type        = string
@@ -40,7 +50,8 @@ data "external" "nixos_system" {
   program = ["${path.module}/nixos-eval.sh"]
 
   query = {
-    attrpath = var.attrpath
+    attrpath   = var.attrpath
+    entrypoint = var.entrypoint
   }
 }
 
diff --git a/ops/terraform/deploy-nixos/nixos-eval.sh b/ops/terraform/deploy-nixos/nixos-eval.sh
index dd15784b1b..38f036bba9 100755
--- a/ops/terraform/deploy-nixos/nixos-eval.sh
+++ b/ops/terraform/deploy-nixos/nixos-eval.sh
@@ -5,12 +5,11 @@ set -ueo pipefail
 
 # Load input variables from Terraform. jq's @sh format takes care of
 # escaping.
-eval "$(jq -r '@sh "ATTRPATH=\(.attrpath)"')"
+eval "$(jq -r '@sh "ATTRPATH=\(.attrpath) && ENTRYPOINT=\(.entrypoint)"')"
 
 # Evaluate the system derivation.
-# TODO: configurable REPO_ROOT
-REPO_ROOT=$(git rev-parse --show-toplevel)
-SYSTEM_DRV=$(nix-instantiate -A "${ATTRPATH}" "${REPO_ROOT}")
+[[ -z "$ENTRYPOINT" ]] && ENTRYPOINT=$(git rev-parse --show-toplevel)
+SYSTEM_DRV=$(nix-instantiate -A "${ATTRPATH}" "${ENTRYPOINT}")
 
 # Return system derivation back to Terraform.
 jq -n --arg drv "$SYSTEM_DRV" '{"drv":$drv}'