nixos/adguardhome: fix shellcheck error in pre-start script

This commit is contained in:
SebastianStork 2026-06-03 22:11:15 +02:00
commit d9d779c24d
No known key found for this signature in database

View file

@ -176,22 +176,32 @@ in
StartLimitBurst = 10;
};
preStart = lib.optionalString (settings != null) ''
if [ -e "$STATE_DIRECTORY/AdGuardHome.yaml" ] \
&& [ "${toString cfg.mutableSettings}" = "1" ]; then
# First run a schema_version update on the existing configuration
# This ensures that both the new config and the existing one have the same schema_version
# Note: --check-config has the side effect of modifying the file at rest!
${lib.getExe cfg.package} -c "$STATE_DIRECTORY/AdGuardHome.yaml" --check-config
preStart =
let
installFresh = ''
cp --force "${configFile}" "$STATE_DIRECTORY/AdGuardHome.yaml"
chmod 600 "$STATE_DIRECTORY/AdGuardHome.yaml"
'';
in
lib.optionalString (settings != null) (
if cfg.mutableSettings then
''
if [ -e "$STATE_DIRECTORY/AdGuardHome.yaml" ]; then
# First run a schema_version update on the existing configuration
# This ensures that both the new config and the existing one have the same schema_version
# Note: --check-config has the side effect of modifying the file at rest!
${lib.getExe cfg.package} -c "$STATE_DIRECTORY/AdGuardHome.yaml" --check-config
# Writing directly to AdGuardHome.yaml results in empty file
${lib.getExe pkgs.yaml-merge} "$STATE_DIRECTORY/AdGuardHome.yaml" "${configFile}" > "$STATE_DIRECTORY/AdGuardHome.yaml.tmp"
mv "$STATE_DIRECTORY/AdGuardHome.yaml.tmp" "$STATE_DIRECTORY/AdGuardHome.yaml"
else
cp --force "${configFile}" "$STATE_DIRECTORY/AdGuardHome.yaml"
chmod 600 "$STATE_DIRECTORY/AdGuardHome.yaml"
fi
'';
# Writing directly to AdGuardHome.yaml results in empty file
${lib.getExe pkgs.yaml-merge} "$STATE_DIRECTORY/AdGuardHome.yaml" "${configFile}" > "$STATE_DIRECTORY/AdGuardHome.yaml.tmp"
mv "$STATE_DIRECTORY/AdGuardHome.yaml.tmp" "$STATE_DIRECTORY/AdGuardHome.yaml"
else
${installFresh}
fi
''
else
installFresh
);
serviceConfig = {
DynamicUser = true;