tvl-depot/ops/terraform/deploy-nixos/nixos-eval.sh
Florian Klink 35f636b684 feat(ops/terraform/deploy-nixos): support argstr map
This allows setting argstr to a map of keys and values.
We use jq to construct "--argstr k v" arguments, which are passed to
nix-instantiate.

Change-Id: I720a597ca2276364bc7005c156064d938f143041
Reviewed-on: https://cl.tvl.fyi/c/depot/+/11141
Tested-by: BuildkiteCI
Autosubmit: flokli <flokli@flokli.de>
Reviewed-by: tazjin <tazjin@tvl.su>
2024-03-14 07:14:55 +00:00

21 lines
738 B
Bash
Executable file

#!/usr/bin/env bash
# SPDX-FileCopyrightText: 2023 The TVL Authors
#
# SPDX-License-Identifier: MIT
#
# Builds a NixOS system configuration at the given attribute path.
set -ueo pipefail
# Load input variables from Terraform. jq's @sh format takes care of
# escaping.
eval "$(jq -r '@sh "attrpath=\(.attrpath) && entrypoint=\(.entrypoint) && argstr=\((.argstr // {}) | to_entries | map ("--argstr", .key, .value) | join(" "))"')"
# Evaluate the system derivation.
[[ -z "$entrypoint" ]] && entrypoint=$(git rev-parse --show-toplevel)
# shellcheck disable=SC2086,SC2154
system_drv=$(nix-instantiate -A "${attrpath}" "${entrypoint}" ${argstr})
# Return system derivation back to Terraform.
jq -n --arg drv "$system_drv" '{"drv":$drv}'