nixos-config icon indicating copy to clipboard operation
nixos-config copied to clipboard

allow to prepare the VMWare image

Open zimbatm opened this issue 4 years ago • 7 comments

This is more of a showcase of a feature which I really like with NixOS.

If the CI or another machine has Nix installed, it's possible to generate a new VMDK directly from the NixOS configuration. Building and copying the VMDK would replace almost all the bootstrap steps from the video. A similar technique is also possible to generate AMIs and other system images from the same config.

I wasn't able to test this unfortunately because I don't have VMWare installed. You might have to set a password to the user using the NixOS config as well in order to be able to login.

zimbatm avatar Oct 25 '21 21:10 zimbatm

Well god damn this is cool. I'll have to give this a shot.

mitchellh avatar Oct 26 '21 16:10 mitchellh

I tried this - does this require nixos to build? I tried standard nix on my mac and it didn't work, but this would be a much easier way.

fud avatar Dec 15 '21 01:12 fud

There is a bit of a bootstrap problem because you need a Linux machine with Nix installed to generate the image.

One way to work around the issue is to use GitHub Actions to build and push the VM. Or you can install Nix on your macOS, and set up a Nix remote builder like https://nixbuild.net .

zimbatm avatar Dec 15 '21 12:12 zimbatm

@zimbatm do you have any example of how the GH action would look like?This could really create pre-baked images , making the whole re-produceability and idempotency phenomenal

lucamaraschi avatar Dec 19 '21 05:12 lucamaraschi

First, we need to add a GHA to the repo. So I created https://github.com/mitchellh/nixos-config/pull/14

Then append the following steps to the action (make sure to fix the indent so it's the same as the other steps):

- run: nix build .#vmwareImage
- uses: actions/upload-artifact@v2
  with:
    name: vmware
    path: ./result/*.vmdk

zimbatm avatar Dec 21 '21 08:12 zimbatm

Note that this approach is also applicable to building VirtualBox, Qemu, Vagrant, AMIs, ... by including the right NixOS module. It takes a bit of fiddling and reading the code still, but here is a good inspiration source: https://github.com/nix-community/nixos-generators/

zimbatm avatar Dec 21 '21 08:12 zimbatm

I was able to build a qcow2 image with minimal nix config using

nix-build '<nixpkgs/nixos>' -A config.system.build.qcow2 --arg configuration "{ imports = [ ./build-qcow2.nix ]; }"

where the nixos config for the build and for the guest OS are defined here

jtara1 avatar Feb 22 '24 01:02 jtara1