Add a bash function for converting yaml to nix

Signed-off-by: Magic_RB <magic_rb@redalder.org>
This commit is contained in:
Magic_RB 2023-05-28 12:43:00 +02:00
parent f9a53c7cbb
commit 44df8c3076
No known key found for this signature in database
GPG key ID: 08D5287CC5DDCA0E

View file

@ -124,3 +124,18 @@ function loadenv()
$(passhead Infrastructure/Consul) \ $(passhead Infrastructure/Consul) \
$(passhead Infrastructure/Influx) $(passhead Infrastructure/Influx)
} }
function yaml2nix()
{
input_file="$1"
output_file="$2"
if [ "${input_file}" = "${output_file}" ] ; then
remarshal -if yaml -of json -i "${input_file}" -o /dev/stdout | nix eval --impure --expr 'builtins.fromJSON (builtins.readFile "/dev/stdin")' > "${input_file}.tmp"
mv "${input_file}.tmp" "${output_file}"
else
remarshal -if yaml -of json -i "${input_file}" -o /dev/stdout | nix eval --impure --expr 'builtins.fromJSON (builtins.readFile "/dev/stdin")' > "${output_file}"
fi
nixfmt "${output_file}"
}