From 9a9ded1675b9cba302c50ee1d0616199cc4bc321 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Na=C3=AFm=20Favier?= Date: Fri, 23 Jun 2023 20:12:19 +0200 Subject: [PATCH] nixos/syncthing: fix escaping --- nixos/modules/services/networking/syncthing.nix | 6 +++--- nixos/tests/syncthing-init.nix | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/nixos/modules/services/networking/syncthing.nix b/nixos/modules/services/networking/syncthing.nix index 3d41fe4013ea..69b45eb02d1d 100644 --- a/nixos/modules/services/networking/syncthing.nix +++ b/nixos/modules/services/networking/syncthing.nix @@ -55,9 +55,9 @@ let # generate the new config by merging with the NixOS config options new_cfg=$(printf '%s\n' "$old_cfg" | ${pkgs.jq}/bin/jq -c '. * { - "devices": (${builtins.toJSON devices}${optionalString (cfg.devices == {} || ! cfg.overrideDevices) " + .devices"}), - "folders": (${builtins.toJSON folders}${optionalString (cfg.folders == {} || ! cfg.overrideFolders) " + .folders"}) - } * ${builtins.toJSON cfg.extraOptions}') + "devices": ('${escapeShellArg (builtins.toJSON devices)}'${optionalString (cfg.devices == {} || ! cfg.overrideDevices) " + .devices"}), + "folders": ('${escapeShellArg (builtins.toJSON folders)}'${optionalString (cfg.folders == {} || ! cfg.overrideFolders) " + .folders"}) + } * '${escapeShellArg (builtins.toJSON cfg.extraOptions)}) # send the new config curl -X PUT -d "$new_cfg" ${cfg.guiAddress}/rest/config diff --git a/nixos/tests/syncthing-init.nix b/nixos/tests/syncthing-init.nix index fcd90739e6a5..5102c0127832 100644 --- a/nixos/tests/syncthing-init.nix +++ b/nixos/tests/syncthing-init.nix @@ -1,6 +1,7 @@ import ./make-test-python.nix ({ lib, pkgs, ... }: let testId = "7CFNTQM-IMTJBHJ-3UWRDIU-ZGQJFR6-VCXZ3NB-XUH3KZO-N52ITXR-LAIYUAU"; + testName = "testDevice foo'bar"; in { name = "syncthing-init"; @@ -9,12 +10,12 @@ in { nodes.machine = { services.syncthing = { enable = true; - devices.testDevice = { + devices.${testName} = { id = testId; }; folders.testFolder = { path = "/tmp/test"; - devices = [ "testDevice" ]; + devices = [ testName ]; }; extraOptions.gui.user = "guiUser"; };