code editing workflow

Started by dirtyfreebooter, March 17, 2025, 08:56:49 PM

Previous topic - Next topic
curious as to hear how people are working with opnsense developement.. git clone / git branch / make mount / edit / git commit / git push / create pull request, is great and all. currently doing that on a Proxmox VM and its fairly simple.

but using vim/emacs on the terminal is so-so. vscode via remote SSH to freebsd doesn't really work without linux binary support, which the opnsense repo seems to be missing essential packages
devel/linux-rl9-libsigsegv
emulators/linux_base-rl9

i don't necessarily have to have vscode, but largely gotten use to it at this point. neovim seems like its possible with some effort to get it working on freebsd.

so i'd like to hear what other solutions people are using before i spend too much time in one direction.

thanks

I use Vagrant - need to urgently update my project for 25.1. OPNsense runs in a virtual machine, source tree(s) are on the host system. OPNsense mounts project directory via NFS.

For 24.7 see https://github.com/punktDe/vagrant-opnsense

My current large show stopper is that I need to configure a Debian VM on a powerful hypervisor for nested virtualisation and Vagrant so I can use VScode over SSH to that machine - because my Intel Mac is being replaced by Apple silicon.
Deciso DEC750
People who think they know everything are a great annoyance to those of us who do. (Isaac Asimov)

Quote from: Patrick M. Hausen on March 17, 2025, 09:31:15 PMI use Vagrant - need to urgently update my project for 25.1. OPNsense runs in a virtual machine, source tree(s) are on the host system. OPNsense mounts project directory via NFS.

For 24.7 see https://github.com/punktDe/vagrant-opnsense

My current large show stopper is that I need to configure a Debian VM on a powerful hypervisor for nested virtualisation and Vagrant so I can use VScode over SSH to that machine - because my Intel Mac is being replaced by Apple silicon.

oh yea, that is certainly doable with the proxmox setup i have, just have the code on a linux vm and nfs export and have opnsense nfs mount it. i'll give this a try. seems promising.

thanks!

April 09, 2025, 11:19:29 AM #3 Last Edit: April 09, 2025, 12:19:05 PM by fsackur
My current dev work is mostly parsing the source code, so I'm developing locally for the most part.

In my first quick-and-dirty hacking, I did a bunch of symlinking and rsync. Don't do that, it was miserable.

I fantasise about being an emacs/tmux wizard, but in the real world I'm just a VSCode user. There was a brief window when you could VSCode SSH to BSD, but that window is gone. BOO. I've also tried the SSHFS extension, but there are too many files for it to cope. So it's necessary to mount the source code into the VM.

I spent time looking into `virtio` so I could use qemu filesystem sharing, but concluded that you need to actually get to grips with BSD to make it work. So I use NFS instead. Here are the steps:

#region virtual host =============================================
dnf install -y nfs-utils  # Fedora is life

pushd /gitroot/opnsense-root  # my local dev folder, you can use /my-little-pony if you prefer
git clone opnsense/core opnsense/plugins opnsense/tools  # whatever

# serve to libvirt subnet
export="/gitroot/opnsense-root 192.168.124.0/24(rw,sync,fsid=0,no_subtree_check,no_root_squash,insecure)"
echo "$export" >> /etc/exports.d/opnsense.exports
systemctl enable --now nfs-server

firewall-cmd --zone=libvirt --permanent --add-service=nfs
firewall-cmd --zone=libvirt --permanent --add-service=mountd
firewall-cmd --zone=libvirt --permanent --add-service=rpc-bind
firewall-cmd --reload

# should show the share
exportfs
#endregion virtual host =============================================


#region BSD VM =============================================
# check yer host firewall ports:
rpcinfo -p 192.168.124.1
#    program vers proto  port  service
#    100000    4  tcp    111  rpcbind
#    100000    3  tcp    111  rpcbind
#      ...etc...
# It's possible for all services to be shown but still get RPC errors. In that case,
# try adding more services: nfs3, portmap. I tested on F41 / BSD14.2.

# You REALLY want bgnow, because mount comes before networking.
# Skip that option and your box won't boot.
#
#      Device                               Mountpoint  FStype  Options                Dump  Pass
mount="192.168.124.1:/gitroot/opnsense-root /gitroot    nfs     rw,bgnow,soft,noatime  0    3"
echo "$Mount" | sudo tee -a /etc/fstab
# yeah I installed sudo on BSD. I never claimed to be a good person.

git config --global --add safe.directory /gitroot/core
git config --global --add safe.directory /gitroot/plugins
git config --global --add safe.directory /gitroot/tools

# Use script from https://medium.com/@mihakralj/the-direct-route-installing-freebsd-packages-on-opnsense-d002ac0c56b8
# Update script packagesite.txz => packagesite.tzst
./sideload.sh py311-pip 
# output:
# pkg add https://pkg.freebsd.org/FreeBSD:14:amd64/latest/All/py311-pip-23.3.2_4.pkg
# then you can do:
pip install libfoo
# ...but, for awareness, the OS packages will be 99 versions behind pypi, so you
# can't easily release on these versions

# If you can live with old versions, do:
./sideload.sh py311-libfoo
# or you can vendor in the libraries, but upstream might not be best pleased!

#endregion BSD VM =============================================

After doing that, I just dev locally. If you're developing `core`, cd into the repo and do `make mount`. If you're developing a plugin, cd into the dir containing your `src` and your `Makefile` and do `make install && service configd restart && configctl foo bar`.

The PHP extensions I've tried in Code thrash my poor little box. I can have the plugins repo open, but not the core repo, or my poor little host starts whining like a jumbo jet. Half the time I'm doing text search instead of using the LSP because the fan noise is just silly.

One other thing, delete `/tmp/opnsense_menu_cache.xml` if you create a `Menu.xml`, or you'll be forever wondering why it doesn't show up.
We do this not because it is easy, but because we thought it would be easy

> make mount

I recommend editing files in /usr/core and then just "make upgrade". It takes care of everything (like purging caches and restarting the web server) and doesn't leave behind the mess that "make mount" can accumulate.

If you don't like "make upgrade" then at least use "make install".

If you prefer editing files in the system "make collect" is a nice thing collecting your file system changes into /usr/core, but it's rarely super useful.



Cheers,
Franco