about summary refs log tree commit diff
path: root/modules/profiles
diff options
context:
space:
mode:
authoraszlig <aszlig@redmoonstudios.org>2015-12-11 05:21:27 +0100
committeraszlig <aszlig@redmoonstudios.org>2015-12-11 05:21:27 +0100
commit006d6a6dd58c2e7fa7ddb88ed26b9aa6c1802f29 (patch)
tree8c1094fe31a289f91a7e188ee9dfa1a18cee357f /modules/profiles
parentde77a794486a31f66cd0fb8cd90653941dbe6d20 (diff)
profiles/common: Pass tests attribute to modules.
This is going to be used in modules or configurations to include tests
specific to the module, for example let's say you have a foo.nix module
that defines a foo service and you have a test named "foo" in the
tests.vuizvui namespace.

You can use it like this:

{ config, tests, lib, ... }:

{
  ... other options of the foo service module ...
  config = lib.mkIf config.foo.enable {
    vuizvui.requiresTests = [ tests.vuizvui.foo ];
  };
}

If a machine config enables the module foo (foo.enable = true) then the
"foo" test is also a constituent of the machine channel for the machine.

Signed-off-by: aszlig <aszlig@redmoonstudios.org>
Diffstat (limited to 'modules/profiles')
-rw-r--r--modules/profiles/common.nix22
1 files changed, 20 insertions, 2 deletions
diff --git a/modules/profiles/common.nix b/modules/profiles/common.nix
index 8621f6ae..b7fad147 100644
--- a/modules/profiles/common.nix
+++ b/modules/profiles/common.nix
@@ -44,7 +44,11 @@ with lib;
     };
   };
 
-  config = {
+  config = let
+    nixpkgs = import ../../nixpkgs-path.nix;
+    system = config.nixpkgs.system;
+
+  in {
     nixpkgs.config.packageOverrides = pkgs: {
       # XXX: REAAAALLLY UGLY hack to force the Headcounter Hydra to rebuild GHC
       # and all its packages and not use binary substitution.
@@ -74,7 +78,6 @@ with lib;
     in mkIf config.vuizvui.enableGlobalNixpkgsConfig (mkForce nixpkgsCfg);
 
     nix.nixPath = let
-      nixpkgs = import ../../nixpkgs-path.nix;
       rootChannelsPath = "/nix/var/nix/profiles/per-user/root/channels";
       channelPath = "${rootChannelsPath}/${config.vuizvui.channelName}";
       nixosConfig = "/etc/nixos/configuration.nix";
@@ -90,5 +93,20 @@ with lib;
         rootChannelsPath
       ] ++ optional config.vuizvui.enableGlobalNixpkgsConfig nixpkgsConfig;
     in mkIf config.vuizvui.modifyNixPath (mkOverride 90 nixPath);
+
+    _module.args.tests = {
+      nixos = let
+        upstreamTests = (import "${nixpkgs}/nixos/release.nix" {
+          inherit nixpkgs;
+        }).tests;
+        isTestOrSystems = attr: attr ? test || attr ? ${system};
+        cond = attr: !isTestOrSystems attr;
+        reduce = attr: if attr ? test then attr else attr.${system};
+      in mapAttrsRecursiveCond cond (path: reduce) upstreamTests;
+
+      vuizvui = import ../../tests {
+        inherit system;
+      };
+    };
   };
 }