about summary refs log tree commit diff
path: root/lib/call-machine.nix
diff options
context:
space:
mode:
authoraszlig <aszlig@redmoonstudios.org>2015-12-10 07:14:00 +0100
committeraszlig <aszlig@redmoonstudios.org>2015-12-10 07:14:00 +0100
commitbbafadb193a03c5d6757e2b3f409c96884571f01 (patch)
tree2a245d0df20fa42ae478b92d8f5edbfd73880f4a /lib/call-machine.nix
parentd9d59024954b5cc524285df3529a6d6b44263f94 (diff)
machines: Move callMachine function to lib/.
The function is gettin rather large, so it makes sense to move it into
another file so that the default.nix in machines/ won't be cluttered up
with all the implementation-specific details.

Signed-off-by: aszlig <aszlig@redmoonstudios.org>
Diffstat (limited to 'lib/call-machine.nix')
-rw-r--r--lib/call-machine.nix65
1 files changed, 65 insertions, 0 deletions
diff --git a/lib/call-machine.nix b/lib/call-machine.nix
new file mode 100644
index 00000000..3d524439
--- /dev/null
+++ b/lib/call-machine.nix
@@ -0,0 +1,65 @@
+system: path:
+
+let
+  nixpkgs = import ../nixpkgs-path.nix;
+
+in rec {
+  config = import path;
+  build = import "${nixpkgs}/nixos/lib/eval-config.nix" {
+    inherit system;
+    modules = [ config ] ++ import ../modules/module-list.nix;
+  };
+  iso = let
+    isoModule = "${nixpkgs}/nixos/modules/installer/cd-dvd/iso-image.nix";
+    patchedModule = (import nixpkgs {}).runCommand "iso-image.nix" {} ''
+      sed -e 's|../../../lib/|${nixpkgs}/nixos/lib/|g' \
+          -e 's/"nomodeset"//g' \
+          "${isoModule}" > "$out"
+    '';
+    wrapIso = { config, pkgs, lib, ... }@attrs: let
+      eval = (import patchedModule attrs);
+      evalcfg = eval.config or {};
+      bootcfg = evalcfg.boot or {};
+      fscfg = evalcfg.fileSystems or {};
+    in {
+      options = eval.options or {};
+      imports = eval.imports or [];
+      config = evalcfg // {
+        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 = [
+      use wrapIso
+      (
+        { lib, ... }: let
+          name = build.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";
+        }
+      )
+    ];
+  };
+  use = {
+    imports = [ config ] ++ import ../modules/module-list.nix;
+  };
+  vm = (import "${nixpkgs}/nixos" {
+    inherit system;
+    configuration = use;
+  }).vm;
+}