]> git.scottworley.com Git - syncthing-autoregister/commitdiff
Avoid race: Install initial configuration statically
authorScott Worley <scottworley@scottworley.com>
Mon, 27 Jul 2020 22:40:15 +0000 (15:40 -0700)
committerScott Worley <scottworley@scottworley.com>
Mon, 27 Jul 2020 22:40:15 +0000 (15:40 -0700)
tests/automatic-enrollment.nix

index 8cbcdc446b5743b57dcc2458e000651a1e0576f9..1a6b360bc28ebd6632598b43781d42b4a591b082 100644 (file)
@@ -17,6 +17,18 @@ import <nixpkgs/nixos/tests/make-test-python.nix> ({ pkgs, lib, ... }:
         environment.systemPackages = with pkgs; [ nix ];
       }
     '';
+    initialConfiguration = pkgs.writeText "initial-configuration.nix" ''
+      {
+        imports = [ "${configuration}" ];
+        system.activationScripts.installInitialConfiguration = {
+          text = '''
+            mkdir -p /etc/nixos
+            cp "${configuration}" /etc/nixos/configuration.nix
+          ''';
+          deps = [ ];
+        };
+      }
+    '';
     configurationWithDeviceIDs =
       pkgs.writeText "configuration-with-device-ids.nix" ''
         {
@@ -31,8 +43,8 @@ import <nixpkgs/nixos/tests/make-test-python.nix> ({ pkgs, lib, ... }:
     name = "syncthing";
 
     nodes = {
-      a = "${configuration}";
-      b = "${configuration}";
+      a = "${initialConfiguration}";
+      b = "${initialConfiguration}";
     };
 
     testScript = ''
@@ -47,12 +59,10 @@ import <nixpkgs/nixos/tests/make-test-python.nix> ({ pkgs, lib, ... }:
           )
 
 
-      initialConfiguration = "${configuration}"
       configurationWithDeviceIDs = (
           "${configurationWithDeviceIDs}"
       )
 
-      setConfig(a, initialConfiguration)
       a.wait_for_unit("syncthing-autoregister.service")
       setConfig(a, configurationWithDeviceIDs)
       verifyDeviceIDSet(a, "a")