nixbox
nixbox copied to clipboard
nixbox 18.09 not on Vagrant Cloud
see here: https://app.vagrantup.com/nixos
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
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.
Does anyone know of a CI that offers support for VirtualBox?
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
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.
Is there a solution for this issue?
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 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.
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
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 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.
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 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.
sounds good @PierreR
fixed in dfc1beca4bef917756f2c9f2a7a7a4abdfbcfa47
@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.
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.
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
woops, reverted. I don't see the vagrant-cloud post-processor
... 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;
Oh right, the project doesn't cross-compile right now, it has to be executed on a linux machine
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, 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?
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.
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.
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?
Do you mean I can only run the command on Linux? I could do it in a VM, if that's possible.
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.
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}
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.