3
0
Fork 0
forked from mirrors/nixpkgs

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 }:
with stdenv.lib;
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 {
installedVM = import ./install {
installedVM = installer {
inherit isoFile productKey;
};
runInVM = img: attrs: import ./controller (attrs // {
runInVM = img: attrs: controller (attrs // {
inherit (installedVM) sshKey;
qemuArgs = attrs.qemuArgs or [] ++ [
"-boot order=c"
@ -34,9 +53,9 @@ in rec {
"echo '/cygdrive/${letter} ${target} none bind 0 0' >> /etc/fstab"
];
in runInVM "winvm.img" {
command = lib.concatStringsSep " && " ([
command = concatStringsSep " && " ([
"net config server /autodisconnect:-1"
] ++ lib.concatLists (lib.mapAttrsToList genDriveCmds drives));
] ++ concatLists (mapAttrsToList genDriveCmds drives));
suspendTo = "state.gz";
};
@ -55,7 +74,7 @@ in rec {
resumeAndRun = command: runInVM "${suspendedVM}/disk.img" {
resumeFrom = "${suspendedVM}/state.gz";
qemuArgs = lib.singleton "-snapshot";
qemuArgs = singleton "-snapshot";
inherit command;
};
}

View file

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

View file

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

View file

@ -1,5 +1,11 @@
pkgs:
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 = ''
source /tmp/xchg/saved-env 2> /dev/null || true
@ -18,11 +24,11 @@ in {
shell = "/bin/sh";
};
};
in lib.overrideDerivation drv (attrs: let
bootstrap = import ./bootstrap.nix attrs.windowsImage;
in pkgs.lib.overrideDerivation drv (attrs: let
bootstrap = bootstrapper attrs.windowsImage;
in {
requiredSystemFeatures = [ "kvm" ];
buildur = "${stdenv.shell}";
buildur = "${pkgs.stdenv.shell}";
args = ["-e" (bootstrap.resumeAndRun builder)];
windowsImage = bootstrap.suspendedVM;
origArgs = attrs.args;

View file

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

View file

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