nixos/adguardhome: run --check-config before merging

To prevent merging configurations on different `schema_version`,
we will now check the existing configuration, which has the side-effect of
updating the `schema_version`.

Fixes #246461 as described in https://github.com/NixOS/nixpkgs/issues/246461#issuecomment-1667663556
This commit is contained in:
Carl Richard Theodor Schneider 2024-04-30 22:47:52 +02:00
parent c4b3e96167
commit 3e86aba9d2

View File

@ -167,8 +167,13 @@ in {
preStart = 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
# Writing directly to AdGuardHome.yaml results in empty file
${pkgs.yaml-merge}/bin/yaml-merge "$STATE_DIRECTORY/AdGuardHome.yaml" "${configFile}" > "$STATE_DIRECTORY/AdGuardHome.yaml.tmp"
${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"
@ -178,7 +183,7 @@ in {
serviceConfig = {
DynamicUser = true;
ExecStart = "${cfg.package}/bin/adguardhome ${args}";
ExecStart = "${lib.getExe cfg.package} ${args}";
AmbientCapabilities = [ "CAP_NET_BIND_SERVICE" ]
++ optionals cfg.allowDHCP [ "CAP_NET_RAW" ];
Restart = "always";