4 # This file and its contents are supplied under the terms of the
5 # Common Development and Distribution License ("CDDL"). You may
6 # only use this file in accordance with the terms of the CDDL.
8 # A full copy of the text of the CDDL should have accompanied this
9 # source. A copy of the CDDL is also available via the Internet at
10 # http://www.illumos.org/license/CDDL.
14 # Copyright 2016 Adam Stevko. All rights reserved.
15 # Copyright 2017 Michal Nowak
16 # Copyright 2021 David Stes
19 Vagrant.configure("2") do |config|
20 # Every Vagrant development environment requires a box. You can search for
21 # boxes at https://atlas.hashicorp.com/search.
22 config.vm.box = "openindiana/hipster"
24 # Disable automatic box update checking. If you disable this, then
25 # boxes will only be checked for updates when the user runs
26 # `vagrant box outdated`. This is not recommended.
27 config.vm.box_check_update = true
29 # Unless OpenIndiana is better supported in vagrant, we have to use this
30 # workaround. The problem with vagrant is that it creates folder as root:root,
31 # but rsync connects as vagrant and thus fails to write.
32 config.vm.synced_folder ".", "/vagrant", type: "rsync",
33 rsync__args: ["--verbose", "--archive", "-zz", "--copy-links"],
34 rsync__rsync_path: "pfexec rsync", owner: "vagrant", group: "vagrant"
36 # Autoconfigure resources for development VM. The snippet is taken from
37 # https://stefanwrobel.com/how-to-make-vagrant-performance-not-suck.
38 # We allocate 1/4 of available system memory and CPU core count of the host
39 # to the VM, so performance does not suck.
40 host = RbConfig::CONFIG['host_os']
42 # Get memory size and CPU cores amount
44 mem = `/usr/sbin/prtconf|grep Memory|cut -f3 -d' '`.to_i * 1024 * 1024
45 cpus = `/usr/sbin/psrinfo|wc -l`.to_i
46 elsif host =~ /darwin/
47 # sysctl returns Bytes
48 mem = `sysctl -n hw.memsize`.to_i
49 cpus = `sysctl -n hw.ncpu`.to_i
51 # meminfo shows size in kB; convert to Bytes
52 mem = `awk '/MemTotal/ {print $2}' /proc/meminfo`.to_i * 1024
53 cpus = `getconf _NPROCESSORS_ONLN`.to_i
54 elsif host =~ /mswin|mingw|cygwin/
55 # Windows code via https://github.com/rdsubhas/vagrant-faster
56 mem = `wmic computersystem Get TotalPhysicalMemory`.split[1].to_i
57 cpus = `echo %NUMBER_OF_PROCESSORS%`.to_i
59 puts "Unsupported operating system"
63 # Give VM 1/4 system memory as well as CPU core count
67 config.vm.provider "virtualbox" do |v|
68 v.customize ["modifyvm", :id, "--memory", mem]
69 v.customize ["modifyvm", :id, "--cpus", cpus]
71 v.customize ["storagectl", :id, "--name", "SATA Controller", "--hostiocache", "on"]
72 # Enable following line, if oi-userland directory is on non-rotational
73 # drive (e.g. SSD). (This could be automated, but with all those storage
74 # technologies (LVM, partitions, ...) on all three operationg systems,
75 # it's actually error prone to detect it automatically.) macOS has it
76 # enabled by default as recent Macs have SSD anyway.
78 v.customize ["storageattach", :id, "--storagectl", "SATA Controller", "--port", 0, "--nonrotational", "on"]
80 #v.customize ["storageattach", :id, "--storagectl", "SATA Controller", "--port", 0, "--nonrotational", "on"]
82 # Should we ever support `--discard` option, we need to switch to VDI
83 # virtual disk format first.
84 #v.customize ["storageattach", :id, "--storagectl", "SATA Controller", "--port", 0, "--discard", "on"]
85 config.vm.synced_folder ".", "/vagrant_mounted"
88 config.vm.provider :libvirt do |libvirt|
93 # Once vagrant is able to chown files on OpenIndiana, chown line should be
94 # removed from this part.
95 config.vm.provision "shell", inline: <<-SHELL
96 pfexec chown -R vagrant:vagrant /vagrant
97 pfexec pkg install build-essential
99 cd /vagrant && gmake setup
100 pfexec pkg set-publisher --non-sticky -g file:///vagrant/i386/repo userland
101 pfexec pkg set-publisher --non-sticky openindiana.org
102 echo "VM is ready, happy contributing!"