Loading nixos/modules/services/networking/syncthing.nix +3 −3 Original line number Diff line number Diff line Loading @@ -272,7 +272,7 @@ let If it does, write the ignore patterns to the rest API. */ + lib.optionalString ((conf_type == "dirs") && (new_cfg.ignorePatterns != null)) '' curl -d '{"ignore": ${builtins.toJSON new_cfg.ignorePatterns}}' -X POST ${s.ignoreAddress}?folder=${new_cfg.id} curl -d '{"ignore": ${builtins.toJSON new_cfg.ignorePatterns}}' -X POST ${s.ignoreAddress}?folder=${lib.strings.escapeURL new_cfg.id} '' )) (lib.concatStringsSep "\n") Loading @@ -286,11 +286,11 @@ let 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 | .[]' '[.[].${s.GET_IdAttrName}] - $new_ids | .[]|@uri' )" for id in ''${stale_${conf_type}_ids}; do >&2 echo "Deleting stale device: $id" curl -X DELETE ${s.baseAddress}/$id curl -X DELETE "${s.baseAddress}/$id" done '' )) Loading nixos/tests/syncthing/folders.nix +31 −0 Original line number Diff line number Diff line Loading @@ -50,6 +50,12 @@ in ]; ignorePatterns = [ ]; }; folders."foo bar" = { path = "/var/lib/syncthing/foo-bar"; devices = [ "b" ]; }; }; }; }; Loading Loading @@ -88,6 +94,16 @@ in "notB" ]; }; # Test how we handle white spaces in folder IDs folders."foo bar" = { path = "/var/lib/syncthing/foo-bar"; devices = [ "a" ]; ignorePatterns = [ "notB" ]; }; }; }; }; Loading Loading @@ -183,5 +199,20 @@ in # Check that files have been correctly ignored b.fail("cat /var/lib/syncthing/baz/notB") c.fail("cat /var/lib/syncthing/baz/notC") # Test foo bar a.wait_for_file("/var/lib/syncthing/foo-bar") b.wait_for_file("/var/lib/syncthing/foo-bar") a.succeed("echo a2b > /var/lib/syncthing/foo-bar/a2b") a.succeed("echo a2b > /var/lib/syncthing/foo-bar/notB") b.succeed("echo b2a > /var/lib/syncthing/foo-bar/b2a") a.wait_for_file("/var/lib/syncthing/foo-bar/b2a") b.wait_for_file("/var/lib/syncthing/foo-bar/a2b") # Check that file has been correctly ignored b.fail("cat /var/lib/syncthing/foo-bar/notB") ''; } nixos/tests/syncthing/many-devices.nix +41 −28 Original line number Diff line number Diff line Loading @@ -102,10 +102,10 @@ let not, }: lib.pipe IDsToDelete [ (lib.mapAttrsToList ( t: id: (map ( obj: checkSettingWithId { inherit t id; inherit (obj) t id; inherit not; } )) Loading @@ -114,13 +114,23 @@ let # These IDs are added to syncthing using the API, similarly to how the # generated systemd unit's bash script does it. Only we add it and expect the # systemd unit bash script to remove them when executed. IDsToDelete = { # Also created using the syncthing generate command above device = "LZ2CTHT-3W2M7BC-CMKDFZL-DLUQJFS-WJR73PA-NZGODWG-DZBHCHI-OXTQXAK"; # Intentionally this is a substring of the IDs of the 'test_folder's, as # explained in: https://github.com/NixOS/nixpkgs/issues/259256 folder = "DeleteMe"; }; IDsToDelete = [ { t = "device"; id = "LZ2CTHT-3W2M7BC-CMKDFZL-DLUQJFS-WJR73PA-NZGODWG-DZBHCHI-OXTQXAK"; # Arbitrary, doesn't really matter name = "DeleteThisDevice"; } # Folders' id strings also use for their path when created. { t = "folder"; id = "DeleteMe"; } { t = "folder"; id = "Delete Me"; } ]; addDeviceToDeleteScript = pkgs.writers.writeBash "syncthing-add-device-to-delete.sh" '' set -euo pipefail Loading @@ -141,24 +151,27 @@ let --retry 5 --retry-delay 1 --retry-all-errors \ "$@" } ${lib.concatMapStringsSep "\n" (obj: '' curl -d ${ lib.escapeShellArg ( builtins.toJSON { deviceID = IDsToDelete.device; name = "DeleteMe"; builtins.toJSON ( if obj.t == "device" then { deviceID = obj.id; inherit (obj) name; } ) } \ -X POST 127.0.0.1:8384/rest/config/devices curl -d ${ lib.escapeShellArg ( builtins.toJSON { id = IDsToDelete.folder; path = "/var/lib/syncthing/DeleteMe"; else if obj.t == "folder" then { inherit (obj) id; path = "/var/lib/syncthing/${obj.id}"; } else throw "unsupported object type ${obj.t}" ) ) } \ -X POST 127.0.0.1:8384/rest/config/folders -X POST 127.0.0.1:8384/rest/config/${obj.t}s '') IDsToDelete} ''; in { Loading Loading
nixos/modules/services/networking/syncthing.nix +3 −3 Original line number Diff line number Diff line Loading @@ -272,7 +272,7 @@ let If it does, write the ignore patterns to the rest API. */ + lib.optionalString ((conf_type == "dirs") && (new_cfg.ignorePatterns != null)) '' curl -d '{"ignore": ${builtins.toJSON new_cfg.ignorePatterns}}' -X POST ${s.ignoreAddress}?folder=${new_cfg.id} curl -d '{"ignore": ${builtins.toJSON new_cfg.ignorePatterns}}' -X POST ${s.ignoreAddress}?folder=${lib.strings.escapeURL new_cfg.id} '' )) (lib.concatStringsSep "\n") Loading @@ -286,11 +286,11 @@ let 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 | .[]' '[.[].${s.GET_IdAttrName}] - $new_ids | .[]|@uri' )" for id in ''${stale_${conf_type}_ids}; do >&2 echo "Deleting stale device: $id" curl -X DELETE ${s.baseAddress}/$id curl -X DELETE "${s.baseAddress}/$id" done '' )) Loading
nixos/tests/syncthing/folders.nix +31 −0 Original line number Diff line number Diff line Loading @@ -50,6 +50,12 @@ in ]; ignorePatterns = [ ]; }; folders."foo bar" = { path = "/var/lib/syncthing/foo-bar"; devices = [ "b" ]; }; }; }; }; Loading Loading @@ -88,6 +94,16 @@ in "notB" ]; }; # Test how we handle white spaces in folder IDs folders."foo bar" = { path = "/var/lib/syncthing/foo-bar"; devices = [ "a" ]; ignorePatterns = [ "notB" ]; }; }; }; }; Loading Loading @@ -183,5 +199,20 @@ in # Check that files have been correctly ignored b.fail("cat /var/lib/syncthing/baz/notB") c.fail("cat /var/lib/syncthing/baz/notC") # Test foo bar a.wait_for_file("/var/lib/syncthing/foo-bar") b.wait_for_file("/var/lib/syncthing/foo-bar") a.succeed("echo a2b > /var/lib/syncthing/foo-bar/a2b") a.succeed("echo a2b > /var/lib/syncthing/foo-bar/notB") b.succeed("echo b2a > /var/lib/syncthing/foo-bar/b2a") a.wait_for_file("/var/lib/syncthing/foo-bar/b2a") b.wait_for_file("/var/lib/syncthing/foo-bar/a2b") # Check that file has been correctly ignored b.fail("cat /var/lib/syncthing/foo-bar/notB") ''; }
nixos/tests/syncthing/many-devices.nix +41 −28 Original line number Diff line number Diff line Loading @@ -102,10 +102,10 @@ let not, }: lib.pipe IDsToDelete [ (lib.mapAttrsToList ( t: id: (map ( obj: checkSettingWithId { inherit t id; inherit (obj) t id; inherit not; } )) Loading @@ -114,13 +114,23 @@ let # These IDs are added to syncthing using the API, similarly to how the # generated systemd unit's bash script does it. Only we add it and expect the # systemd unit bash script to remove them when executed. IDsToDelete = { # Also created using the syncthing generate command above device = "LZ2CTHT-3W2M7BC-CMKDFZL-DLUQJFS-WJR73PA-NZGODWG-DZBHCHI-OXTQXAK"; # Intentionally this is a substring of the IDs of the 'test_folder's, as # explained in: https://github.com/NixOS/nixpkgs/issues/259256 folder = "DeleteMe"; }; IDsToDelete = [ { t = "device"; id = "LZ2CTHT-3W2M7BC-CMKDFZL-DLUQJFS-WJR73PA-NZGODWG-DZBHCHI-OXTQXAK"; # Arbitrary, doesn't really matter name = "DeleteThisDevice"; } # Folders' id strings also use for their path when created. { t = "folder"; id = "DeleteMe"; } { t = "folder"; id = "Delete Me"; } ]; addDeviceToDeleteScript = pkgs.writers.writeBash "syncthing-add-device-to-delete.sh" '' set -euo pipefail Loading @@ -141,24 +151,27 @@ let --retry 5 --retry-delay 1 --retry-all-errors \ "$@" } ${lib.concatMapStringsSep "\n" (obj: '' curl -d ${ lib.escapeShellArg ( builtins.toJSON { deviceID = IDsToDelete.device; name = "DeleteMe"; builtins.toJSON ( if obj.t == "device" then { deviceID = obj.id; inherit (obj) name; } ) } \ -X POST 127.0.0.1:8384/rest/config/devices curl -d ${ lib.escapeShellArg ( builtins.toJSON { id = IDsToDelete.folder; path = "/var/lib/syncthing/DeleteMe"; else if obj.t == "folder" then { inherit (obj) id; path = "/var/lib/syncthing/${obj.id}"; } else throw "unsupported object type ${obj.t}" ) ) } \ -X POST 127.0.0.1:8384/rest/config/folders -X POST 127.0.0.1:8384/rest/config/${obj.t}s '') IDsToDelete} ''; in { Loading