Skip to content

Commit

Permalink
Add a development environment setup using Vagrant. #9
Browse files Browse the repository at this point in the history
  • Loading branch information
Luka Vilfan committed Oct 3, 2022
1 parent 53b835a commit 2382f01
Show file tree
Hide file tree
Showing 13 changed files with 260 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,6 @@ dkms.conf
# # # ArchPkgbuild # # #
package/arch/*
!package/arch/PKGBUILD

# # # Vagrant # # #
**/.vagrant
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ library, meaning a rock-solid foundation to build on.
* `wl-clipboard` (screenshot & clipboard)
* `brightnessctl` (brightness control via waybar)

### Using the Vagrant development environment
TODO: Finish this section

### Building and installing

* Clone the repo
Expand Down
106 changes: 106 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

module LocalCommand
class Config < Vagrant.plugin("2", :config)
attr_accessor :command
end

class Plugin < Vagrant.plugin("2")
name "local_shell"

config(:local_shell, :provisioner) do
Config
end

provisioner(:local_shell) do
Provisioner
end
end

class Provisioner < Vagrant.plugin("2", :provisioner)
def provision
result = system "#{config.command}"
end
end
end

Vagrant.configure("2") do |config|
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.

# Every Vagrant development devenvment requires a box. You can search for
# boxes at https://vagrantcloud.com/search.
config.vm.define "devenv"
config.vm.box = "generic/arch"
config.vm.hostname = "bonsai-devenv"

# Configure libvirt for 3d accelerated graphical session.
config.vm.provider :libvirt do |libvirt|
libvirt.graphics_type = "spice"
libvirt.video_accel3d = true
libvirt.video_type = "virtio"
libvirt.graphics_ip = nil
libvirt.graphics_port = nil
libvirt.uuid = "60fa5b18-e4d6-47a4-af7a-023d3d34bfaa"
libvirt.uri = "qemu:///system"
end

# Share working directory with devenv.
config.vm.synced_folder ".", "/vagrant_data"

# Various provisioners for working with the devenv.
config.vm.provision "connect", type: "local_shell", run: "always" do |p|
p.command = "virt-viewer -ac qemu:///system --uuid 60fa5b18-e4d6-47a4-af7a-023d3d34bfaa &"
end

config.vm.provision "prepare_box", type: "shell", run: "once" do |p|
p.path = "devenv/prepare_box.sh"
p.privileged = true
end

config.vm.provision "install_compile_deps", type: "shell", run: "once" do |p|
p.path = "devenv/install_compile_deps.sh"
p.privileged = true
end

config.vm.provision "install_runtime_deps", type: "shell", run: "once" do |p|
p.path = "devenv/install_runtime_deps.sh"
p.privileged = true
end

config.vm.provision "prepare_git", type: "shell", run: "never" do |p|
p.path = "devenv/project_prepare_git.sh"
p.privileged = false
end

config.vm.provision "prepare_local", type: "shell", run: "never" do |p|
p.path = "devenv/project_prepare_local.sh"
p.privileged = false
end

config.vm.provision "build", type: "shell", run: "never" do |p|
p.path = "devenv/project_build.sh"
p.privileged = false
end

config.vm.provision "update", type: "shell", run: "never" do |p|
p.path = "devenv/project_update.sh"
p.privileged = false
end

config.vm.provision "run", type: "shell", run: "never" do |p|
p.path = "devenv/project_run.sh"
p.privileged = false
end

config.vm.provision "kill", type: "shell", run: "never" do |p|
p.path = "devenv/project_kill.sh"
p.privileged = false
end

config.vm.provision "clean", type: "shell", run: "never" do |p|
p.path = "devenv/project_clean.sh"
p.privileged = false
end
end
55 changes: 55 additions & 0 deletions devenv/install_compile_deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env bash

install() {
pacman -S --noconfirm $@
}

concat() {
local -n in=$1
for dep in ${in[@]}; do
deps="$deps $dep"
done
echo $deps
}

