Loading nixos/modules/services/networking/syncthing.nix +276 −276 Original line number Diff line number Diff line Loading @@ -9,11 +9,11 @@ let devices = mapAttrsToList (name: device: { deviceID = device.id; inherit (device) name addresses introducer; }) cfg.declarative.devices; }) cfg.devices; folders = mapAttrsToList ( _: folder: { inherit (folder) path id label type; devices = map (device: { deviceId = cfg.declarative.devices.${device}.id; }) folder.devices; devices = map (device: { deviceId = cfg.devices.${device}.id; }) folder.devices; rescanIntervalS = folder.rescanInterval; fsWatcherEnabled = folder.watch; fsWatcherDelayS = folder.watchDelay; Loading @@ -23,7 +23,7 @@ let }) (filterAttrs ( _: folder: folder.enable ) cfg.declarative.folders); ) cfg.folders); updateConfig = pkgs.writers.writeDash "merge-syncthing-config" '' set -efu Loading @@ -50,9 +50,9 @@ let # generate the new config by merging with the NixOS config options new_cfg=$(echo "$old_cfg" | ${pkgs.jq}/bin/jq -c '. * { "devices": (${builtins.toJSON devices}${optionalString (! cfg.declarative.overrideDevices) " + .devices"}), "folders": (${builtins.toJSON folders}${optionalString (! cfg.declarative.overrideFolders) " + .folders"}) } * ${builtins.toJSON cfg.declarative.extraOptions}') "devices": (${builtins.toJSON devices}${optionalString (! cfg.overrideDevices) " + .devices"}), "folders": (${builtins.toJSON folders}${optionalString (! cfg.overrideFolders) " + .folders"}) } * ${builtins.toJSON cfg.extraOptions}') # send the new config curl -X PUT -d "$new_cfg" ${cfg.guiAddress}/rest/config Loading @@ -74,7 +74,6 @@ in { available on http://127.0.0.1:8384/. ''; declarative = { cert = mkOption { type = types.nullOr types.str; default = null; Loading @@ -98,7 +97,7 @@ in { default = true; description = '' Whether to delete the devices which are not configured via the <literal>declarative.devices</literal> option. <literal>devices</literal> option. If set to false, devices added via the webinterface will persist but will have to be deleted manually. ''; Loading Loading @@ -161,7 +160,7 @@ in { default = true; description = '' Whether to delete the folders which are not configured via the <literal>declarative.folders</literal> option. <literal>folders</literal> option. If set to false, folders added via the webinterface will persist but will have to be deleted manually. ''; Loading Loading @@ -222,7 +221,7 @@ in { default = []; description = '' The devices this folder should be shared with. Must be defined in the <literal>declarative.devices</literal> attribute. in the <literal>devices</literal> attribute. ''; }; Loading Loading @@ -352,7 +351,6 @@ in { gui.theme = "black"; }; }; }; guiAddress = mkOption { type = types.str; Loading Loading @@ -447,7 +445,9 @@ in { This option was removed because Syncthing now has the inotify functionality included under the name "fswatcher". It can be enabled on a per-folder basis through the webinterface. '') ]; ] ++ map (o: mkRenamedOptionModule [ "services" "syncthing" "declarative" o ] [ "services" "syncthing" o ] ) [ "cert" "key" "devices" "folders" "overrideDevices" "overrideFolders" "extraOptions"]; ###### implementation Loading Loading @@ -491,14 +491,14 @@ in { RestartForceExitStatus="3 4"; User = cfg.user; Group = cfg.group; ExecStartPre = mkIf (cfg.declarative.cert != null || cfg.declarative.key != null) ExecStartPre = mkIf (cfg.cert != null || cfg.key != null) "+${pkgs.writers.writeBash "syncthing-copy-keys" '' install -dm700 -o ${cfg.user} -g ${cfg.group} ${cfg.configDir} ${optionalString (cfg.declarative.cert != null) '' install -Dm400 -o ${cfg.user} -g ${cfg.group} ${toString cfg.declarative.cert} ${cfg.configDir}/cert.pem ${optionalString (cfg.cert != null) '' install -Dm400 -o ${cfg.user} -g ${cfg.group} ${toString cfg.cert} ${cfg.configDir}/cert.pem ''} ${optionalString (cfg.declarative.key != null) '' install -Dm400 -o ${cfg.user} -g ${cfg.group} ${toString cfg.declarative.key} ${cfg.configDir}/key.pem ${optionalString (cfg.key != null) '' install -Dm400 -o ${cfg.user} -g ${cfg.group} ${toString cfg.key} ${cfg.configDir}/key.pem ''} ''}" ; Loading Loading @@ -529,7 +529,7 @@ in { }; }; syncthing-init = mkIf ( cfg.declarative.devices != {} || cfg.declarative.folders != {} || cfg.declarative.extraOptions != {} cfg.devices != {} || cfg.folders != {} || cfg.extraOptions != {} ) { description = "Syncthing configuration updater"; after = [ "syncthing.service" ]; Loading nixos/tests/syncthing-init.nix +7 −9 Original line number Diff line number Diff line Loading @@ -9,7 +9,6 @@ in { machine = { services.syncthing = { enable = true; declarative = { devices.testDevice = { id = testId; }; Loading @@ -20,7 +19,6 @@ in { extraOptions.gui.user = "guiUser"; }; }; }; testScript = '' machine.wait_for_unit("syncthing-init.service") Loading Loading
nixos/modules/services/networking/syncthing.nix +276 −276 Original line number Diff line number Diff line Loading @@ -9,11 +9,11 @@ let devices = mapAttrsToList (name: device: { deviceID = device.id; inherit (device) name addresses introducer; }) cfg.declarative.devices; }) cfg.devices; folders = mapAttrsToList ( _: folder: { inherit (folder) path id label type; devices = map (device: { deviceId = cfg.declarative.devices.${device}.id; }) folder.devices; devices = map (device: { deviceId = cfg.devices.${device}.id; }) folder.devices; rescanIntervalS = folder.rescanInterval; fsWatcherEnabled = folder.watch; fsWatcherDelayS = folder.watchDelay; Loading @@ -23,7 +23,7 @@ let }) (filterAttrs ( _: folder: folder.enable ) cfg.declarative.folders); ) cfg.folders); updateConfig = pkgs.writers.writeDash "merge-syncthing-config" '' set -efu Loading @@ -50,9 +50,9 @@ let # generate the new config by merging with the NixOS config options new_cfg=$(echo "$old_cfg" | ${pkgs.jq}/bin/jq -c '. * { "devices": (${builtins.toJSON devices}${optionalString (! cfg.declarative.overrideDevices) " + .devices"}), "folders": (${builtins.toJSON folders}${optionalString (! cfg.declarative.overrideFolders) " + .folders"}) } * ${builtins.toJSON cfg.declarative.extraOptions}') "devices": (${builtins.toJSON devices}${optionalString (! cfg.overrideDevices) " + .devices"}), "folders": (${builtins.toJSON folders}${optionalString (! cfg.overrideFolders) " + .folders"}) } * ${builtins.toJSON cfg.extraOptions}') # send the new config curl -X PUT -d "$new_cfg" ${cfg.guiAddress}/rest/config Loading @@ -74,7 +74,6 @@ in { available on http://127.0.0.1:8384/. ''; declarative = { cert = mkOption { type = types.nullOr types.str; default = null; Loading @@ -98,7 +97,7 @@ in { default = true; description = '' Whether to delete the devices which are not configured via the <literal>declarative.devices</literal> option. <literal>devices</literal> option. If set to false, devices added via the webinterface will persist but will have to be deleted manually. ''; Loading Loading @@ -161,7 +160,7 @@ in { default = true; description = '' Whether to delete the folders which are not configured via the <literal>declarative.folders</literal> option. <literal>folders</literal> option. If set to false, folders added via the webinterface will persist but will have to be deleted manually. ''; Loading Loading @@ -222,7 +221,7 @@ in { default = []; description = '' The devices this folder should be shared with. Must be defined in the <literal>declarative.devices</literal> attribute. in the <literal>devices</literal> attribute. ''; }; Loading Loading @@ -352,7 +351,6 @@ in { gui.theme = "black"; }; }; }; guiAddress = mkOption { type = types.str; Loading Loading @@ -447,7 +445,9 @@ in { This option was removed because Syncthing now has the inotify functionality included under the name "fswatcher". It can be enabled on a per-folder basis through the webinterface. '') ]; ] ++ map (o: mkRenamedOptionModule [ "services" "syncthing" "declarative" o ] [ "services" "syncthing" o ] ) [ "cert" "key" "devices" "folders" "overrideDevices" "overrideFolders" "extraOptions"]; ###### implementation Loading Loading @@ -491,14 +491,14 @@ in { RestartForceExitStatus="3 4"; User = cfg.user; Group = cfg.group; ExecStartPre = mkIf (cfg.declarative.cert != null || cfg.declarative.key != null) ExecStartPre = mkIf (cfg.cert != null || cfg.key != null) "+${pkgs.writers.writeBash "syncthing-copy-keys" '' install -dm700 -o ${cfg.user} -g ${cfg.group} ${cfg.configDir} ${optionalString (cfg.declarative.cert != null) '' install -Dm400 -o ${cfg.user} -g ${cfg.group} ${toString cfg.declarative.cert} ${cfg.configDir}/cert.pem ${optionalString (cfg.cert != null) '' install -Dm400 -o ${cfg.user} -g ${cfg.group} ${toString cfg.cert} ${cfg.configDir}/cert.pem ''} ${optionalString (cfg.declarative.key != null) '' install -Dm400 -o ${cfg.user} -g ${cfg.group} ${toString cfg.declarative.key} ${cfg.configDir}/key.pem ${optionalString (cfg.key != null) '' install -Dm400 -o ${cfg.user} -g ${cfg.group} ${toString cfg.key} ${cfg.configDir}/key.pem ''} ''}" ; Loading Loading @@ -529,7 +529,7 @@ in { }; }; syncthing-init = mkIf ( cfg.declarative.devices != {} || cfg.declarative.folders != {} || cfg.declarative.extraOptions != {} cfg.devices != {} || cfg.folders != {} || cfg.extraOptions != {} ) { description = "Syncthing configuration updater"; after = [ "syncthing.service" ]; Loading
nixos/tests/syncthing-init.nix +7 −9 Original line number Diff line number Diff line Loading @@ -9,7 +9,6 @@ in { machine = { services.syncthing = { enable = true; declarative = { devices.testDevice = { id = testId; }; Loading @@ -20,7 +19,6 @@ in { extraOptions.gui.user = "guiUser"; }; }; }; testScript = '' machine.wait_for_unit("syncthing-init.service") Loading