vm/windows: Make list of dependencies explicit.

So far, the VMs have always been using the native architecture, because
it was reimporting <nixpkgs> several times. Now, we propagate a list of
packages down to all sub-imports, which not only makes clearer which
dependencies a part actually has, but also will make it easier in case
we want to refactor those parts to use callPackage.

Signed-off-by: aszlig <aszlig@redmoonstudios.org>
This commit is contained in:
aszlig 2014-02-26 05:43:34 +01:00
parent d8e66722a3
commit 623f1940c0
No known key found for this signature in database
GPG Key ID: D0EBD0EC8C2DC961
6 changed files with 70 additions and 36 deletions

View File

@ -1,13 +1,32 @@
{ stdenv, fetchurl, vmTools, writeScript, writeText, runCommand, makeInitrd
, python, perl, coreutils, dosfstools, gzip, mtools, netcat, openssh, qemu
, samba, socat, vde2, cdrkit, pathsFromGraph
}:
{ isoFile, productKey }: { isoFile, productKey }:
with stdenv.lib;
let let
inherit (import <nixpkgs> {}) lib stdenv qemu; controller = import ./controller {
inherit stdenv writeScript vmTools makeInitrd;
inherit samba vde2 openssh socat netcat coreutils gzip;
};
mkCygwinImage = import ./cygwin-iso {
inherit stdenv fetchurl runCommand python perl cdrkit pathsFromGraph;
};
installer = import ./install {
inherit controller mkCygwinImage;
inherit stdenv runCommand openssh qemu writeText dosfstools mtools;
};
in rec { in rec {
installedVM = import ./install { installedVM = installer {
inherit isoFile productKey; inherit isoFile productKey;
}; };
runInVM = img: attrs: import ./controller (attrs // { runInVM = img: attrs: controller (attrs // {
inherit (installedVM) sshKey; inherit (installedVM) sshKey;
qemuArgs = attrs.qemuArgs or [] ++ [ qemuArgs = attrs.qemuArgs or [] ++ [
"-boot order=c" "-boot order=c"
@ -34,9 +53,9 @@ in rec {
"echo '/cygdrive/${letter} ${target} none bind 0 0' >> /etc/fstab" "echo '/cygdrive/${letter} ${target} none bind 0 0' >> /etc/fstab"
]; ];
in runInVM "winvm.img" { in runInVM "winvm.img" {
command = lib.concatStringsSep " && " ([ command = concatStringsSep " && " ([
"net config server /autodisconnect:-1" "net config server /autodisconnect:-1"
] ++ lib.concatLists (lib.mapAttrsToList genDriveCmds drives)); ] ++ concatLists (mapAttrsToList genDriveCmds drives));
suspendTo = "state.gz"; suspendTo = "state.gz";
}; };
@ -55,7 +74,7 @@ in rec {
resumeAndRun = command: runInVM "${suspendedVM}/disk.img" { resumeAndRun = command: runInVM "${suspendedVM}/disk.img" {
resumeFrom = "${suspendedVM}/state.gz"; resumeFrom = "${suspendedVM}/state.gz";
qemuArgs = lib.singleton "-snapshot"; qemuArgs = singleton "-snapshot";
inherit command; inherit command;
}; };
} }

View File

@ -1,3 +1,7 @@
{ stdenv, writeScript, vmTools, makeInitrd
, samba, vde2, openssh, socat, netcat, coreutils, gzip
}:
{ sshKey { sshKey
, qemuArgs ? [] , qemuArgs ? []
, command ? "sync" , command ? "sync"
@ -6,10 +10,9 @@
, installMode ? false , installMode ? false
}: }:
let with stdenv.lib;
inherit (import <nixpkgs> {}) lib stdenv writeScript vmTools makeInitrd;
inherit (import <nixpkgs> {}) samba vde2 openssh socat netcat coreutils gzip;
let
preInitScript = writeScript "preinit.sh" '' preInitScript = writeScript "preinit.sh" ''
#!${vmTools.initrdUtils}/bin/ash -e #!${vmTools.initrdUtils}/bin/ash -e
export PATH=${vmTools.initrdUtils}/bin export PATH=${vmTools.initrdUtils}/bin
@ -62,13 +65,13 @@ let
''; '';
initrd = makeInitrd { initrd = makeInitrd {
contents = lib.singleton { contents = singleton {
object = preInitScript; object = preInitScript;
symlink = "/init"; symlink = "/init";
}; };
}; };
shellEscape = x: "'${lib.replaceChars ["'"] [("'\\'" + "'")] x}'"; shellEscape = x: "'${replaceChars ["'"] [("'\\'" + "'")] x}'";
loopForever = "while :; do ${coreutils}/bin/sleep 1; done"; loopForever = "while :; do ${coreutils}/bin/sleep 1; done";
@ -128,12 +131,12 @@ let
-i /ssh.key \ -i /ssh.key \
-l Administrator \ -l Administrator \
192.168.0.1 -- ${shellEscape command} 192.168.0.1 -- ${shellEscape command}
'') + lib.optionalString (suspendTo != null) '' '') + optionalString (suspendTo != null) ''
${coreutils}/bin/touch /xchg/suspend_now ${coreutils}/bin/touch /xchg/suspend_now
${loopForever} ${loopForever}
''); '');
kernelAppend = lib.concatStringsSep " " [ kernelAppend = concatStringsSep " " [
"panic=1" "panic=1"
"loglevel=4" "loglevel=4"
"console=tty1" "console=tty1"
@ -141,7 +144,7 @@ let
"command=${initScript}" "command=${initScript}"
]; ];
controllerQemuArgs = lib.concatStringsSep " " (maybeKvm64 ++ [ controllerQemuArgs = concatStringsSep " " (maybeKvm64 ++ [
"-nographic" "-nographic"
"-no-reboot" "-no-reboot"
"-virtfs local,path=/nix/store,security_model=none,mount_tag=store" "-virtfs local,path=/nix/store,security_model=none,mount_tag=store"
@ -153,20 +156,20 @@ let
"-net vde,vlan=0,sock=$QEMU_VDE_SOCKET" "-net vde,vlan=0,sock=$QEMU_VDE_SOCKET"
]); ]);
maybeKvm64 = lib.optional (stdenv.system == "x86_64-linux") "-cpu kvm64"; maybeKvm64 = optional (stdenv.system == "x86_64-linux") "-cpu kvm64";
cygwinQemuArgs = lib.concatStringsSep " " (maybeKvm64 ++ [ cygwinQemuArgs = concatStringsSep " " (maybeKvm64 ++ [
"-monitor unix:$MONITOR_SOCKET,server,nowait" "-monitor unix:$MONITOR_SOCKET,server,nowait"
"-nographic" "-nographic"
"-net nic,vlan=0,macaddr=52:54:00:12:01:01" "-net nic,vlan=0,macaddr=52:54:00:12:01:01"
"-net vde,vlan=0,sock=$QEMU_VDE_SOCKET" "-net vde,vlan=0,sock=$QEMU_VDE_SOCKET"
"-rtc base=2010-01-01,clock=vm" "-rtc base=2010-01-01,clock=vm"
] ++ qemuArgs ++ lib.optionals (resumeFrom != null) [ ] ++ qemuArgs ++ optionals (resumeFrom != null) [
"-incoming 'exec: ${gzip}/bin/gzip -c -d \"${resumeFrom}\"'" "-incoming 'exec: ${gzip}/bin/gzip -c -d \"${resumeFrom}\"'"
]); ]);
modulesClosure = lib.overrideDerivation vmTools.modulesClosure (o: { modulesClosure = overrideDerivation vmTools.modulesClosure (o: {
rootModules = o.rootModules ++ lib.singleton "virtio_net"; rootModules = o.rootModules ++ singleton "virtio_net";
}); });
preVM = '' preVM = ''
@ -183,7 +186,7 @@ let
UNIX-CONNECT:$QEMU_VDE_SOCKET/ctl,retry=20 UNIX-CONNECT:$QEMU_VDE_SOCKET/ctl,retry=20
''; '';
bgBoth = lib.optionalString (suspendTo != null) " &"; bgBoth = optionalString (suspendTo != null) " &";
vmExec = if installMode then '' vmExec = if installMode then ''
${vmTools.qemuProg} ${controllerQemuArgs} & ${vmTools.qemuProg} ${controllerQemuArgs} &

