mirror of
https://git.sr.ht/~magic_rb/dotfiles
synced 2024-11-22 08:04:20 +01:00
Add a bash function for converting yaml to nix
Signed-off-by: Magic_RB <magic_rb@redalder.org>
This commit is contained in:
parent
f9a53c7cbb
commit
44df8c3076
|
@ -124,3 +124,18 @@ function loadenv()
|
|||
$(passhead Infrastructure/Consul) \
|
||||
$(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}"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue