summary refs log tree commit diff
path: root/nixos/tests
diff options
context:
space:
mode:
authoraszlig <aszlig@nix.build>2018-04-26 06:38:02 +0200
committeraszlig <aszlig@nix.build>2018-04-26 08:04:50 +0200
commit3e11ff6e0d9fb21a962408407f24b465b30fe96f (patch)
tree99245ead49830503f7a5ce0f67150232b08795e5 /nixos/tests
parent761266bd18cf1117a11d2fd6168259f7fe867122 (diff)
downloadnixlib-3e11ff6e0d9fb21a962408407f24b465b30fe96f.tar
nixlib-3e11ff6e0d9fb21a962408407f24b465b30fe96f.tar.gz
nixlib-3e11ff6e0d9fb21a962408407f24b465b30fe96f.tar.bz2
nixlib-3e11ff6e0d9fb21a962408407f24b465b30fe96f.tar.lz
nixlib-3e11ff6e0d9fb21a962408407f24b465b30fe96f.tar.xz
nixlib-3e11ff6e0d9fb21a962408407f24b465b30fe96f.tar.zst
nixlib-3e11ff6e0d9fb21a962408407f24b465b30fe96f.zip
nixos/dhparams: Introduce a 'stateful' option
This option allows us to turn off stateful generation of Diffie-Hellman
parameters, which in some way is still stateful as the generated DH
params file is non-deterministic.

However what we can avoid with this is to have an increased surface for
failures during system startup, because generation of the parameters is
done during build-time.

Another advantage of this is that we no longer need to take care of
cleaning up the files that are no longer used and in my humble opinion I
would have preferred that #11505 (which puts the dhparams in the Nix
store) would have been merged instead of #22634 (which we have now).

Luckily we can still change that and this change gives the user the
option to put the dhparams into the Nix store.

Beside of the more obvious advantages pointed out here, this also
effects test runtime if more services are starting to use this (for
example see #39507 and #39288), because generating DH params could take
a long time depending on the bit size which adds up to test runtime.

If we generate the DH params in a separate derivation, subsequent test
runs won't need to wait for DH params generation during bootup.

Of course, tests could still mock this by force-disabling the service
and adding a service or activation script that places pre-generated DH
params in /var/lib/dhparams but this would make tests less readable and
the workaround would have to be made for each test affected.

Note that the 'stateful' option is still true by default so that we are
backwards-compatible with existing systems.

Signed-off-by: aszlig <aszlig@nix.build>
Cc: @Ekleog, @abbradar, @fpletz
Diffstat (limited to 'nixos/tests')
-rw-r--r--nixos/tests/dhparams.nix21
1 files changed, 21 insertions, 0 deletions
diff --git a/nixos/tests/dhparams.nix b/nixos/tests/dhparams.nix
index ead5f2efce7c..da75391e4ce5 100644
--- a/nixos/tests/dhparams.nix
+++ b/nixos/tests/dhparams.nix
@@ -47,6 +47,13 @@ in import ./make-test.nix {
 
   nodes.generation3 = common;
 
+  nodes.generation4 = {
+    imports = [ common ];
+    security.dhparams.stateful = false;
+    security.dhparams.params.foo2.bits = 18;
+    security.dhparams.params.bar2.bits = 19;
+  };
+
   testScript = { nodes, ... }: let
     getParamPath = gen: name: let
       node = "generation${toString gen}";
@@ -105,5 +112,19 @@ in import ./make-test.nix {
         'test -e ${nodes.generation3.config.security.dhparams.path}'
       );
     };
+
+    ${switchToGeneration 4}
+
+    subtest "check bit sizes dhparam files", sub {
+      ${assertParamBits 4 "foo2" 18}
+      ${assertParamBits 4 "bar2" 19}
+    };
+
+    subtest "check whether dhparam files are in the Nix store", sub {
+      $machine->succeed(
+        'expr match ${getParamPath 4 "foo2"} ${builtins.storeDir}',
+        'expr match ${getParamPath 4 "bar2"} ${builtins.storeDir}',
+      );
+    };
   '';
 }