about summary refs log tree commit diff
path: root/nixos/modules
diff options
context:
space:
mode:
authorlassulus <git@lassul.us>2023-10-05 23:08:05 +0200
committerlassulus <git@lassul.us>2023-10-05 23:08:05 +0200
commit82b59a8fb23310b05aa570c213cf64df55db6c45 (patch)
treebe1a9a0b25c8cfac64161da49e43b8827f1502c0 /nixos/modules
parentfdd898f8f79e8d2f99ed2ab6b3751811ef683242 (diff)
downloadnixlib-82b59a8fb23310b05aa570c213cf64df55db6c45.tar
nixlib-82b59a8fb23310b05aa570c213cf64df55db6c45.tar.gz
nixlib-82b59a8fb23310b05aa570c213cf64df55db6c45.tar.bz2
nixlib-82b59a8fb23310b05aa570c213cf64df55db6c45.tar.lz
nixlib-82b59a8fb23310b05aa570c213cf64df55db6c45.tar.xz
nixlib-82b59a8fb23310b05aa570c213cf64df55db6c45.tar.zst
nixlib-82b59a8fb23310b05aa570c213cf64df55db6c45.zip
nixos/syncthing: match stale ids by subtracting in jq
Diffstat (limited to 'nixos/modules')
-rw-r--r--nixos/modules/services/networking/syncthing.nix14
1 files changed, 7 insertions, 7 deletions
diff --git a/nixos/modules/services/networking/syncthing.nix b/nixos/modules/services/networking/syncthing.nix
index 346b50700c79..d3f6853424c8 100644
--- a/nixos/modules/services/networking/syncthing.nix
+++ b/nixos/modules/services/networking/syncthing.nix
@@ -100,13 +100,13 @@ let
       the Nix configured list of IDs
       */
       + lib.optionalString s.override ''
-        old_conf_${conf_type}_ids="$(curl -X GET ${s.baseAddress} | ${jq} --raw-output '.[].${s.GET_IdAttrName}')"
-        for id in ''${old_conf_${conf_type}_ids}; do
-          if echo ${lib.concatStringsSep " " s.new_conf_IDs} | grep -q $id; then
-            continue
-          else
-            curl -X DELETE ${s.baseAddress}/$id
-          fi
+        stale_${conf_type}_ids="$(curl -X GET ${s.baseAddress} | ${jq} \
+          --argjson new_ids ${lib.escapeShellArg (builtins.toJSON s.new_conf_IDs)} \
+          --raw-output \
+          '[.[].${s.GET_IdAttrName}] - $new_ids | .[]'
+        )"
+        for id in ''${stale_${conf_type}_ids}; do
+          curl -X DELETE ${s.baseAddress}/$id
         done
       ''
     ))