1 import <nixpkgs/nixos/tests/make-test-python.nix> ({ pkgs, lib, ... }:
3 deviceIDFilename = "/tmp/syncthing-auto-register-test-device-ids.nix";
4 configuration = pkgs.writeText "configuration.nix" ''
7 ${../.}/modules/syncthing-autoregister.nix
8 <nixos/nixos/modules/installer/cd-dvd/channel.nix>
10 services.syncthing = {
12 openDefaultPorts = true;
15 path = "${deviceIDFilename}";
18 environment.systemPackages = with pkgs; [ nix ];
21 initialConfiguration = pkgs.writeText "initial-configuration.nix" ''
23 imports = [ "${configuration}" ];
24 system.activationScripts.installInitialConfiguration = {
27 cp "${configuration}" /etc/nixos/configuration.nix
33 configurationWithDeviceIDs =
34 pkgs.writeText "configuration-with-device-ids.nix" ''
47 a = "${initialConfiguration}";
48 b = "${initialConfiguration}";
55 def setConfig(machine, config):
56 machine.copy_from_host(config, "/etc/nixos/configuration.nix")
59 def verifyDeviceIDSet(machine, expectedDevice):
61 '(( "$(nix eval --raw -f "<nixos/nixos>" config.services.syncthing.declarative.devices.%s.id | wc -c)" == 63 ))'
66 configurationWithDeviceIDs = (
67 "${configurationWithDeviceIDs}"
70 hostDeviceIDFilename = os.path.join(
72 os.path.basename("${deviceIDFilename}"),
75 a.wait_for_unit("syncthing-autoregister.service")
76 setConfig(a, configurationWithDeviceIDs)
77 verifyDeviceIDSet(a, "a")
78 a.copy_from_vm("${deviceIDFilename}")
81 hostDeviceIDFilename, "${deviceIDFilename}"
83 b.succeed("chown syncthing ${deviceIDFilename}")
84 setConfig(b, configurationWithDeviceIDs)
85 verifyDeviceIDSet(b, "a")