nixbox icon indicating copy to clipboard operation
nixbox copied to clipboard

nixbox 18.09 not on Vagrant Cloud

Open MaCXyLo opened this issue 6 years ago • 40 comments

see here: https://app.vagrantup.com/nixos

MaCXyLo avatar Dec 26 '18 19:12 MaCXyLo

I ran into this as well, after using the instructions in the README, specifically: vagrant init nixos/nixos-18.09-x86_64 then vagrant up.

The solution, for now, seems to be to downgrade to one that is available: nixos/nixos-18.03-x86_64

BrianHicks avatar Jan 02 '19 21:01 BrianHicks

The main reason is that Hashicorp has stopped offering CI builders and other CIs don't support VirtualBox. On top of that I don't have VirtualBox installed on my system anymore.

zimbatm avatar Jan 03 '19 08:01 zimbatm

Does anyone know of a CI that offers support for VirtualBox?

zimbatm avatar Jan 03 '19 08:01 zimbatm

nixops supports deployment of virtualbox images. hydra is the build server of nixos. but i have no experience with both.

next question is, if it's a good idea, to create a chicken or the egg problem?...

gitlab also seems to offer support for virtualbox images using packer: https://gitlab.com/gitlab-org/gitlab-packer/commit/15a926b58205dfa2fc7cb8bb8e166d742f4015ba

MaCXyLo avatar Jan 06 '19 17:01 MaCXyLo

Following on that link, looks like GitLab stopped using packer to build images: https://gitlab.com/gitlab-org/gitlab-ce/issues/164#note_75698

Maybe we should just generate the images with Nix directly instead of using Packer, it's not that hard as well. The only difficult thing is to wrap the vagrant config properly on the output. With Nix it's possible to generate VirtualBox images without having VirtualBox installed on the host.

zimbatm avatar Jan 08 '19 14:01 zimbatm

Is there a solution for this issue?

wpoosanguansit avatar Jan 14 '19 04:01 wpoosanguansit

something like https://github.com/nix-community/nixos-generators could be a good replacement. What's left is to wrap the output in a format that Vagrant can understand.

zimbatm avatar Jan 15 '19 15:01 zimbatm

@zimbatm I have VirtualBox installed on my system, and I wouldn't mind supporting this effort for future versions of NixOS as well.

Let me know what's involved in publishing these images to the https://app.vagrantup.com/nixos repo.

gurjeet avatar Mar 10 '19 11:03 gurjeet

Thanks for the offer @gurjeet. The best way forward would be to generate the images using Nix instead. Once that is done it will be possible to push them using the CI directly.

The image would include the vagrant.nix nixos module and output a OVA file, which is then wrapped in a .tar.gz with the metadata packed with it. The package format is described over here: https://www.vagrantup.com/docs/boxes/format.html

zimbatm avatar Mar 14 '19 21:03 zimbatm

I just made a PR, hopefully it will be a bit clearer: https://github.com/nix-community/nixos-generators/pull/22

If that works, then we can deprecate this project and then create a new one to periodically publish the Vagrant boxes

zimbatm avatar Mar 14 '19 22:03 zimbatm

@zimbatm I'm new to NixOS in general, and haven't used nix-generators before. How should I test your patch to that repo.

I am on macOS 10.13.6, and have nix(-darwin) installed. I have cloned the nixis-generators repo, and in that directory executing./nixos-generate --list shows vagrant as one of the formats.

The next step is to provide a configuration.nix to specify the NixOS derivation I need. I don't see a suitable one on my macOS. Can you please suggest which one I should use.

gurjeet avatar Mar 15 '19 06:03 gurjeet

Yes that's a good start.

The principle for testing would be to run ./nixos-generate -f vagrant, get the .box image and try to start it with vagrant somehow (I think vagrant import is needed to import the box). This will fail because the format is probably wrong.

Once you have that test phase working, download one of the original .box files, unpack it with tar and look at the differences. The metadata file needs to be completed, the .ova file name needs to be fixed I guess. Then open formats/vagrant.nix and fix the build instructions to match that.

If that's too much low-level for you, ping me on IRC and I can walk you through it a bit more.

zimbatm avatar Mar 15 '19 13:03 zimbatm

@zimbatm serait-il possible d'enlever le postprocessor "vagrant-cloud" des fichiers json puisqu'apparemment cela ne sert plus à rien ? Si ok je peux pousser un tel changement.

PierreR avatar Apr 11 '19 13:04 PierreR

sounds good @PierreR

zimbatm avatar Apr 16 '19 08:04 zimbatm

fixed in dfc1beca4bef917756f2c9f2a7a7a4abdfbcfa47

zimbatm avatar Apr 16 '19 08:04 zimbatm

@zimbatm you also want to remove the vagrant box post-processors ? It was useful for me to create a vagrant box compatible with virtualbox. FWIW I don't use this post-processors with vmware because AFAIK there is no good free vagrant plugin for vmware.

PierreR avatar Apr 16 '19 10:04 PierreR

The project is about creating vagrant boxes and adds all the cruft necessary for that to work like the vagrant users, a bunch of system packages... If all you want is to generate a VM image then it's probably better to use the nixos-generators project.

