--- /dev/null
+{ config, lib, pkgs, ... }:
+let
+ localpkgs = import ../. { inherit pkgs; };
+ register-script = pkgs.writeShellScript "syncthing-autoregister-script" ''
+ ${localpkgs.syncthing-set-id}/bin/syncthing-set-id /tmp/syncthing-auto-register-test-device-ids.nix
+ '';
+in {
+ config = {
+ systemd.services.syncthing-autoregister = {
+ after = [ "syncthing.service" "syncthing-init.service" ];
+ wantedBy = [ "multi-user.target" ];
+ environment.NIX_PATH = config.environment.variables.NIX_PATH;
+ serviceConfig = {
+ User = config.services.syncthing.user;
+ RemainAfterExit = true;
+ Type = "oneshot";
+ ExecStart = register-script;
+ };
+ };
+ };
+}
+
--- /dev/null
+import <nixpkgs/nixos/tests/make-test-python.nix> ({ pkgs, lib, ... }:
+ let
+ configuration = pkgs.writeText "configuration.nix" ''
+ { pkgs, ... }: {
+ imports = [
+ ${../.}/modules/syncthing-autoregister.nix
+ <nixos/nixos/modules/installer/cd-dvd/channel.nix>
+ ];
+ services.syncthing = {
+ enable = true;
+ openDefaultPorts = true;
+ };
+ environment.systemPackages = with pkgs; [ nix ];
+ }
+ '';
+ in {
+
+ name = "syncthing";
+
+ machine = "${configuration}";
+
+ testScript = ''
+ machine.copy_from_host(
+ "${configuration}",
+ "/etc/nixos/configuration.nix",
+ )
+ machine.wait_for_unit("syncthing-autoregister.service")
+ machine.succeed(
+ '(( "$(nix eval --raw -f /tmp/syncthing-auto-register-test-device-ids.nix services.syncthing.declarative.devices.machine.id | wc -c)" == 63 ))'
+ )
+ '';
+ })