]> git.scottworley.com Git - syncthing-autoregister/commitdiff
Verify files sync after "nixos-rebuild switch"
authorScott Worley <scottworley@scottworley.com>
Wed, 29 Jul 2020 23:41:10 +0000 (16:41 -0700)
committerScott Worley <scottworley@scottworley.com>
Wed, 29 Jul 2020 23:41:10 +0000 (16:41 -0700)
lib/test-nixos-rebuild-switch-config.nix [new file with mode: 0644]
tests/automatic-enrollment.nix

diff --git a/lib/test-nixos-rebuild-switch-config.nix b/lib/test-nixos-rebuild-switch-config.nix
new file mode 100644 (file)
index 0000000..a31a39e
--- /dev/null
@@ -0,0 +1,38 @@
+{ lib, pkgs, ... }: {
+  imports = [
+    <nixos/nixos/modules/installer/cd-dvd/channel.nix>
+    <nixos/nixos/modules/profiles/base.nix>
+    <nixos/nixos/modules/testing/test-instrumentation.nix>
+    <nixos/nixos/modules/virtualisation/qemu-vm.nix>
+  ];
+
+  nix.binaryCaches = lib.mkForce [ ];
+  nix.extraOptions = ''
+    hashed-mirrors =
+    connect-timeout = 1
+  '';
+
+  system.extraDependencies = with pkgs; [
+    # List of packages from installer test
+    curl                # To diagnose fetch requests
+    desktop-file-utils
+    docbook5
+    docbook_xsl_ns
+    grub
+    libxml2.bin
+    libxslt.bin
+    nixos-artwork.wallpapers.simple-dark-gray-bottom
+    ntp
+    perlPackages.ListCompare
+    perlPackages.XMLLibXML
+    shared-mime-info
+    stdenvNoCC
+    sudo
+    texinfo
+    unionfs-fuse
+    xorg.lndir
+  ];
+
+  # Don't try to install bootloaders in a VM
+  boot.loader.grub.devices = lib.mkForce [ "nodev" ];
+}
index 617f672e4da38f157986db9d2f7b2d1ef3be764b..184bcc75e99c455f335d888479f8866f01b95c1d 100644 (file)
@@ -1,11 +1,11 @@
 import <nixpkgs/nixos/tests/make-test-python.nix> ({ pkgs, lib, ... }:
   let
     deviceIDFilename = "/tmp/syncthing-auto-register-test-device-ids.nix";
 import <nixpkgs/nixos/tests/make-test-python.nix> ({ pkgs, lib, ... }:
   let
     deviceIDFilename = "/tmp/syncthing-auto-register-test-device-ids.nix";
-    configuration = pkgs.writeText "configuration.nix" ''
+    vmConfiguration = pkgs.writeText "vm-configuration.nix" ''
       { pkgs, ... }: {
         imports = [
       { pkgs, ... }: {
         imports = [
+          ${../.}/lib/test-nixos-rebuild-switch-config.nix
           ${../.}/modules/syncthing-autoregister.nix
           ${../.}/modules/syncthing-autoregister.nix
-          <nixos/nixos/modules/installer/cd-dvd/channel.nix>
         ];
         services.syncthing = {
           enable = true;
         ];
         services.syncthing = {
           enable = true;
@@ -15,37 +15,76 @@ import <nixpkgs/nixos/tests/make-test-python.nix> ({ pkgs, lib, ... }:
             path = "${deviceIDFilename}";
           };
         };
             path = "${deviceIDFilename}";
           };
         };
+
+        # For verifyDeviceIDSet()
         environment.systemPackages = with pkgs; [ nix ];
       }
     '';
         environment.systemPackages = with pkgs; [ nix ];
       }
     '';
-    initialConfiguration = pkgs.writeText "initial-configuration.nix" ''
-      {
-        imports = [ "${configuration}" ];
+
+    evaluatedVMConfiguration = import <nixos/nixos/lib/eval-config.nix> {
+      system = builtins.currentSystem;
+      modules = [ "${vmConfiguration}" ];
+    };
+
+    # Also include a syncthing configuration with a declarative device id
+    # because using this feature pulls in additional dependencies.
+    evaluatedSyncthingDeclarativeConfiguration = import <nixos/nixos/lib/eval-config.nix> {
+      system = builtins.currentSystem;
+      modules = [
+        ../lib/test-nixos-rebuild-switch-config.nix
+        {
+          services.syncthing = {
+            enable = true;
+            declarative.folders.forDeps.path = "/nope";
+          };
+        }
+      ];
+    };
+
+    initialConfiguration = {
+        imports = [ "${vmConfiguration}" ];
+        virtualisation.memorySize = 2048;
         system.activationScripts.installInitialConfiguration = {
         system.activationScripts.installInitialConfiguration = {
-          text = '''
+          text = ''
             mkdir -p /etc/nixos
             mkdir -p /etc/nixos
-            cp "${configuration}" /etc/nixos/configuration.nix
-          ''';
+            cp "${vmConfiguration}" /etc/nixos/configuration.nix
+          '';
           deps = [ ];
         };
           deps = [ ];
         };
-      }
-    '';
+        system.extraDependencies = [
+          evaluatedVMConfiguration.config.system.build.toplevel
+          evaluatedSyncthingDeclarativeConfiguration.config.system.build.toplevel
+        ];
+      };
+
     configurationWithDeviceIDs =
       pkgs.writeText "configuration-with-device-ids.nix" ''
         {
           imports = [
     configurationWithDeviceIDs =
       pkgs.writeText "configuration-with-device-ids.nix" ''
         {
           imports = [
-            ${configuration}
+            ${vmConfiguration}
             ${deviceIDFilename}
           ];
         }
       '';
             ${deviceIDFilename}
           ];
         }
       '';
+
+    configurationWithFolder =
+      pkgs.writeText "configuration-with-folder.nix" ''
+        { config, ... }: {
+          imports = [ ${configurationWithDeviceIDs} ];
+          services.syncthing.declarative.folders.foo = {
+            devices = [ "a" "b" ];
+            path = "''${config.services.syncthing.dataDir}/foo";
+          };
+        }
+      '';
+
   in {
 
     name = "syncthing";
 
     nodes = {
   in {
 
     name = "syncthing";
 
     nodes = {
-      a = "${initialConfiguration}";
-      b = "${initialConfiguration}";
+      a = initialConfiguration;
+      b = initialConfiguration;
     };
 
     testScript = ''
     };
 
     testScript = ''
@@ -81,6 +120,9 @@ import <nixpkgs/nixos/tests/make-test-python.nix> ({ pkgs, lib, ... }:
       configurationWithDeviceIDs = (
           "${configurationWithDeviceIDs}"
       )
       configurationWithDeviceIDs = (
           "${configurationWithDeviceIDs}"
       )
+      configurationWithFolder = (
+          "${configurationWithFolder}"
+      )
 
       start_all()
       a.wait_for_unit("syncthing-autoregister.service")
 
       start_all()
       a.wait_for_unit("syncthing-autoregister.service")
@@ -93,5 +135,18 @@ import <nixpkgs/nixos/tests/make-test-python.nix> ({ pkgs, lib, ... }:
       setConfig(b, configurationWithDeviceIDs)
       verifyDeviceIDSet(b, "a")
       verifyDeviceIDSet(b, "b")
       setConfig(b, configurationWithDeviceIDs)
       verifyDeviceIDSet(b, "a")
       verifyDeviceIDSet(b, "b")
+
+      getDeviceFile(b)
+      putDeviceFile(a)
+      setConfig(a, configurationWithFolder)
+      setConfig(b, configurationWithFolder)
+      a.succeed("nixos-rebuild switch")
+      b.succeed("nixos-rebuild switch")
+      a.wait_for_file("/var/lib/syncthing/foo")
+      b.wait_for_file("/var/lib/syncthing/foo")
+      a.succeed("echo a2b > /var/lib/syncthing/foo/a2b")
+      b.succeed("echo b2a > /var/lib/syncthing/foo/b2a")
+      a.wait_for_file("/var/lib/syncthing/foo/b2a")
+      b.wait_for_file("/var/lib/syncthing/foo/a2b")
     '';
   })
     '';
   })