Vagrant: Difference between revisions

imported>Mic92
document vagrant quirk
Adding notes about networking firewall blocking DHCP requests
 
(3 intermediate revisions by 2 users not shown)
Line 6: Line 6:


=== Using NFS mounts ===
=== Using NFS mounts ===
Add to your <tt>Vagrantfile</tt>:
<syntaxhighlight lang="Ruby">
  # Mount a folder inside the VM.
  config.vm.synced_folder "myfolder/", "/mnt/myfolder", type: "nfs", nfs_version: 4
</syntaxhighlight>


Add to your <tt>configuration.nix</tt>:
Add to your <tt>configuration.nix</tt>:
Line 13: Line 19:
   # Minimal configuration for NFS support with Vagrant.
   # Minimal configuration for NFS support with Vagrant.
   services.nfs.server.enable = true;
   services.nfs.server.enable = true;
   # !!! This is "unsafe", ports needed should be found and fixed here.
 
   networking.firewall.enable = false;
   # Add firewall exception for VirtualBox provider
  networking.firewall.extraCommands = ''
    ip46tables -I INPUT 1 -i vboxnet+ -p tcp -m tcp --dport 2049 -j ACCEPT
  '';
 
  # Add firewall exception for libvirt provider when using NFSv4
   networking.firewall.interfaces."virbr1" = {                                 
    allowedTCPPorts = [ 2049 ];                                             
    allowedUDPPorts = [ 2049 ];                                             
  };    
}
}
</syntaxhighlight>
</syntaxhighlight>


This will make NFS mounts work.
This should make NFS mounts work.
 
{{note|Vagrant will, by default, want to use <code>sudo</code> and modify <tt>/etc/exports</tt>. As long as you are not defining exports with <tt>configuration.nix</tt>, vagrant should be able to work.}}
 
{{note|Home directories are set not to be world-searchable by default on NixOS. This may lead to a "permission denied" error when trying to mount directories within your home into the VM. You can change this by running <code>chmod a+x ~</code>, but note that this will allow all users on the system to read world-readable files within your home given the paths.}}


{{note|Do note that vagrant will, by default, want to use <code>sudo</code> and modify <tt>/etc/exports</tt>. As long as you are not defining exports with <tt>configuration.nix</tt>, vagrant should be able to work.}}
{{Warning|Since '''Vagrant 2.3.4 a bug is preventing the mounting of the nfs folders'''. The issue is vagrant try to call System V instead of Systemd in order to get the status of nfs service. For details and '''workaround''' : [https://github.com/hashicorp/vagrant/issues/13296]}}


== Plugins ==
== Plugins ==
Line 69: Line 88:


More information in this [https://github.com/NixOS/nixpkgs/issues/36880 issue]
More information in this [https://github.com/NixOS/nixpkgs/issues/36880 issue]
== Troubleshooting: VM failing to receive IP address ==
If you run <code>vagrant up</code> and your VM is stalling with the message <code>Waiting for domain to get an IP address</code>, your networking firewall may be blocking vagrants DHCP requests. You can allow the requests with the following changes to your configuration.nix file:
<syntaxhighlight lang=nix>
# Trust libvirt bridge interfaces for VM networking (required for Vagrant DHCP)
networking.firewall.trustedInterfaces = [ "virbr0" "virbr1" "virbr2" ];
# Don't let NetworkManager manage libvirt bridges (prevents conflicts)
networking.networkmanager.unmanaged = [ "virbr0" "virbr1" "virbr2" ];
</syntaxhighlight>