Today I had a problem with watch tasks like grunt-contrib-watch not noticing changes to files inside my Vagrant VM’s NFS share. To avoid this I wanted to edit the files over SSH using Emacs’
tramp-mode, but because of NFS share UID differences it proved difficult. NFS is set by Vagrant to write as the correct user, but because the host machine’s UID doesn’t match the VM’s vagrant user, the files appear read-only from the VM’s perspective. (With a Mac host at least the files are owned by
501:dialout, instead of
vagrant:vagrant.) This confuses TRAMP mode and ends up with an RSI inducing amount of “File X is write-protected; try to save anyway? (yes or no)” messages. It took far too long to figure out a way around it but, I got there in the end with help from the good folks on #vagrant and #emacs. Here’s a snippet to brutally disable the warnings:
Here’s hoping Vagrant will support something like this :nfs_guest feature soon, it certainly sounds like the developers are on the case. But in the meantime at least I can get on with some coding!
Another tact I’ve tried to get the other developers up and running is a shell script that watches for changes and touches the corresponding file over SSH.
(It assumes the Vagrantfile is in the project root, and that ~/remote/base/path is the path to your project, in the NFS mount, on the remote machine.)