mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-09 19:13:26 +03:00
[Backport release-25.05] nixos/olivetin: use yq-go to merge config files (#415121)
This commit is contained in:
commit
98ee4579d1
1 changed files with 7 additions and 21 deletions
|
@ -102,30 +102,16 @@ in
|
||||||
inherit (cfg) path;
|
inherit (cfg) path;
|
||||||
|
|
||||||
preStart = ''
|
preStart = ''
|
||||||
tmp="$(mktemp -d)"
|
shopt -s nullglob
|
||||||
trap 'rm -rf "$tmp"' EXIT
|
|
||||||
cd "$tmp"
|
|
||||||
|
|
||||||
cp ${settingsFormat.generate "olivetin-config.yaml" cfg.settings} config.yaml
|
tmp="$(mktemp)"
|
||||||
chmod +w config.yaml
|
${lib.getExe pkgs.yq-go} eval-all '. as $item ireduce ({}; . *+ $item)' \
|
||||||
for ((i=0; i < ${toString (lib.length cfg.extraConfigFiles)}; i++)); do
|
${settingsFormat.generate "olivetin-config.yaml" cfg.settings} \
|
||||||
${lib.getExe pkgs.yq} -yi '
|
$CREDENTIALS_DIRECTORY/config-*.yaml > "$tmp"
|
||||||
def merge($y):
|
chmod -w "$tmp"
|
||||||
. as $x |
|
|
||||||
if ($x | type == "object") and ($y | type == "object") then
|
|
||||||
$x + $y + with_entries(select(.key | in($y)) | .key as $key | .value |= merge($y[$key]))
|
|
||||||
elif ($x | type == "array") and ($y | type == "array") then
|
|
||||||
$x + $y
|
|
||||||
else
|
|
||||||
$y
|
|
||||||
end;
|
|
||||||
merge($f | fromjson)
|
|
||||||
' config.yaml --rawfile f <(${lib.getExe pkgs.yq} -c . "$CREDENTIALS_DIRECTORY/config-$i.yaml")
|
|
||||||
done
|
|
||||||
chmod -w config.yaml
|
|
||||||
|
|
||||||
mkdir -p /run/olivetin/config
|
mkdir -p /run/olivetin/config
|
||||||
mv config.yaml /run/olivetin/config/config.yaml
|
mv "$tmp" /run/olivetin/config/config.yaml
|
||||||
'';
|
'';
|
||||||
|
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue