about summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/call-machine.nix65
-rw-r--r--lib/get-tests.nix22
2 files changed, 87 insertions, 0 deletions
diff --git a/lib/call-machine.nix b/lib/call-machine.nix
new file mode 100644
index 00000000..0844e4eb
--- /dev/null
+++ b/lib/call-machine.nix
@@ -0,0 +1,65 @@
+path: { system ? builtins.currentSystem }:
+
+let
+  nixpkgs = import ../nixpkgs-path.nix;
+
+  eval = import "${nixpkgs}/nixos/lib/eval-config.nix" {
+    inherit system;
+    modules = [ path ] ++ import ../modules/module-list.nix;
+  };
+
+  iso = let
+    isoModule = "${nixpkgs}/nixos/modules/installer/cd-dvd/iso-image.nix";
+    wrapIso = { config, pkgs, lib, ... }@attrs: let
+      isoEval = (import isoModule attrs);
+      isoEvalcfg = isoEval.config or {};
+      bootcfg = isoEvalcfg.boot or {};
+      fscfg = isoEvalcfg.fileSystems or {};
+    in {
+      options = isoEval.options or {};
+      imports = isoEval.imports or [];
+      config = isoEvalcfg // {
+        boot = bootcfg // lib.optionalAttrs (bootcfg ? loader) {
+          loader = lib.mkForce bootcfg.loader;
+        };
+        fileSystems = lib.mapAttrs (lib.const lib.mkForce) fscfg // {
+          "/boot" = lib.mkForce (fscfg."/boot" or {
+            device = "none";
+            fsType = "none";
+            options = "noauto";
+          });
+        };
+      };
+    };
+  in import "${nixpkgs}/nixos/lib/eval-config.nix" {
+    inherit system;
+    modules = [
+      config wrapIso
+      (
+        { lib, ... }: let
+          name = eval.config.networking.hostName;
+          upperName = lib.toUpper name;
+        in rec {
+          isoImage.isoName = "${name}.iso";
+          isoImage.volumeID = builtins.substring 0 11 "${upperName}_LIVE";
+          isoImage.makeEfiBootable = true;
+          isoImage.makeUsbBootable = true;
+          isoImage.appendToMenuLabel = " \"${name}\" Live System";
+        }
+      )
+    ];
+  };
+
+  config = {
+    imports = [ path ] ++ import ../modules/module-list.nix;
+  };
+
+  vm = (import "${nixpkgs}/nixos" {
+    inherit system;
+    configuration = config;
+  }).vm;
+
+in {
+  build = eval.config.system.build.toplevel;
+  inherit config eval iso vm;
+}
diff --git a/lib/get-tests.nix b/lib/get-tests.nix
new file mode 100644
index 00000000..08fc9475
--- /dev/null
+++ b/lib/get-tests.nix
@@ -0,0 +1,22 @@
+{ system ? builtins.currentSystem
+, nixpkgs ? import ../nixpkgs-path.nix
+, vuizvuiTests ? ../tests
+}:
+
+with import "${nixpkgs}/lib";
+
+{
+  nixos = let
+    upstreamTests = (import "${nixpkgs}/nixos/release.nix" {
+      inherit nixpkgs;
+    }).tests;
+    isTestOrJob = attr: (attr.type or null) == "derivation" || attr ? test;
+    isTestOrSystems = attr: isTestOrJob attr || attr ? ${system};
+    cond = attr: !isTestOrSystems attr;
+    reduce = attr: if isTestOrJob attr then attr else attr.${system};
+  in mapAttrsRecursiveCond cond (path: reduce) upstreamTests;
+
+  vuizvui = import vuizvuiTests {
+    inherit system;
+  };
+}