Open zimbatm opened 2 years ago
Well god damn this is cool. I'll have to give this a shot.
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.
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 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
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
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/
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.