about summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorMaximilian Bosch <maximilian@mbosch.me>2018-09-17 23:08:43 +0200
committerMaximilian Bosch <maximilian@mbosch.me>2018-12-18 01:58:56 +0100
commit113a6b9325b92d483e6c2f12c35c2887ab175a8d (patch)
tree42cf330ce8f8b4b4a10dc30c7d4a393a3a2cfa20 /nixos
parentbc1911e96e0705cd54983b6555ca25c55a66ded6 (diff)
downloadnixlib-113a6b9325b92d483e6c2f12c35c2887ab175a8d.tar
nixlib-113a6b9325b92d483e6c2f12c35c2887ab175a8d.tar.gz
nixlib-113a6b9325b92d483e6c2f12c35c2887ab175a8d.tar.bz2
nixlib-113a6b9325b92d483e6c2f12c35c2887ab175a8d.tar.lz
nixlib-113a6b9325b92d483e6c2f12c35c2887ab175a8d.tar.xz
nixlib-113a6b9325b92d483e6c2f12c35c2887ab175a8d.tar.zst
nixlib-113a6b9325b92d483e6c2f12c35c2887ab175a8d.zip
nixos/testing: disallow special chars in machine names in network expressions
These names are referenced by Perl variables inside the testing
frameworks which don't allow chars like `-` as character inside. An exemplary
expression may look like this:

```
{
  x11-vm = {
    services.xserver.enable = true;
  };
}
```

This expression evaluates, e.g. when running `nixos-build-vms`, but when
trying to run `./result/bin/nixos-run-vms`, an error like this occurs:

```
starting VDE switch for network 1
running the VM test script
error: Can't modify subtraction (-) in scalar assignment at (eval 17) line 1, at EOF
Bareword "test" not allowed while "strict subs" in use at (eval 17) line 1.
Can't modify subtraction (-) in scalar assignment at (eval 17) line 1, at EOF
Bareword "test" not allowed while "strict subs" in use at (eval 17) line 1.
vde_switch: EOF on stdin, cleaning up and exiting
cleaning up
```

This can be very confusing for beginners, this change breaks evaluation
if such names are used for machines.
Diffstat (limited to 'nixos')
-rw-r--r--nixos/lib/testing.nix20
1 files changed, 17 insertions, 3 deletions
diff --git a/nixos/lib/testing.nix b/nixos/lib/testing.nix
index 42a0c60c7e19..3fb691409a0d 100644
--- a/nixos/lib/testing.nix
+++ b/nixos/lib/testing.nix
@@ -149,9 +149,23 @@ in rec {
       test = passMeta (runTests driver);
       report = passMeta (releaseTools.gcovReport { coverageRuns = [ test ]; });
 
-    in (if makeCoverageReport then report else test) // {
-      inherit nodes driver test;
-    };
+      nodeNames = builtins.attrNames nodes;
+      invalidNodeNames = lib.filter
+        (node: builtins.match "^[A-z_][A-z0-9_]+$" node == null) nodeNames;
+
+    in
+      if lib.length invalidNodeNames > 0 then
+        throw ''
+          Cannot create machines out of (${lib.concatStringsSep ", " invalidNodeNames})!
+          All machines are references as perl variables in the testing framework which will break the
+          script when special characters are allowed.
+
+          Please stick to alphanumeric chars and underscores as separation.
+        ''
+      else
+        (if makeCoverageReport then report else test) // {
+          inherit nodes driver test;
+        };
 
   runInMachine =
     { drv