2009-12-16 00:26:52 +01:00
|
|
|
{ nixos ? ../..
|
|
|
|
, nixpkgs ? ../../../nixpkgs
|
|
|
|
, services ? ../../../nixos/services
|
2009-12-11 01:51:13 +01:00
|
|
|
, system ? builtins.currentSystem
|
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
test nixos installation automatically using a build job (unfinished)
|
|
|
|
|
|
|
|
run this test this way:
|
|
|
|
nix-build --no-out-link --show-trace tests/test-nixos-install-from-cd.nix
|
|
|
|
|
|
|
|
--no-out-link is important because creating ./result will cause rebuilding of
|
|
|
|
the iso as the nixos repository is included in the iso.
|
|
|
|
|
|
|
|
To prevent this make these paths point to another location:
|
|
|
|
nixosTarball = makeTarball "nixos.tar.bz2" (cleanSource ../../..);
|
|
|
|
nixpkgsTarball = makeTarball "nixpkgs.tar.bz2" (cleanSource pkgs.path);
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2009-12-16 00:26:52 +01:00
|
|
|
configuration_iso = ./configuration-iso.nix;
|
|
|
|
configuration_install = ./configuration.nix;
|
2009-12-11 01:51:13 +01:00
|
|
|
|
2009-12-16 00:26:52 +01:00
|
|
|
release = (import ../../release.nix) { inherit nixpkgs; };
|
2009-12-11 01:51:13 +01:00
|
|
|
|
2009-12-16 00:26:52 +01:00
|
|
|
isoFile = (
|
|
|
|
release.makeIso
|
|
|
|
{
|
|
|
|
module = configuration_iso;
|
|
|
|
description = "minimal-testing-only";
|
|
|
|
maintainers = ["MarcWeber"];
|
|
|
|
}
|
|
|
|
{ inherit system; }
|
|
|
|
).iso;
|
2009-12-11 01:51:13 +01:00
|
|
|
|
2009-12-16 00:26:52 +01:00
|
|
|
eval = import ../../lib/eval-config.nix {
|
2009-12-11 01:51:13 +01:00
|
|
|
inherit system nixpkgs;
|
2009-12-16 00:26:52 +01:00
|
|
|
modules = [ configuration_install ];
|
2009-12-11 01:51:13 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
inherit (eval) pkgs config;
|
|
|
|
|
|
|
|
inherit (pkgs) qemu_kvm;
|
|
|
|
|
|
|
|
# prebuild system which will be installed for two reasons:
|
|
|
|
# build derivations are in store and can be reused
|
|
|
|
# the iso is only build when this suceeds (?)
|
|
|
|
systemDerivation = builtins.addErrorContext "while building system" config.system.build.toplevel;
|
|
|
|
|
2009-12-15 07:37:32 +01:00
|
|
|
# TODO test both: copyKernels = true and false. true doesn't work ?
|
|
|
|
|
2009-12-16 05:55:35 +01:00
|
|
|
debug = if false then ''
|
|
|
|
export DISPLAY=localhost:0.0
|
|
|
|
''
|
|
|
|
else
|
|
|
|
# That's crazy: You see nothing but your computer is doing a *lot* of work :-)
|
|
|
|
''
|
|
|
|
KVM_OPTIONS="-nographic"
|
|
|
|
'';
|
|
|
|
|
2009-12-11 01:51:13 +01:00
|
|
|
in
|
|
|
|
|
|
|
|
rec {
|
|
|
|
|
|
|
|
test =
|
|
|
|
# FIXME: support i686 as well
|
|
|
|
# FIXME: X shouldn't be required
|
|
|
|
# Is there a way to use kvm when not running as root?
|
|
|
|
# Would using uml provide any advantages?
|
2009-12-16 00:26:52 +01:00
|
|
|
|
2009-12-16 05:55:35 +01:00
|
|
|
|
|
|
|
# TODO: Run installation withoun networking support ?
|
|
|
|
# This can be done by using either firewalls or building system by .drv path?
|
2009-12-11 01:51:13 +01:00
|
|
|
pkgs.runCommand "nixos-installation-test" { inherit systemDerivation; } ''
|
|
|
|
|
2009-12-16 05:55:35 +01:00
|
|
|
set -e
|
|
|
|
|
2009-12-16 00:26:52 +01:00
|
|
|
INFO(){ echo "INFO: " $@; }
|
2009-12-15 07:37:32 +01:00
|
|
|
|
|
|
|
die(){ echo $@; exit 1; }
|
|
|
|
|
|
|
|
if ${pkgs.procps}/bin/ps aux | grep -v grep | grep sbin/nmbd ; then
|
|
|
|
die "!! aborting: -smb won't work when host is running samba!"
|
|
|
|
fi
|
|
|
|
|
|
|
|
[ -e /dev/kvm ] || die "modprobe a kvm-* module /dev/kvm not present. You want it for speed reasons!"
|
|
|
|
|
2009-12-11 01:51:13 +01:00
|
|
|
for path in ${pkgs.socat} ${pkgs.openssh} ${qemu_kvm}; do
|
|
|
|
PATH=$path/bin:$PATH
|
|
|
|
done
|
|
|
|
|
2009-12-15 07:37:32 +01:00
|
|
|
# without samba -smb doesn't work
|
|
|
|
PATH=${pkgs.samba}/sbin:$PATH
|
2009-12-11 01:51:13 +01:00
|
|
|
|
|
|
|
# install the system
|
2009-12-16 05:55:35 +01:00
|
|
|
${debug}
|
2009-12-11 01:51:13 +01:00
|
|
|
|
2009-12-15 07:37:32 +01:00
|
|
|
SOCKET_NAME=65535.socket
|
|
|
|
|
|
|
|
# creating shell script for debugging purposes
|
2009-12-11 01:51:13 +01:00
|
|
|
cat >> run-kvm.sh << EOF
|
2009-12-15 07:37:32 +01:00
|
|
|
#!/bin/sh -e
|
2009-12-16 00:26:57 +01:00
|
|
|
|
2009-12-16 00:26:52 +01:00
|
|
|
exec qemu-system-x86_64 -m 512 \
|
2009-12-11 01:51:13 +01:00
|
|
|
-no-kvm-irqchip \
|
2009-12-15 07:37:32 +01:00
|
|
|
-net nic,model=virtio -net user -smb /nix \
|
2009-12-11 01:51:13 +01:00
|
|
|
-hda image \
|
2009-12-15 07:37:32 +01:00
|
|
|
-redir tcp:''${SOCKET_NAME/.socket/}::22 \
|
2009-12-16 05:55:35 +01:00
|
|
|
$KVM_OPTIONS \
|
2009-12-11 01:51:13 +01:00
|
|
|
"\$@"
|
|
|
|
EOF
|
|
|
|
chmod +x run-kvm.sh
|
|
|
|
|
2009-12-15 07:37:32 +01:00
|
|
|
RUN_KVM(){
|
|
|
|
INFO "launching qemu-kvm in a background process"
|
|
|
|
{ ./run-kvm.sh "$@" \
|
|
|
|
|| { echo "starting kvm failed, exiting" 1>&2; kill -9 $$; }
|
|
|
|
} &
|
|
|
|
}
|
2009-12-11 01:51:13 +01:00
|
|
|
|
|
|
|
waitTill(){
|
|
|
|
echo $1
|
2009-12-16 05:55:35 +01:00
|
|
|
eval "while ! $2; do sleep 1; done"
|
2009-12-11 01:51:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
SSH(){
|
2009-12-16 05:55:35 +01:00
|
|
|
# if timout occurs ssh command will be retried.
|
|
|
|
# Waiting forever doesn't seem to work because
|
|
|
|
# there seems to be a race condition where
|
|
|
|
# SSH connects but sshd doesn't notice it.
|
|
|
|
# Thus fail and retry
|
2009-12-15 07:37:32 +01:00
|
|
|
ssh -o UserKnownHostsFile=/dev/null \
|
2009-12-11 01:51:13 +01:00
|
|
|
-o StrictHostKeyChecking=no \
|
|
|
|
-o ProxyCommand="socat stdio ./$SOCKET_NAME" \
|
2009-12-16 05:55:35 +01:00
|
|
|
-o ConnectTimeout=1 \
|
2009-12-11 01:51:13 +01:00
|
|
|
root@127.0.0.1 \
|
|
|
|
"$@";
|
|
|
|
}
|
2009-12-15 07:37:32 +01:00
|
|
|
SSH_STDIN_E(){ { echo "set -e;"; cat; } | SSH; }
|
|
|
|
|
|
|
|
SHUTDOWN_VM(){
|
|
|
|
SSH 'shutdown -h now';
|
|
|
|
INFO "waiting for kvm to shutown"
|
|
|
|
wait
|
|
|
|
}
|
2009-12-11 01:51:13 +01:00
|
|
|
|
|
|
|
# wait for socket
|
|
|
|
|
2009-12-15 07:37:32 +01:00
|
|
|
waitForSSHD(){
|
|
|
|
waitTill "waiting for sshd job" "SSH 'echo Hello > /dev/tty1' &> /dev/null"
|
|
|
|
}
|
|
|
|
|
2009-12-16 05:55:35 +01:00
|
|
|
nixBuildTest(){
|
|
|
|
INFO "verifying that nix-env -i works"
|
2009-12-15 07:37:32 +01:00
|
|
|
|
2009-12-16 05:55:35 +01:00
|
|
|
SSH_STDIN_E << EOF
|
|
|
|
|
|
|
|
cat >> test.nix << EOF_TEST
|
|
|
|
let pkgs = import /etc/nixos/nixpkgs/pkgs/top-level/all-packages.nix {};
|
|
|
|
in pkgs.stdenv.mkDerivation {
|
|
|
|
name = "test";
|
|
|
|
phases = "create_out";
|
|
|
|
create_out = "mkdir -p \\\$out/ok";
|
|
|
|
}
|
|
|
|
EOF_TEST
|
|
|
|
|
|
|
|
nix-build test.nix
|
|
|
|
[ -e result/ok ]
|
|
|
|
EOF
|
|
|
|
|
|
|
|
}
|
2009-12-15 07:37:32 +01:00
|
|
|
|
|
|
|
### test installting NixOS: install system then reboot
|
|
|
|
|
|
|
|
|
|
|
|
INFO "creating image file"
|
2009-12-16 00:26:52 +01:00
|
|
|
# 2GB = data; 1GB=swap
|
|
|
|
# Maybe using 1GB swap is much. But qcow2 doesn't fill holes so it only
|
|
|
|
# used when required (?)
|
|
|
|
qemu-img create -f qcow2 image 3G
|
2009-12-15 07:37:32 +01:00
|
|
|
|
|
|
|
RUN_KVM -boot d -cdrom $(echo ${isoFile}/iso/*.iso)
|
|
|
|
|
|
|
|
waitForSSHD
|
2009-12-11 01:51:13 +01:00
|
|
|
|
2009-12-16 05:55:35 +01:00
|
|
|
nixBuildTest
|
|
|
|
|
2009-12-11 01:51:13 +01:00
|
|
|
# INSTALLATION
|
2009-12-15 07:37:32 +01:00
|
|
|
INFO "creating filesystem .."
|
|
|
|
SSH_STDIN_E << EOF
|
|
|
|
parted /dev/sda mklabel msdos
|
|
|
|
parted /dev/sda mkpart primary 0 2G
|
2009-12-16 00:26:52 +01:00
|
|
|
parted /dev/sda mkpart primary 1G 3G
|
|
|
|
waitFor(){
|
|
|
|
while [ ! -e "\$1" ]; do
|
|
|
|
echo "waiting for \$1 to appear"; sleep 1;
|
|
|
|
done
|
|
|
|
}
|
|
|
|
waitFor /dev/sda2
|
|
|
|
mkswap /dev/sda2
|
|
|
|
swapon /dev/sda2
|
|
|
|
|
|
|
|
waitFor /dev/sda1
|
2009-12-15 07:37:32 +01:00
|
|
|
mkfs.ext3 /dev/sda1
|
2009-12-16 00:26:52 +01:00
|
|
|
|
2009-12-15 07:37:32 +01:00
|
|
|
mount /dev/sda1 /mnt
|
|
|
|
mkdir -p /mnt/nix-on-host
|
|
|
|
mount //10.0.2.4/qemu -oguest,username=nobody,noperm -tcifs /mnt/nix-on-host
|
|
|
|
EOF
|
2009-12-11 01:51:13 +01:00
|
|
|
|
|
|
|
|
2009-12-15 07:37:32 +01:00
|
|
|
SSH_STDIN_E << EOF
|
|
|
|
# simple nixos-hardware-scan syntax check:
|
|
|
|
nixos-hardware-scan > /tmp/test.nix
|
|
|
|
EOF
|
|
|
|
|
2009-12-16 00:26:52 +01:00
|
|
|
INFO "copying sources and Nix, starting installation"
|
2009-12-15 07:37:32 +01:00
|
|
|
SSH_STDIN_E << EOF
|
|
|
|
|
|
|
|
nixos-prepare-install
|
|
|
|
|
|
|
|
# has the generated configuration.nix file syntax errors?
|
|
|
|
nix-instantiate --eval-only /tmp/test.nix
|
|
|
|
|
2009-12-16 05:55:35 +01:00
|
|
|
mkdir /mnt/root
|
|
|
|
echo 'export NIXOS_CONFIG=/etc/nixos/nixos/tests/test-nixos-install-from-cd/configuration.nix' >> /mnt/root/.bashrc
|
|
|
|
. /mnt/root/.bashrc
|
2009-12-15 07:37:32 +01:00
|
|
|
export NIX_OTHER_STORES=/nix-on-host
|
2009-12-16 00:26:52 +01:00
|
|
|
|
|
|
|
run-in-chroot "/nix/store/nixos-bootstrap --install --no-pull"
|
2009-12-15 07:37:32 +01:00
|
|
|
#nixos-install
|
|
|
|
EOF
|
|
|
|
|
|
|
|
SHUTDOWN_VM
|
2009-12-11 01:51:13 +01:00
|
|
|
|
2009-12-15 07:37:32 +01:00
|
|
|
INFO "booting installed system"
|
|
|
|
RUN_KVM -boot c
|
|
|
|
waitForSSHD
|
2009-12-16 00:26:57 +01:00
|
|
|
|
2009-12-16 05:55:35 +01:00
|
|
|
nixBuildTest
|
2009-12-16 00:26:57 +01:00
|
|
|
|
2009-12-15 07:37:32 +01:00
|
|
|
SHUTDOWN_VM
|
2009-12-11 01:51:13 +01:00
|
|
|
|
2009-12-15 07:37:32 +01:00
|
|
|
echo "$(date) success" > $out
|
2009-12-11 01:51:13 +01:00
|
|
|
'';
|
|
|
|
}
|