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

error running 'mv /tmp/vagrant-provision.nix /etc/nixos/vagrant-provision.nix' #15

Closed bbigras closed 4 years ago

bbigras commented 4 years ago

I use virtualbox and I disabled the shared folders with config.vm.synced_folder '.', '/vagrant', disabled: true since the box wouldn't start otherwise.

  config.vm.provision :nixos, expression: {
    services: {
      nginx: {
        enable: true,
      }
    }
  }
❯ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'nixbox64'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: vm-nix_default_1574441637593_12507
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default:
    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    default:
    default: Inserting generated public key within guest...
    default: Removing insecure key from the guest if it's present...
    default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Running provisioner: nixos...
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

mv /tmp/vagrant-provision.nix /etc/nixos/vagrant-provision.nix

Stdout from the command:

Stderr from the command:
stefandeml commented 4 years ago

yeah, running into the same error on my end. Running provisioner: nixos fails for the example config in the repo. @zimbatm any pointer where to look to fix that issue?

stefandeml commented 4 years ago

Update:

Using the vagrant box on vagrantcloud "nixos/nixos-16.09-x86_64" instead of the one created by nixbox packer solved the issue. Hence I think it's a issue with nixbox and not this plugin. Any idea what could be the reason?

zimbatm commented 4 years ago

Is it possible that /etc/nixos doesn't exist in the new image? The plugin assumes that it's there:

https://github.com/nix-community/vagrant-nixos-plugin/blob/b79bac22e85c39f2eccdc0aad591794432e493f4/lib/vagrant-nixos/provisioner.rb#L94-L111

bbigras commented 4 years ago

/etc/nixos does exist if I check with vagrant ssh just after getting the error message:

image

zimbatm commented 4 years ago

What about /tmp/vagrant-provision.nix, is it still there?

Typically what I would do is edit the ruby code to add some puts debugging. It looks like line 103 succeeded and the file got uploaded. Then for some reason the mv command failed. It could be a number of issues.

You could change line 107 to add -v flag for more verbosity from the tool: comm.sudo("mv -v #{source} #{target}")

bbigras commented 4 years ago

What about /tmp/vagrant-provision.nix, is it still there?

Yes.

image

Can the script handle the sudo password? comm.sudo("echo test") doesn't work either.

bbigras commented 4 years ago

I seem able to run vagrant provision if I set NOPASSWD in the sudoer file.

zimbatm commented 4 years ago

that smells like a regression in the image. The vagrant user is supposed to have password-less sudo access.

zimbatm commented 4 years ago

the vagrant user is supposed to belong to the wheel group and that group is supposed to have NOPASSWD in the sudoers:

https://github.com/nix-community/nixbox/blob/12d37d11d1651293d6518ae1cb806c6e0f074b67/scripts/configuration.nix#L45-L75

stefandeml commented 4 years ago

This PR should fix the issue: https://github.com/nix-community/nixbox/pull/53

zimbatm commented 4 years ago

nice, thanks for debugging this!