nixos/syncthing: fix escaping

This commit is contained in:
Naïm Favier 2023-06-23 20:12:19 +02:00
parent 1fa8dad8e7
commit 9a9ded1675
No known key found for this signature in database
GPG Key ID: 95AFCE8211908325
2 changed files with 6 additions and 5 deletions

View File

@ -55,9 +55,9 @@ let
# generate the new config by merging with the NixOS config options # generate the new config by merging with the NixOS config options
new_cfg=$(printf '%s\n' "$old_cfg" | ${pkgs.jq}/bin/jq -c '. * { new_cfg=$(printf '%s\n' "$old_cfg" | ${pkgs.jq}/bin/jq -c '. * {
"devices": (${builtins.toJSON devices}${optionalString (cfg.devices == {} || ! cfg.overrideDevices) " + .devices"}), "devices": ('${escapeShellArg (builtins.toJSON devices)}'${optionalString (cfg.devices == {} || ! cfg.overrideDevices) " + .devices"}),
"folders": (${builtins.toJSON folders}${optionalString (cfg.folders == {} || ! cfg.overrideFolders) " + .folders"}) "folders": ('${escapeShellArg (builtins.toJSON folders)}'${optionalString (cfg.folders == {} || ! cfg.overrideFolders) " + .folders"})
} * ${builtins.toJSON cfg.extraOptions}') } * '${escapeShellArg (builtins.toJSON cfg.extraOptions)})
# send the new config # send the new config
curl -X PUT -d "$new_cfg" ${cfg.guiAddress}/rest/config curl -X PUT -d "$new_cfg" ${cfg.guiAddress}/rest/config

View File

@ -1,6 +1,7 @@
import ./make-test-python.nix ({ lib, pkgs, ... }: let import ./make-test-python.nix ({ lib, pkgs, ... }: let
testId = "7CFNTQM-IMTJBHJ-3UWRDIU-ZGQJFR6-VCXZ3NB-XUH3KZO-N52ITXR-LAIYUAU"; testId = "7CFNTQM-IMTJBHJ-3UWRDIU-ZGQJFR6-VCXZ3NB-XUH3KZO-N52ITXR-LAIYUAU";
testName = "testDevice foo'bar";
in { in {
name = "syncthing-init"; name = "syncthing-init";
@ -9,12 +10,12 @@ in {
nodes.machine = { nodes.machine = {
services.syncthing = { services.syncthing = {
enable = true; enable = true;
devices.testDevice = { devices.${testName} = {
id = testId; id = testId;
}; };
folders.testFolder = { folders.testFolder = {
path = "/tmp/test"; path = "/tmp/test";
devices = [ "testDevice" ]; devices = [ testName ];
}; };
extraOptions.gui.user = "guiUser"; extraOptions.gui.user = "guiUser";
}; };