mirror of
https://github.com/arnaucube/hyperplonk.git
synced 2026-01-11 16:41:28 +01:00
env setup (#6)
This commit is contained in:
2
nix/vagrant/.gitignore
vendored
Normal file
2
nix/vagrant/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
hyperplonk/
|
||||
.vagrant
|
||||
66
nix/vagrant/README.md
Normal file
66
nix/vagrant/README.md
Normal file
@@ -0,0 +1,66 @@
|
||||
# Test nix-shell in vagrant VMs
|
||||
|
||||
Set up a vagrant guest VM, and test the dev environment inside the guest.
|
||||
|
||||
- Only tested on nixos host with _libvirt_ virtualization provider.
|
||||
- Assumes that the host has an SSH agent. The agent is used for SSH auth inside
|
||||
the guest.
|
||||
- Upon creation (`vagrant up`) a copy of this local repo is rsynced to the
|
||||
`/hyperplonk` directory in the guest. The tests are run against these files. To
|
||||
see changes made to the code on the host run `vagrant reload` to re-sync the
|
||||
source code from host to guest.
|
||||
|
||||
## Available vagrant boxes
|
||||
The following boxes are available:
|
||||
|
||||
- `ubuntu`: `ubuntu20.04` + `nix`
|
||||
- `ubuntu_rustup`: `ubuntu20.04` + `nix` + `rustup`
|
||||
|
||||
More OSes/VMs can be added in the `Vagrantfile`.
|
||||
|
||||
Append name of box after vagrant command to apply to a single box only
|
||||
|
||||
vagrant up ubuntu_rustup
|
||||
vagrant ssh ubuntu_rustup
|
||||
|
||||
## Usage
|
||||
Enable `libvrtd` on your host:
|
||||
[ubuntu](https://ubuntu.com/server/docs/virtualization-libvirt),
|
||||
[nixos](https://nixos.wiki/wiki/Libvirt).
|
||||
|
||||
Make sure we are in the `libvirtd` group.
|
||||
|
||||
Install `libvirt` vagrant plugin (not needed on nixos):
|
||||
|
||||
vagrant plugin install vagrant-libvirt
|
||||
|
||||
Activate nix-shell in this directory (or ensure vagrant is installed):
|
||||
|
||||
nix-shell
|
||||
|
||||
Start vm:
|
||||
|
||||
vagrant up ubuntu
|
||||
|
||||
There is a password prompt to add the insecure vagrant key to the agent. One can
|
||||
supply an empty password once or cancel the prompt each time one runs `vagrant
|
||||
ssh`.
|
||||
|
||||
Run formatter, linter, tests inside a nix-shell environment inside the `ubuntu`
|
||||
guest:
|
||||
|
||||
vagrant ssh ubuntu -- -t /vagrant/test-nix-shell-guest
|
||||
|
||||
This runs the `test-nix-shell-guest` script in this directory inside the vagrant
|
||||
guest.
|
||||
|
||||
Clean up with
|
||||
|
||||
vagrant destroy ubuntu
|
||||
|
||||
## Notes
|
||||
|
||||
- After editing the Vagrantfile, `vagrant reload` will apply the changes.
|
||||
- When making substantial changes or changing names of vagrant boxes I usually
|
||||
have more luck with running `vagrant destroy` with the previous `Vagrantfile`
|
||||
and then `vagrant up` again with the new `Vagrantfile`.
|
||||
36
nix/vagrant/Vagrantfile
vendored
Normal file
36
nix/vagrant/Vagrantfile
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
# -*- mode: ruby -*-
|
||||
# vi: set ft=ruby :
|
||||
|
||||
Vagrant.configure("2") do |config|
|
||||
|
||||
config.vm.define "ubuntu" do |ubuntu|
|
||||
ubuntu.vm.box = "generic/ubuntu2004"
|
||||
$script = <<~SCRIPT
|
||||
set -euxo pipefail
|
||||
curl -L https://nixos.org/nix/install | sh
|
||||
SCRIPT
|
||||
ubuntu.vm.provision "shell", inline: $script, privileged: false
|
||||
end
|
||||
|
||||
config.vm.define "ubuntu_rustup" do |ubuntu|
|
||||
ubuntu.vm.box = "generic/ubuntu2004"
|
||||
$script = <<~SCRIPT
|
||||
set -euxo pipefail
|
||||
curl -L https://nixos.org/nix/install | sh
|
||||
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
|
||||
source $HOME/.cargo/env
|
||||
rustup default stable-2021-06-17
|
||||
SCRIPT
|
||||
ubuntu.vm.provision "shell", inline: $script, privileged: false
|
||||
end
|
||||
|
||||
config.ssh.forward_agent = true
|
||||
config.vm.synced_folder ".", "/vagrant", disabled: false
|
||||
config.vm.synced_folder "../..", "/hyperplonk", disabled: false, rsync__exclude: [".git/", "target"]
|
||||
|
||||
|
||||
config.vm.provider "libvirt" do |v|
|
||||
v.cpus = 4
|
||||
end
|
||||
|
||||
end
|
||||
7
nix/vagrant/shell.nix
Normal file
7
nix/vagrant/shell.nix
Normal file
@@ -0,0 +1,7 @@
|
||||
with import ../nixpkgs.nix { };
|
||||
|
||||
mkShell {
|
||||
buildInputs = [
|
||||
vagrant
|
||||
];
|
||||
}
|
||||
20
nix/vagrant/test-nix-shell-guest
Executable file
20
nix/vagrant/test-nix-shell-guest
Executable file
@@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euxo pipefail
|
||||
|
||||
# vagrant "ssh + command" does not source, adding -- -t does not help
|
||||
. $HOME/.nix-profile/etc/profile.d/nix.sh
|
||||
if [ -f $HOME/.carg/env ]; then
|
||||
source $HOME/.cargo/env
|
||||
fi
|
||||
|
||||
ssh-keyscan gitlab.com >> ~/.ssh/known_hosts
|
||||
ssh -T git@gitlab.com
|
||||
|
||||
cd /hyperplonk
|
||||
|
||||
nix-shell --run "cargo-clippy"
|
||||
nix-shell --run "cargo fmt -- --check"
|
||||
nix-shell --run "cargo test --doc"
|
||||
nix-shell --run "cargo test --release"
|
||||
|
||||
echo "Ok!"
|
||||
Reference in New Issue
Block a user