Vagrant: Difference between revisions

From NixOS Wiki
imported>Samueldr
m Adds a (slightly wrong) documentation to make use of NFS mounts and vagrant.
imported>GeFrIt42
m vagrant 2.3.4's bug in mounting nfs folders: add reference to vagrant bug issue that contains a workaround
 
(3 intermediate revisions by 3 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|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.}}
{{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.}}
 
{{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 27: Line 46:


See [[Vagrant_Box#NixOS_Plugin|the NixOS vagrant box page]], which as information about the <code>vagrant-nixos-plugin</code> project.
See [[Vagrant_Box#NixOS_Plugin|the NixOS vagrant box page]], which as information about the <code>vagrant-nixos-plugin</code> project.
== Troubleshooting:  conflicting dependencies bundler when installing vagrant plugins==
As of 18.03 vagrant plugins are broken:
<syntaxhighlight lang=console>
$  vagrant plugin update
Updating installed plugins...
Bundler, the underlying system Vagrant uses to install plugins,
reported an error. The error is shown below. These errors are usually
caused by misconfigured plugin installations or transient network
issues. The error from Bundler is:
conflicting dependencies bundler (= 1.14.6) and bundler (= 1.16.1)
  Activated bundler-1.16.1
  which does not match conflicting dependency (= 1.14.6)
  Conflicting dependency chains:
    bundler (= 1.16.1), 1.16.1 activated
  versus:
    bundler (= 1.14.6)
  Gems matching bundler (= 1.14.6):
    bundler-1.14.6
</syntaxhighlight>
using the following nix expression fixes the problems:
<syntaxhighlight lang=nix>
(import <nixpkgs> {
    overlays = [
      (self: super: {
        bundler = super.bundler.overrideAttrs (old: {
          name = "bundler-1.16.1";
          src = super.fetchurl {
            url = "https://rubygems.org/gems/bundler-1.16.1.gem";
            sha256 = "1s2nq4qnffxg3kwrk7cnwxcvfihlhxm9absl2l6d3qckf3sy1f22";
          };
        });
      })
    ];
  }).vagrant
</syntaxhighlight>
More information in this [https://github.com/NixOS/nixpkgs/issues/36880 issue]

Latest revision as of 15:03, 3 December 2023

Note: This page is about vagrant, see Vagrant Box for the NixOS vagrant boxes.

NixOS as Host

Using NFS mounts

Add to your Vagrantfile:

  # Mount a folder inside the VM.
  config.vm.synced_folder "myfolder/", "/mnt/myfolder", type: "nfs", nfs_version: 4

Add to your configuration.nix:

{
  # Minimal configuration for NFS support with Vagrant.
  services.nfs.server.enable = true;
  
  # 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 ];                                               
  };     
}

This should make NFS mounts work.

Note: Vagrant will, by default, want to use sudo and modify /etc/exports. As long as you are not defining exports with configuration.nix, 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 chmod a+x ~, but note that this will allow all users on the system to read world-readable files within your home given the paths.
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 : [1]

Plugins

NixOS Plugin

See the NixOS vagrant box page, which as information about the vagrant-nixos-plugin project.

Troubleshooting: conflicting dependencies bundler when installing vagrant plugins

As of 18.03 vagrant plugins are broken:

$  vagrant plugin update
Updating installed plugins...
Bundler, the underlying system Vagrant uses to install plugins,
reported an error. The error is shown below. These errors are usually
caused by misconfigured plugin installations or transient network
issues. The error from Bundler is:
conflicting dependencies bundler (= 1.14.6) and bundler (= 1.16.1)
  Activated bundler-1.16.1
  which does not match conflicting dependency (= 1.14.6)
  Conflicting dependency chains:
    bundler (= 1.16.1), 1.16.1 activated
  versus:
    bundler (= 1.14.6)
  Gems matching bundler (= 1.14.6):
    bundler-1.14.6

using the following nix expression fixes the problems:

(import <nixpkgs> {
    overlays = [
      (self: super: {
        bundler = super.bundler.overrideAttrs (old: {
          name = "bundler-1.16.1";
          src = super.fetchurl {
            url = "https://rubygems.org/gems/bundler-1.16.1.gem";
            sha256 = "1s2nq4qnffxg3kwrk7cnwxcvfihlhxm9absl2l6d3qckf3sy1f22";
          };
        });
      })
    ];
  }).vagrant

More information in this issue