zimbatm avatar Apr 16 '19 12:04 zimbatm

The project is about creating vagrant boxes

I was just trying to point it out that dfc1bec is removing the creation of such a vagrant box

PierreR avatar Apr 16 '19 15:04 PierreR

woops, reverted. I don't see the vagrant-cloud post-processor

zimbatm avatar Apr 16 '19 22:04 zimbatm

... getting back to the ideal world I am trying to create for myself.

The command you suggested fails with the following error. I had a look at the patch before running the command, and the contents of formats/vagrant.nix seem to imply that the nixos-generate command needs to be executed on a Linux system.

$ ./nixos-generate -f vagrant
error: assertion failed at /nix/store/v6aja9ar864688529ayznix8mvv3ih10-nixpkgs-19.09pre184256.5b7e3718ee3/nixpkgs/pkgs/os-specific/linux/kernel/generic.nix:56:1
(use '--show-trace' to show detailed location information)

EDIT: To clarify a bit more, the line 56 in that file is asserting this:

assert stdenv.isLinux;

gurjeet avatar Jun 30 '19 05:06 gurjeet

Oh right, the project doesn't cross-compile right now, it has to be executed on a linux machine

zimbatm avatar Jun 30 '19 22:06 zimbatm

Does anyone want to try out https://github.com/nix-community/nixos-generators/pull/50 ? You will have to also checkout nixpkgs to the associated PR and then build the .box file

zimbatm avatar Dec 19 '19 22:12 zimbatm

@zimbatm, I'd like to try that PR, but it's not clear to me how to do it. Is it enough to clone your nixos-generators fork?

LucianU avatar Feb 05 '20 06:02 LucianU

Clone https://github.com/nix-community/nixos-generators/pull/50 and https://github.com/NixOS/nixpkgs/pull/76071

Then in the nixos-generators, override the configuration.nix to

{ config, lib, pkgs, modulesPath, ... }:
{
  documentation.man.enable = false;
  documentation.nixos.enable = false;
  sound.enable = false;
}

Finally run ./nixos-generators -I nixpkgs=../path/to/nixpkgs-clone -f vagrant-virtualbox`.

At the end if should give you a vbox file that you can import into virtualbox and try out.

zimbatm avatar Feb 05 '20 09:02 zimbatm

I'm getting this error

./nixos-generate -I nixpkgs=../nixpkgs/ -f vagrant-virtualbox
error: attribute 'vagrantVirtualbox' in selection path 'config.system.build.vagrantVirtualbox' not found

I'm running on a Mac, btw.

LucianU avatar Feb 06 '20 06:02 LucianU

thanks, fixed in https://github.com/NixOS/nixpkgs/pull/76071/commits/686125dbf9e1b5e933d3e74a7843bd9b1939d272

You will need a Linux remote builder to produce a compatible image. Do you know how to set that up?

zimbatm avatar Feb 06 '20 11:02 zimbatm

Do you mean I can only run the command on Linux? I could do it in a VM, if that's possible.

LucianU avatar Feb 06 '20 14:02 LucianU

You can run the command on macOS if you have a Linux remote builder machine setup. You will have to add ./nixos-generate -I nixpkgs=../nixpkgs/ -f vagrant-virtualbox --system linux-x86_64. Or run it in a VM that works too.

zimbatm avatar Feb 06 '20 20:02 zimbatm

I tried building inside a NixOS VM managed with VirtualBox and I got this error:

WARNING: Image format was not specified for 'nixos.raw' and probing guessed raw.
         Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
         Specify the 'raw' format explicitly to remove the restrictions.
qemu-system-x86_64: cannot set up guest memory 'pc.ram': Cannot allocate memory
builder for '/nix/store/jpnka8baajbkkazqpqd40v7sxzy0g65s-nixos-ova-20.03.git.686125d-x86_64-linux.drv' failed with exit code 1
cannot build derivation '/nix/store/q76pbx6gfmhv976kw1gppy9nrxyar0xk-virtualbox-vagrant.box.drv': 1 dependencies couldn't be built
error: build of '/nix/store/q76pbx6gfmhv976kw1gppy9nrxyar0xk-virtualbox-vagrant.box.drv' failed

I think that's because the VM is managed by VirtualBox.

Next, I tried on a DigitalOcean instance running Ubuntu. I got this error:

error: a 'x86_64-linux' with features {kvm} is required to build '/nix/store/jpnka8baajbkkazqpqd40v7sxzy0g65s-nixos-ova-20.03.git.686125d-x86_64-linux.drv', but I am a 'x86_64-linux' with features {benchmark, big-parallel, nixos-test}

LucianU avatar Feb 07 '20 07:02 LucianU

I'm afraid there are going to be many rounds to trial.

For the first issue, I think giving more RAM to the VirtualBox VM should solve it.

The second issue is because the Nix relies on KVM to build the image. Most hosting providers don't allow nested virtualization. I know Google Cloud or Azure do propose that option.

zimbatm avatar Feb 07 '20 11:02 zimbatm