dependencies=(
base-devel
gdb
git
meson
libinput
libevdev
systemd-libs
libxkbcommon
mesa
vulkan-headers
libdrm
wayland
wayland-utils
wayland-protocols
xdg-desktop-portal
xdg-desktop-portal-wlr
pixman
cairo
seatd
xcb-util
xcb-util-renderutil
xcb-util-wm
xcb-util-errors
xorg-xwayland
glslang
ffmpeg
rsync
)

install $(concat dependencies)

install_wlroots_latest() {
git clone https://gitlab.freedesktop.org/wlroots/wlroots.git /root/wlroots
cd /root/wlroots
meson builddir
meson compile -C builddir
meson install -C builddir
}

install_wlroots_latest
26 changes: 26 additions & 0 deletions devenv/install_runtime_deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash

install() {
pacman -S --noconfirm $@
}

concat() {
local -n in=$1
for dep in ${in[@]}; do
deps="$deps $dep"
done
echo $deps
}

dependencies=(
swaybg
swaylock
bemenu-wayland
waybar
slurp
grim
wl-clipboard
brightnessctl
)

install $(concat dependencies)
7 changes: 7 additions & 0 deletions devenv/prepare_box.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

update () {
pacman -Syu --noconfirm
}

update
6 changes: 6 additions & 0 deletions devenv/project_build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

[ ! -d /home/vagrant/bonsai ] && echo "Run prepare_* first." && exit 1

cd /home/vagrant/bonsai
meson compile -C builddir/
9 changes: 9 additions & 0 deletions devenv/project_clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

[ ! -d /home/vagrant/bonsai ] && echo "Nothing to clean." && exit 0

cd /home/vagrant/bonsai

[ ! -d builddir ] && echo "Nothing to clean." && exit 0

rm -rf builddir
3 changes: 3 additions & 0 deletions devenv/project_kill.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

killall bonsai
5 changes: 5 additions & 0 deletions devenv/project_prepare_git.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

[ ! -d /home/vagrant/bonsai ] && git clone https://github.com/vilfa/bonsai.git /home/vagrant/bonsai
cd /home/vagrant/bonsai
[ ! -d builddir ] && PKG_CONFIG_PATH=/usr/local/lib/pkgconfig meson builddir/
10 changes: 10 additions & 0 deletions devenv/project_prepare_local.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

[ -d /home/vagrant/bonsai ] && rm -rf /home/vagrant/bonsai
mkdir /home/vagrant/bonsai && cd /home/vagrant/bonsai
rsync -vh --no-compress --progress --info=progress -r \
/vagrant_data/* /home/vagrant/bonsai \
--exclude=".*" --exclude="builddir"

cd /home/vagrant/bonsai
[ ! -d builddir ] && PKG_CONFIG_PATH=/usr/local/lib/pkgconfig meson builddir/
21 changes: 21 additions & 0 deletions devenv/project_run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

[ ! -d /home/vagrant/bonsai ] && echo "Run prepare_* first." && exit 1

cd /home/vagrant/bonsai

[ ! -f builddir/bonsai/bonsai ] && echo "Run build first." && exit 1

tty=$(who | grep tty)
if [[ "$tty" ]]; then
tty="/dev/$(who | grep tty | tr -s ' ' | cut -d ' ' -f 2)"
echo "Open graphical console is $tty."
echo "Running bonsai in the open graphical session is currently unsupported."
echo "Run it manually with `cd /home/vagrant/bonsai && ./builddir/bonsai/bonsai`."
# TODO: Run bonsai in the open graphical console.
# setsid bash -c "export XDG_SEAT=seat0 && exec /home/vagrant/bonsai/builddir/bonsai/bonsai <> $tty >&0 2>&1"
# sudo openvt -svfc 1 -- bash -c "export XDG_SEAT=seat0 && exec /home/vagrant/bonsai/builddir/bonsai"
else
echo "Login in the graphical session first (vagrant:vagrant)."
exit 1
fi
6 changes: 6 additions & 0 deletions devenv/project_update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

[ ! -d /home/vagrant/bonsai ] && echo "Run prepare_* first." && exit 1
rsync -vh --no-compress --progress --info=progress -r \
/vagrant_data/* /home/vagrant/bonsai \
--exclude=".*" --exclude="builddir"

0 comments on commit 2382f01

Please sign in to comment.