]>
Commit | Line | Data |
---|---|---|
b00b144b SW |
1 | import <nixpkgs/nixos/tests/make-test-python.nix> ({ pkgs, lib, ... }: |
2 | let | |
e16b7079 | 3 | deviceIDFilename = "/tmp/syncthing-auto-register-test-device-ids.nix"; |
b00b144b SW |
4 | configuration = pkgs.writeText "configuration.nix" '' |
5 | { pkgs, ... }: { | |
6 | imports = [ | |
7 | ${../.}/modules/syncthing-autoregister.nix | |
8 | <nixos/nixos/modules/installer/cd-dvd/channel.nix> | |
9 | ]; | |
10 | services.syncthing = { | |
11 | enable = true; | |
12 | openDefaultPorts = true; | |
7fb0951b SW |
13 | autoRegister = { |
14 | enable = true; | |
e16b7079 | 15 | path = "${deviceIDFilename}"; |
7fb0951b | 16 | }; |
b00b144b SW |
17 | }; |
18 | environment.systemPackages = with pkgs; [ nix ]; | |
19 | } | |
20 | ''; | |
2475b534 SW |
21 | initialConfiguration = pkgs.writeText "initial-configuration.nix" '' |
22 | { | |
23 | imports = [ "${configuration}" ]; | |
24 | system.activationScripts.installInitialConfiguration = { | |
25 | text = ''' | |
26 | mkdir -p /etc/nixos | |
27 | cp "${configuration}" /etc/nixos/configuration.nix | |
28 | '''; | |
29 | deps = [ ]; | |
30 | }; | |
31 | } | |
32 | ''; | |
97c3aa62 SW |
33 | configurationWithDeviceIDs = |
34 | pkgs.writeText "configuration-with-device-ids.nix" '' | |
35 | { | |
36 | imports = [ | |
37 | ${configuration} | |
e16b7079 | 38 | ${deviceIDFilename} |
97c3aa62 SW |
39 | ]; |
40 | } | |
41 | ''; | |
b00b144b SW |
42 | in { |
43 | ||
44 | name = "syncthing"; | |
45 | ||
cefa20b6 | 46 | nodes = { |
2475b534 SW |
47 | a = "${initialConfiguration}"; |
48 | b = "${initialConfiguration}"; | |
cefa20b6 | 49 | }; |
b00b144b SW |
50 | |
51 | testScript = '' | |
97c3aa62 SW |
52 | def setConfig(machine, config): |
53 | machine.copy_from_host(config, "/etc/nixos/configuration.nix") | |
54 | ||
55 | ||
0a262b79 SW |
56 | def verifyDeviceIDSet(machine, expectedDevice): |
57 | machine.succeed( | |
58 | '(( "$(nix eval --raw -f "<nixos/nixos>" config.services.syncthing.declarative.devices.%s.id | wc -c)" == 63 ))' | |
59 | % expectedDevice | |
60 | ) | |
61 | ||
62 | ||
97c3aa62 SW |
63 | configurationWithDeviceIDs = ( |
64 | "${configurationWithDeviceIDs}" | |
b00b144b | 65 | ) |
97c3aa62 | 66 | |
cefa20b6 SW |
67 | a.wait_for_unit("syncthing-autoregister.service") |
68 | setConfig(a, configurationWithDeviceIDs) | |
0a262b79 | 69 | verifyDeviceIDSet(a, "a") |
b00b144b SW |
70 | ''; |
71 | }) |