diff --git a/docs/dev/README.rst b/docs/dev/README.rst index 0c688021dfa0aef8d4e10a6c6501dd5a6a5b6d23..c518c69bfc30025dbe297d3e62b12c5fe8ff9f64 100644 --- a/docs/dev/README.rst +++ b/docs/dev/README.rst @@ -24,7 +24,6 @@ The system tests are run using this command:: $ nix-build --attr system-tests -The system tests boot QEMU VMs which prevents them from running on CI at this time. The build requires > 10 GB of disk space, and the VMs might be timing out on slow or busy machines. If you run into timeouts, diff --git a/morph/grid/local/README.rst b/morph/grid/local/README.rst index 48f395cb82fc272481a61f0d1ab425ffbd20cd02..75bc685852a65673bbb1e572249d34eb5b482db4 100644 --- a/morph/grid/local/README.rst +++ b/morph/grid/local/README.rst @@ -8,14 +8,18 @@ Issues with networking that looked like guest misconfigurations vanished after c This requires `NixOS <https://nixos.org/>`_. Nix without the OS will not work. + Use the local development environment ````````````````````````````````````` -0. Add VirtualBox to your NixOs system configuration at ``/etc/nixos/configuration.nix``:: +0. Add to your NixOS system configuration at ``/etc/nixos/configuration.nix`` (and rebuild):: - virtualisation.virtualbox.host.enable = true; - # Save bytes and build time, optional but recommended: - virtualisation.virtualbox.host.headless = true; + # Enable libvirt - likely incompatible with virtualisation.virtualbox! + virtualisation.libvirtd.enable = true; + # Required for LibVirt + security.polkit.enable = true; + # Enable HW acceleration if (nested virtualisation is) available + #boot.kernelModules = [ "kvm-amd" "kvm-intel" ]; 1. Enter the morph local grid directory:: @@ -27,19 +31,27 @@ Use the local development environment 3. Build and start the VMs:: - VAGRANT_DEFAULT_PROVIDER=virtualbox vagrant up + vagrant up --provider=libvirt + + Optionally, to switch from QEMU to KVM virtualization, edit the virtual machine definition of all the machines and replace the "qemu" on the first line with "kvm":: + + sudo virsh list + sudo virsh edit <machine id> (once for every machine) + vagrant halt + vagrant up + 4. Then, add the Vagrant SSH configuration to your user's ``~/.ssh/config`` file:: install -d ~/.ssh ; vagrant ssh-config >> ~/.ssh/config - Latest Morph honors the ``SSH_CONFIG_FILE`` environment variable (`since 3f90aa88 (March 2020, v 1.5.0) <https://github.com/DBCDK/morph/commit/3f90aa885fac1c29fce9242452fa7c0c505744ef#diff-d155ad793bd62e6ea4c44ba985049ecb13a4f4f32f799791b2bce695a16c0101>`_), so in the future this should get a bit more convenient. + Latest Morph honors the ``SSH_CONFIG_FILE`` environment variable (`since 3f90aa88 (March 2020, v 1.5.0) <https://github.com/DBCDK/morph/commit/3f90aa885fac1c29fce9242452fa7c0c505744ef#diff-d155ad793bd62e6ea4c44ba985049ecb13a4f4f32f799791b2bce695a16c0101>`_), so in the future this should get a bit more convenient. -6. Create a ``public-keys/users.nix`` file with your SSH key (see ``public-keys/users.nix.example`` for the format) so you'll be able to log in after deploying the new configuration:: +5. Create a ``public-keys/users.nix`` file with your SSH key (see ``public-keys/users.nix.example`` for the format) so you'll be able to log in after deploying the new configuration:: $EDITOR public-keys/users.nix -7. Then, build and deploy our software to the Vagrant VMs:: +6. Then, build and deploy our software to the Vagrant VMs:: morph build grid.nix morph push grid.nix @@ -48,4 +60,4 @@ Use the local development environment vagrant up morph upload-secrets grid.nix - You should now be able to log in with the users and keys you set in your ``users.nix`` file. +You should now be able to log in with the users and keys you set in your ``users.nix`` file. diff --git a/morph/grid/local/Vagrantfile b/morph/grid/local/Vagrantfile index 96946e530b313004357f02c3c0737d33f689a33c..911dd3f7570834060ed0879b738bb3ea2a61420d 100644 --- a/morph/grid/local/Vagrantfile +++ b/morph/grid/local/Vagrantfile @@ -1,29 +1,61 @@ # -*- mode: ruby -*- # vi: set ft=ruby : -# This Vagrantfile worked for Florian Sesser using Vagrant 2.2.16dev and -# the VirtualBox Hypervisor. Earlier Vagrant and LibVirt did not work. +# This Vagrantfile worked for Florian Sesser using Vagrant 2.2.19 and +# the LibVirt with QEmu Hypervisor. Earlier Vagrant and VirtualBox did worked too. + +# Get a dedicated LibVirt pool name or use default one +pool_name = ENV.has_key?('POOL_NAME') ? ENV['POOL_NAME'] : 'default' +# For instance, one could create such pool beforehand as follows: +# export POOL_NAME=morph_local_$(id -un) +# POOL_PATH="/path/to/your/storage" +# mkdir -p "${POOL_PATH}" +# sudo virsh pool-define-as ${POOL_NAME} --type dir --target "${POOL_PATH}" +# sudo virsh pool-autostart ${POOL_NAME} +# sudo virsh pool-start ${POOL_NAME} Vagrant.configure("2") do |config| # For a complete reference, please see the online documentation at # https://docs.vagrantup.com. - config.vm.define "payments.localdev" do |config| - config.vm.hostname = "payments" - config.vm.box = "esselius/nixos" - config.vm.box_version = "20.09" - config.vm.box_check_update = false + # Select the base image + config.vm.box = "esselius/nixos" + config.vm.box_version = "20.09" + config.vm.box_check_update = false + + # No need to sync the working dir. with the guest boxess + # Better use SFTP to transfer + config.vm.synced_folder ".", "/vagrant", disabled: true + + # Tune LibVirt/QEmu guests + config.vm.provider :libvirt do |domain| + # The default of one CPU should work + # Increase to speed up boot/push/deploy + # domain.cpus = 1 # To use the self-updating deployment system you need more memory. Giving # all of the VMs enough memory for this is rather taxing, though, and the # self-updating deployment system is not particularly useful for local # dev. But should you want to: # - # config.vm.provider "virtualbox" do |v| - # v.memory = 4096 - # end + # domain.memory = 4096 + # + # Meanwhile, 1024 was apparently the default with VirtualBox + domain.memory = 1024 + + # Using a specific pool may help to manage the disk space + domain.storage_pool_name = pool_name + domain.snapshot_pool_name = pool_name + + # No need of graphics - better use serial + domain.graphics_type = "none" + domain.video_type = "none" + end + + config.vm.define "payments.localdev" do |config| + config.vm.hostname = "payments" - # Assign a static IP address inside the VirtualBox host-only (Vagrant + # Assign a static IP address inside the box host-only (Vagrant # calls it "private") network. The address must be in the range # VirtualBox allows. # https://www.virtualbox.org/manual/ch06.html#network_hostonly says some @@ -37,31 +69,26 @@ Vagrant.configure("2") do |config| config.vm.define "storage1.localdev" do |config| config.vm.hostname = "storage1" - config.vm.box = "esselius/nixos" - config.vm.box_version = "20.09" - config.vm.box_check_update = false config.vm.network "private_network", ip: "192.168.56.22" end config.vm.define "storage2.localdev" do |config| config.vm.hostname = "storage2" - config.vm.box = "esselius/nixos" - config.vm.box_version = "20.09" - config.vm.box_check_update = false config.vm.network "private_network", ip: "192.168.56.23" end config.vm.define "monitoring.localdev" do |config| config.vm.hostname = "monitoring" - config.vm.box = "esselius/nixos" - config.vm.box_version = "20.09" - config.vm.box_check_update = false config.vm.network "private_network", ip: "192.168.56.24" end # To make the VMs assign the static IPs to the network interfaces we need a rebuild: - config.vm.provision "shell", inline: "echo '{nix.settings.trusted-users = [ \"@wheel\" \"root\" \"vagrant\" ];}' > /etc/nixos/custom-configuration.nix" + ## Rename to 'nix.settings.trusted-users' after 20.09 or so: + config.vm.provision "shell", + inline: "echo '{ nix.trustedUsers = [ \"@wheel\" \"root\" \"vagrant\" ]; boot.kernelParams = [ \"console=tty0\" \"console=ttyS0,115200\" ]; }' > /etc/nixos/custom-configuration.nix" config.vm.provision "shell", inline: "nixos-rebuild switch" + config.vm.provision "shell", inline: "systemctl stop firewall.service" + config.vm.provision "shell", inline: "systemctl start serial-getty@ttyS0.service" config.trigger.after :up do |trigger| trigger.info = "Hostname and IP address this host actually uses:" diff --git a/morph/lib/hardware-vagrant.nix b/morph/lib/hardware-vagrant.nix index fba9353105463deed962c44b7cae1bcf936d68f0..c13cef856552e43e1bdfcab8bffce487dd4c0887 100644 --- a/morph/lib/hardware-vagrant.nix +++ b/morph/lib/hardware-vagrant.nix @@ -15,18 +15,19 @@ }; config = { - virtualisation.virtualbox.guest.enable = true; + services.qemuGuest.enable = true; - boot.loader.grub.device = "/dev/sda"; + boot.loader.grub.device = "/dev/vda"; - boot.initrd.availableKernelModules = [ "ata_piix" "sd_mod" "sr_mod" ]; + boot.initrd.availableKernelModules = [ "ata_piix" "virtio_pci" "virtio_blk" "sd_mod" "sr_mod" ]; boot.kernel.sysctl = { "vm.swappiness" = 0; }; + boot.kernelParams = [ "console=tty0" "console=ttyS0,115200" ]; # remove the fsck that runs at startup. It will always fail to run, stopping # your boot until you press *. boot.initrd.checkJournalingFS = false; - networking.interfaces.enp0s8.ipv4.addresses = [{ + networking.interfaces.ens5.ipv4.addresses = [{ address = config.grid.publicIPv4; prefixLength = 24; }]; @@ -47,7 +48,7 @@ fileSystems."/storage" = { fsType = "tmpfs"; }; fileSystems."/" = - { device = "/dev/sda1"; + { device = "/dev/vda1"; fsType = "ext4"; };