2022-09-14 13:40:43 +00:00
|
|
|
{ binaryTarballs
|
|
|
|
, nixpkgsFor
|
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
installScripts = {
|
|
|
|
install-default = {
|
|
|
|
script = ''
|
|
|
|
tar -xf ./nix.tar.xz
|
|
|
|
mv ./nix-* nix
|
|
|
|
./nix/install --no-channel-add
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
install-force-no-daemon = {
|
|
|
|
script = ''
|
|
|
|
tar -xf ./nix.tar.xz
|
|
|
|
mv ./nix-* nix
|
2023-03-31 13:27:02 +00:00
|
|
|
./nix/install --no-daemon --no-channel-add
|
2022-09-14 13:40:43 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
install-force-daemon = {
|
|
|
|
script = ''
|
|
|
|
tar -xf ./nix.tar.xz
|
|
|
|
mv ./nix-* nix
|
2022-09-14 16:53:30 +00:00
|
|
|
./nix/install --daemon --no-channel-add
|
2022-09-14 13:40:43 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-03-23 20:47:27 +00:00
|
|
|
mockChannel = pkgs:
|
|
|
|
pkgs.runCommandNoCC "mock-channel" {} ''
|
|
|
|
mkdir nixexprs
|
2023-03-31 13:28:46 +00:00
|
|
|
mkdir -p $out/channel
|
2023-03-23 20:47:27 +00:00
|
|
|
echo -n 'someContent' > nixexprs/someFile
|
2023-03-31 13:28:46 +00:00
|
|
|
tar cvf - nixexprs | bzip2 > $out/channel/nixexprs.tar.bz2
|
2023-03-23 20:47:27 +00:00
|
|
|
'';
|
|
|
|
|
2022-09-14 16:53:30 +00:00
|
|
|
disableSELinux = "sudo setenforce 0";
|
|
|
|
|
2022-09-14 13:40:43 +00:00
|
|
|
images = {
|
|
|
|
|
2022-09-15 12:51:44 +00:00
|
|
|
/*
|
2022-09-14 13:40:43 +00:00
|
|
|
"ubuntu-14-04" = {
|
|
|
|
image = import <nix/fetchurl.nix> {
|
2022-09-26 14:57:06 +00:00
|
|
|
url = "https://app.vagrantup.com/ubuntu/boxes/trusty64/versions/20190514.0.0/providers/virtualbox.box";
|
2022-09-14 13:40:43 +00:00
|
|
|
hash = "sha256-iUUXyRY8iW7DGirb0zwGgf1fRbLA7wimTJKgP7l/OQ8=";
|
|
|
|
};
|
|
|
|
rootDisk = "box-disk1.vmdk";
|
|
|
|
system = "x86_64-linux";
|
|
|
|
};
|
2022-09-15 12:51:44 +00:00
|
|
|
*/
|
2022-09-14 13:40:43 +00:00
|
|
|
|
|
|
|
"ubuntu-16-04" = {
|
|
|
|
image = import <nix/fetchurl.nix> {
|
2022-09-26 14:57:06 +00:00
|
|
|
url = "https://app.vagrantup.com/generic/boxes/ubuntu1604/versions/4.1.12/providers/libvirt.box";
|
2022-09-15 11:28:03 +00:00
|
|
|
hash = "sha256-lO4oYQR2tCh5auxAYe6bPOgEqOgv3Y3GC1QM1tEEEU8=";
|
2022-09-14 13:40:43 +00:00
|
|
|
};
|
2022-09-15 11:28:03 +00:00
|
|
|
rootDisk = "box.img";
|
2022-09-14 13:40:43 +00:00
|
|
|
system = "x86_64-linux";
|
|
|
|
};
|
|
|
|
|
2022-09-15 11:19:46 +00:00
|
|
|
"ubuntu-22-04" = {
|
|
|
|
image = import <nix/fetchurl.nix> {
|
2022-09-26 14:57:06 +00:00
|
|
|
url = "https://app.vagrantup.com/generic/boxes/ubuntu2204/versions/4.1.12/providers/libvirt.box";
|
2022-09-15 11:19:46 +00:00
|
|
|
hash = "sha256-HNll0Qikw/xGIcogni5lz01vUv+R3o8xowP2EtqjuUQ=";
|
|
|
|
};
|
|
|
|
rootDisk = "box.img";
|
|
|
|
system = "x86_64-linux";
|
|
|
|
};
|
|
|
|
|
2022-09-14 16:40:16 +00:00
|
|
|
"fedora-36" = {
|
|
|
|
image = import <nix/fetchurl.nix> {
|
2022-09-26 14:57:06 +00:00
|
|
|
url = "https://app.vagrantup.com/generic/boxes/fedora36/versions/4.1.12/providers/libvirt.box";
|
2022-09-14 16:40:16 +00:00
|
|
|
hash = "sha256-rxPgnDnFkTDwvdqn2CV3ZUo3re9AdPtSZ9SvOHNvaks=";
|
|
|
|
};
|
|
|
|
rootDisk = "box.img";
|
|
|
|
system = "x86_64-linux";
|
2022-09-14 16:53:30 +00:00
|
|
|
postBoot = disableSELinux;
|
2022-09-14 16:40:16 +00:00
|
|
|
};
|
|
|
|
|
2022-09-15 12:51:10 +00:00
|
|
|
# Currently fails with 'error while loading shared libraries:
|
|
|
|
# libsodium.so.23: cannot stat shared object: Invalid argument'.
|
|
|
|
/*
|
|
|
|
"rhel-6" = {
|
|
|
|
image = import <nix/fetchurl.nix> {
|
2022-09-26 14:57:06 +00:00
|
|
|
url = "https://app.vagrantup.com/generic/boxes/rhel6/versions/4.1.12/providers/libvirt.box";
|
2022-09-15 12:51:10 +00:00
|
|
|
hash = "sha256-QwzbvRoRRGqUCQptM7X/InRWFSP2sqwRt2HaaO6zBGM=";
|
|
|
|
};
|
|
|
|
rootDisk = "box.img";
|
|
|
|
system = "x86_64-linux";
|
|
|
|
};
|
|
|
|
*/
|
|
|
|
|
|
|
|
"rhel-7" = {
|
|
|
|
image = import <nix/fetchurl.nix> {
|
2022-09-26 14:57:06 +00:00
|
|
|
url = "https://app.vagrantup.com/generic/boxes/rhel7/versions/4.1.12/providers/libvirt.box";
|
2022-09-15 12:51:10 +00:00
|
|
|
hash = "sha256-b4afnqKCO9oWXgYHb9DeQ2berSwOjS27rSd9TxXDc/U=";
|
|
|
|
};
|
|
|
|
rootDisk = "box.img";
|
|
|
|
system = "x86_64-linux";
|
|
|
|
};
|
|
|
|
|
|
|
|
"rhel-8" = {
|
|
|
|
image = import <nix/fetchurl.nix> {
|
2022-09-26 14:57:06 +00:00
|
|
|
url = "https://app.vagrantup.com/generic/boxes/rhel8/versions/4.1.12/providers/libvirt.box";
|
2022-09-15 12:51:10 +00:00
|
|
|
hash = "sha256-zFOPjSputy1dPgrQRixBXmlyN88cAKjJ21VvjSWUCUY=";
|
|
|
|
};
|
|
|
|
rootDisk = "box.img";
|
|
|
|
system = "x86_64-linux";
|
|
|
|
postBoot = disableSELinux;
|
|
|
|
};
|
|
|
|
|
2022-09-15 13:50:52 +00:00
|
|
|
"rhel-9" = {
|
|
|
|
image = import <nix/fetchurl.nix> {
|
2022-09-26 14:57:06 +00:00
|
|
|
url = "https://app.vagrantup.com/generic/boxes/rhel9/versions/4.1.12/providers/libvirt.box";
|
2022-09-15 13:50:52 +00:00
|
|
|
hash = "sha256-vL/FbB3kK1rcSaR627nWmScYGKGk4seSmAdq6N5diMg=";
|
|
|
|
};
|
|
|
|
rootDisk = "box.img";
|
|
|
|
system = "x86_64-linux";
|
|
|
|
postBoot = disableSELinux;
|
|
|
|
extraQemuOpts = "-cpu Westmere-v2";
|
|
|
|
};
|
|
|
|
|
2022-09-14 13:40:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
makeTest = imageName: testName:
|
|
|
|
let image = images.${imageName}; in
|
2022-03-02 02:40:18 +00:00
|
|
|
with nixpkgsFor.${image.system}.native;
|
2022-09-14 13:40:43 +00:00
|
|
|
runCommand
|
|
|
|
"installer-test-${imageName}-${testName}"
|
|
|
|
{ buildInputs = [ qemu_kvm openssh ];
|
|
|
|
image = image.image;
|
2022-09-14 16:53:30 +00:00
|
|
|
postBoot = image.postBoot or "";
|
2022-09-14 13:40:43 +00:00
|
|
|
installScript = installScripts.${testName}.script;
|
|
|
|
binaryTarball = binaryTarballs.${system};
|
|
|
|
}
|
|
|
|
''
|
2022-09-14 17:44:41 +00:00
|
|
|
shopt -s nullglob
|
|
|
|
|
2022-09-14 16:40:16 +00:00
|
|
|
echo "Unpacking Vagrant box $image..."
|
2022-09-14 13:40:43 +00:00
|
|
|
tar xvf $image
|
|
|
|
|
2022-09-14 16:40:16 +00:00
|
|
|
image_type=$(qemu-img info ${image.rootDisk} | sed 's/file format: \(.*\)/\1/; t; d')
|
|
|
|
|
|
|
|
qemu-img create -b ./${image.rootDisk} -F "$image_type" -f qcow2 ./disk.qcow2
|
2022-09-14 13:40:43 +00:00
|
|
|
|
2022-09-15 13:56:46 +00:00
|
|
|
extra_qemu_opts="${image.extraQemuOpts or ""}"
|
2022-09-14 17:44:41 +00:00
|
|
|
|
|
|
|
# Add the config disk, required by the Ubuntu images.
|
|
|
|
config_drive=$(echo *configdrive.vmdk || true)
|
|
|
|
if [[ -n $config_drive ]]; then
|
|
|
|
extra_qemu_opts+=" -drive id=disk2,file=$config_drive,if=virtio"
|
|
|
|
fi
|
|
|
|
|
2022-09-14 13:40:43 +00:00
|
|
|
echo "Starting qemu..."
|
|
|
|
qemu-kvm -m 4096 -nographic \
|
|
|
|
-drive id=disk1,file=./disk.qcow2,if=virtio \
|
2022-09-14 17:44:41 +00:00
|
|
|
-netdev user,id=net0,restrict=yes,hostfwd=tcp::20022-:22 -device virtio-net-pci,netdev=net0 \
|
|
|
|
$extra_qemu_opts &
|
2022-09-14 13:40:43 +00:00
|
|
|
qemu_pid=$!
|
|
|
|
trap "kill $qemu_pid" EXIT
|
|
|
|
|
|
|
|
if ! [ -e ./vagrant_insecure_key ]; then
|
|
|
|
cp ${./vagrant_insecure_key} vagrant_insecure_key
|
|
|
|
fi
|
|
|
|
|
|
|
|
chmod 0400 ./vagrant_insecure_key
|
|
|
|
|
2022-09-15 12:51:10 +00:00
|
|
|
ssh_opts="-o StrictHostKeyChecking=no -o HostKeyAlgorithms=+ssh-rsa -o PubkeyAcceptedKeyTypes=+ssh-rsa -i ./vagrant_insecure_key"
|
2022-09-14 13:40:43 +00:00
|
|
|
ssh="ssh -p 20022 -q $ssh_opts vagrant@localhost"
|
|
|
|
|
|
|
|
echo "Waiting for SSH..."
|
|
|
|
for ((i = 0; i < 120; i++)); do
|
|
|
|
echo "[ssh] Trying to connect..."
|
|
|
|
if $ssh -- true; then
|
|
|
|
echo "[ssh] Connected!"
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
if ! kill -0 $qemu_pid; then
|
|
|
|
echo "qemu died unexpectedly"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
|
2022-09-14 16:53:30 +00:00
|
|
|
if [[ -n $postBoot ]]; then
|
|
|
|
echo "Running post-boot commands..."
|
|
|
|
$ssh "set -ex; $postBoot"
|
|
|
|
fi
|
|
|
|
|
2022-09-14 13:40:43 +00:00
|
|
|
echo "Copying installer..."
|
|
|
|
scp -P 20022 $ssh_opts $binaryTarball/nix-*.tar.xz vagrant@localhost:nix.tar.xz
|
|
|
|
|
|
|
|
echo "Running installer..."
|
2022-09-14 16:53:30 +00:00
|
|
|
$ssh "set -eux; $installScript"
|
2022-09-14 13:40:43 +00:00
|
|
|
|
2023-03-23 20:47:27 +00:00
|
|
|
echo "Copying the mock channel"
|
2023-03-31 13:28:46 +00:00
|
|
|
# `scp -r` doesn't seem to work properly on some rhel instances, so let's
|
|
|
|
# use a plain tarpipe instead
|
|
|
|
tar -C ${mockChannel pkgs} -c channel | ssh -p 20022 $ssh_opts vagrant@localhost tar x -f-
|
2023-03-23 20:47:27 +00:00
|
|
|
|
2022-09-14 13:40:43 +00:00
|
|
|
echo "Testing Nix installation..."
|
2022-09-15 09:42:10 +00:00
|
|
|
$ssh <<EOF
|
2022-09-14 16:53:30 +00:00
|
|
|
set -ex
|
2022-09-14 17:44:41 +00:00
|
|
|
|
|
|
|
# FIXME: get rid of this; ideally ssh should just work.
|
|
|
|
source ~/.bash_profile || true
|
|
|
|
source ~/.bash_login || true
|
|
|
|
source ~/.profile || true
|
|
|
|
source /etc/bashrc || true
|
|
|
|
|
2022-09-14 16:53:30 +00:00
|
|
|
nix-env --version
|
2023-10-17 18:44:11 +00:00
|
|
|
nix --extra-experimental-features nix-command store info
|
2022-09-15 09:42:10 +00:00
|
|
|
|
|
|
|
out=\$(nix-build --no-substitute -E 'derivation { name = "foo"; system = "x86_64-linux"; builder = "/bin/sh"; args = ["-c" "echo foobar > \$out"]; }')
|
|
|
|
[[ \$(cat \$out) = foobar ]]
|
2023-03-23 20:47:27 +00:00
|
|
|
|
|
|
|
if pgrep nix-daemon; then
|
|
|
|
MAYBESUDO="sudo"
|
|
|
|
else
|
|
|
|
MAYBESUDO=""
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
$MAYBESUDO \$(which nix-channel) --add file://\$HOME/channel myChannel
|
|
|
|
$MAYBESUDO \$(which nix-channel) --update
|
|
|
|
[[ \$(nix-instantiate --eval --expr 'builtins.readFile <myChannel/someFile>') = '"someContent"' ]]
|
2022-09-15 09:42:10 +00:00
|
|
|
EOF
|
2022-09-14 13:40:43 +00:00
|
|
|
|
|
|
|
echo "Done!"
|
|
|
|
touch $out
|
|
|
|
'';
|
|
|
|
|
|
|
|
in
|
|
|
|
|
2022-09-15 11:15:26 +00:00
|
|
|
builtins.mapAttrs (imageName: image:
|
|
|
|
{ ${image.system} = builtins.mapAttrs (testName: test:
|
|
|
|
makeTest imageName testName
|
|
|
|
) installScripts;
|
|
|
|
}
|
|
|
|
) images
|