From bbafadb193a03c5d6757e2b3f409c96884571f01 Mon Sep 17 00:00:00 2001 From: aszlig Date: Thu, 10 Dec 2015 07:14:00 +0100 Subject: 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 --- lib/call-machine.nix | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 lib/call-machine.nix (limited to 'lib/call-machine.nix') 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; +} -- cgit 1.4.1