nix-community / vagrant-nixos-plugin

Vagrant plugin to add nixos guest capabilities and nix provisioning [maintainer=@zimbatm]
MIT License
68 stars 7 forks source link

Verify the plugin and the (new) boxes work with Vagrant multi-host setups #4

Open ctheune opened 9 years ago

zimbatm commented 9 years ago

@ctheune Just released plugin v0.1.1. It should work with the zimbatm/nixos-15.09-x86_64 image but haven't tried personally. Do you want to give it a go ?

ctheune commented 9 years ago

I'll try to test it out today with our own. We started the flyingcircus/nixos-15.09-x86_64 for our platform stuff.

ctheune commented 9 years ago

Hmm. This didn't work for me out of the box as no vagrant-hostname.nix was created at all.

This should be done by Vagrant itself, right?

Here's the vagrant file:

Vagrant.configure(2) do |config|
  config.vm.box = "flyingcircus/nixos-15.09-x86_64"
  config.vm.network "private_network", ip: "192.168.50.4"
  config.vm.provider "virtualbox" do |v|
    v.memory = 1024
  end
  config.vm.hostname = "asdf"

  config.vm.provision :nixos, :verbose => true, :path => "provision.nix"

end

It doesn't matter whether I add the hostname or not. The plugin shows its updated to 0.1.1 ...

Hmm.

zimbatm commented 9 years ago

Yes Vagrant 1.6.4+ does this for you, the plugin just takes care of running nixos-rebuild swtich.

What version of Vagrant are you using ? Also can you give me the output of ls -la /etc/nixos/ in the guest OS ?

ctheune commented 9 years ago

Here's my setup:

Here's /etc/nixos:

[root@nixos:~]# cd /etc/nixos/

[root@nixos:/etc/nixos]# ls -lah
total 28K
drwxr-xr-x  2 root    root    4.0K Oct 19 13:13 .
drwxr-xr-x 18 root    root    4.0K Oct 19 13:13 ..
-rw-r--r--  1 root    root     202 Oct 16 07:38 configuration.nix
-rw-r--r--  1 root    root     571 Oct 16 07:38 hardware-configuration.nix
-rw-------  1 vagrant vagrant  164 Oct 19 13:13 vagrant-network.nix
-rw-------  1 vagrant vagrant  177 Oct 19 13:13 vagrant.nix
-rw-------  1 vagrant vagrant  880 Oct 19 13:13 vagrant-provision.nix

This is with the following Vagrant file:

Vagrant.configure("2") do |config|
  config.vm.box = "flyingcircus/nixos-15.09-x86_64"
  config.vm.box_version = ">= 1.2"
  config.vm.synced_folder "../fc.directory", "/home/vagrant/fc.directory"
  config.vm.provider "virtualbox" do |v|
      v.memory = 2048
  end

  config.vm.network "private_network", ip: "192.168.50.4"
  # config.vm.hostname = "directory"
  config.vm.provision :nixos, :verbose => true, :path => "provision.nix"
end

I even encountered some weird issues with stability of the VM itself, hopefully this isn't related to this ;)

ctheune commented 9 years ago

Something I noticed: setting the name explicity requires you to re-run both vagrant reload and provision is that intentional?

ctheune commented 9 years ago

I kept playing with this. I think the main issue is that there are cases where the name does not get managed. The interesting part there is to a) be graceful if vagrant-hostname.nix does not exist and b) ponder whether we simply stop caring what the hostname is if a Vagrant file is turned back to default (the manual states that Vagrant doesn't care, so we end up with "whatever" as a result as vagrant won't remove the old vagrant-hostname file, more or less obviously).

zimbatm commented 9 years ago

Try adding the following packages to your base image: https://github.com/zimbatm/nixbox/blob/master/scripts/configuration.nix#L34-L41 I don't remember exactly which is for what but I took some time combing trough the Vagrant code to find on what userland utils it was depending on. I don't know how Vagrant would behave if any of these are missing.

In regards to reload+provision, yes this is a design decision but not mine. The Vagrant folks have decided that provisioning only happens once or with implicit calls thereafter. I had a look at overriding that default for this plugin but didn't see any easy way, it seems like this is handled on another layer.

What happens right now is that the /etc/nixos/vagrant-hostname.nix should be re-generated on reload but only applied to the system during provisioning.

zimbatm commented 9 years ago

Hmm you're right, it's possible that Vagrant just leaves the file standing if you remove the declaration from your Vagrantfile. This is unfortunate.

zimbatm commented 9 years ago

I just learned a new trick: vagrant reload --provision-with nixos will always apply the provisioner after reload. If you only have one provisioner you can also run vagrant reload --provision

zimbatm commented 9 years ago

Even better:

config.vm.provision :nixos, path: "provision.nix", run: "always"
ctheune commented 9 years ago

Right. So, nevertheless, to support simple Vagrantfiles, I suggest making the include of vagrant-hostname.nix optional. I can provide a patch if you're busy.

zimbatm commented 8 years ago

This has been fixed in release v0.2.0. Did you get any chance to test the multi-host setup ?