View File

@ -1,11 +1,11 @@
{ stdenv, fetchurl, runCommand, python, perl, cdrkit, pathsFromGraph }:
{ packages ? [] { packages ? []
, mirror ? "http://ftp.gwdg.de/pub/linux/sources.redhat.com/cygwin" , mirror ? "http://ftp.gwdg.de/pub/linux/sources.redhat.com/cygwin"
, extraContents ? [] , extraContents ? []
}: }:
let let
inherit (import <nixpkgs> {}) fetchurl runCommand python;
cygPkgList = fetchurl { cygPkgList = fetchurl {
url = "${mirror}/x86_64/setup.ini"; url = "${mirror}/x86_64/setup.ini";
sha256 = "19vfm7zr8kcp1algmggk8vsilkccycx22mdf0ynfl6lcmp6dkfsz"; sha256 = "19vfm7zr8kcp1algmggk8vsilkccycx22mdf0ynfl6lcmp6dkfsz";

View File

@ -1,5 +1,11 @@
pkgs:
let let
inherit (import <nixpkgs> {}) lib stdenv; bootstrapper = import ./bootstrap.nix {
inherit (pkgs) stdenv vmTools writeScript writeText runCommand makeInitrd;
inherit (pkgs) coreutils dosfstools gzip mtools netcat openssh qemu samba;
inherit (pkgs) socat vde2 fetchurl python perl cdrkit pathsFromGraph;
};
builder = '' builder = ''
source /tmp/xchg/saved-env 2> /dev/null || true source /tmp/xchg/saved-env 2> /dev/null || true
@ -18,11 +24,11 @@ in {
shell = "/bin/sh"; shell = "/bin/sh";
}; };
}; };
in lib.overrideDerivation drv (attrs: let in pkgs.lib.overrideDerivation drv (attrs: let
bootstrap = import ./bootstrap.nix attrs.windowsImage; bootstrap = bootstrapper attrs.windowsImage;
in { in {
requiredSystemFeatures = [ "kvm" ]; requiredSystemFeatures = [ "kvm" ];
buildur = "${stdenv.shell}"; buildur = "${pkgs.stdenv.shell}";
args = ["-e" (bootstrap.resumeAndRun builder)]; args = ["-e" (bootstrap.resumeAndRun builder)];
windowsImage = bootstrap.suspendedVM; windowsImage = bootstrap.suspendedVM;
origArgs = attrs.args; origArgs = attrs.args;

View File

@ -1,10 +1,12 @@
{ stdenv, runCommand, openssh, qemu, controller, mkCygwinImage
, writeText, dosfstools, mtools
}:
{ isoFile { isoFile
, productKey , productKey
}: }:
let let
inherit (import <nixpkgs> {}) lib stdenv runCommand openssh qemu;
bootstrapAfterLogin = runCommand "bootstrap.sh" {} '' bootstrapAfterLogin = runCommand "bootstrap.sh" {} ''
cat > "$out" <<EOF cat > "$out" <<EOF
mkdir -p ~/.ssh mkdir -p ~/.ssh
@ -29,20 +31,24 @@ let
packages = [ "openssh" "shutdown" ]; packages = [ "openssh" "shutdown" ];
instfloppy = import ./unattended-image.nix { floppyCreator = import ./unattended-image.nix {
inherit stdenv writeText dosfstools mtools;
};
instfloppy = floppyCreator {
cygwinPackages = packages; cygwinPackages = packages;
inherit productKey; inherit productKey;
}; };
cygiso = import ../cygwin-iso { cygiso = mkCygwinImage {
inherit packages; inherit packages;
extraContents = lib.singleton { extraContents = stdenv.lib.singleton {
source = bootstrapAfterLogin; source = bootstrapAfterLogin;
target = "bootstrap.sh"; target = "bootstrap.sh";
}; };
}; };
installController = import ../controller { installController = controller {
inherit sshKey; inherit sshKey;
installMode = true; installMode = true;
qemuArgs = [ qemuArgs = [

View File

@ -1,3 +1,5 @@
{ stdenv, writeText, dosfstools, mtools }:
{ productKey { productKey
, shExecAfterwards ? "E:\\bootstrap.sh" , shExecAfterwards ? "E:\\bootstrap.sh"
, cygwinRoot ? "C:\\cygwin" , cygwinRoot ? "C:\\cygwin"
@ -7,8 +9,6 @@
}: }:
let let
inherit (import <nixpkgs> {}) lib stdenv writeText dosfstools mtools;
afterSetup = [ afterSetup = [
cygwinSetup cygwinSetup
"-L -n -q" "-L -n -q"
@ -80,7 +80,7 @@ let
; Turn off all components ; Turn off all components
[Components] [Components]
${lib.concatMapStrings (comp: "${comp} = Off\n") [ ${stdenv.lib.concatMapStrings (comp: "${comp} = Off\n") [
"AccessOpt" "Appsrv_console" "Aspnet" "BitsServerExtensionsISAPI" "AccessOpt" "Appsrv_console" "Aspnet" "BitsServerExtensionsISAPI"
"BitsServerExtensionsManager" "Calc" "Certsrv" "Certsrv_client" "BitsServerExtensionsManager" "Calc" "Certsrv" "Certsrv_client"
"Certsrv_server" "Charmap" "Chat" "Clipbook" "Cluster" "Complusnetwork" "Certsrv_server" "Charmap" "Chat" "Clipbook" "Cluster" "Complusnetwork"
@ -107,7 +107,7 @@ let
Mode = 0 Mode = 0
[SetupParams] [SetupParams]
UserExecute = "${lib.concatStringsSep " " afterSetup}" UserExecute = "${stdenv.lib.concatStringsSep " " afterSetup}"
[GuiRunOnce] [GuiRunOnce]
Command0 = "${cygwinRoot}\bin\bash -l ${shExecAfterwards}" Command0 = "${cygwinRoot}\bin\bash -l ${shExecAfterwards}"