Thunderbots uses Bazel, which assumes an FHS system. In addition, dependencies are installed imperatively via a script that manually downloads dependencies, making it difficult to port to Nix.
My solution: Use an Ubuntu LXC container with X11 forwarding (for Thunderscope). This can be (mostly) declaratively configured using the Incus options available in NixOS. See the second file for the code.
- Add the provided NixOS module to your system configuration (not home-manager).
- Set options (under
my.containers.tbotsnamespace):- (REQUIRED)
enable = true - (REQUIRED)
user, set to your username - (REQUIRED)
dataDir, set to a folder in your home folder (will be created) - (REQUIRED)
uid, set to the uid corresponding to your user - (optional)
packages, list of strings, interpreted as apt packages to be preinstalled - (optional)
envExtra, shell script to be evaluated in global shell profile - (optional)
bashrcExtra, shell script to be evaluated in global bashrc
- (REQUIRED)
sudo nixos-rebuild switchand reboot (to apply user groups)- Run
incus launch images:ubuntu/24.04/cloud -p tbots-base(Note the/cloud, this is necessary for setup to work)- This should print an instance name, referred to as
<iname>from here on out
- This should print an instance name, referred to as
- Wait for
cloud-initto finish:incus exec <iname> -- cloud-init status --wait - Log into your user in the guest:
incus exec <iname> -- su - $(whoami) - (Inside the container) Perform any desired configuration (e.g. vimrc, ssh keys)
- (Inside the container)
cdto the~/sharedfolder; this is the bind mount created earlier- For convenience, it is recommended to store the Thunderbots repo here so it can be edited on both host and guest
- (Inside the container) Follow Thunderbots instructions (clone code, run scripts, etc)
- You can edit code in the guest container or on the host OS (not sure how well tooling will work on the host, install IDE inside the guest for the best experience).
- For convenience, you can use git from the host so you don't have to set up ssh keys inside the guest
- Code must be built in the guest due to dependencies only being installed there
- Running graphical apps in the guest should automatically forward the window to the host (requires X or Xwayland)
- There is an alias provided for this:
launch <command> [args...]will fork the command to the background, detach it from the terminal, and silence its output
- There is an alias provided for this:
- The X socket forwarding should work for Xwayland (Tested using niri+xwayland-satellite)
- If using Wayland, setup a bind mount for the Wayland socket instead of Xorg (/run/user//wayland-1)
- If you get an error when starting graphical apps like "
couldn't open display :0", runsystemctl restart --user socket_setupas user (not as root)
Code adapted from: