about summary refs log tree commit diff
path: root/ops/terraform/deploy-nixos/nixos-eval.sh
blob: dbc03d2fecf59b80fa30f096f6005e96e6ea6bd3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/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)"')"

# Evaluate the system derivation.
[[ -z "$entrypoint" ]] && entrypoint=$(git rev-parse --show-toplevel)
# shellcheck disable=SC2154
system_drv=$(nix-instantiate -A "${attrpath}" "${entrypoint}")

# Return system derivation back to Terraform.
jq -n --arg drv "$system_drv" '{"drv":$drv}'