Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow to prepare the VMWare image #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

zimbatm
Copy link

@zimbatm zimbatm commented Oct 25, 2021

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.

@mitchellh
Copy link
Owner

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

@fud
Copy link
Contributor

fud commented Dec 15, 2021

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.

@zimbatm
Copy link
Author

zimbatm commented Dec 15, 2021

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 .

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.
@lucamaraschi
Copy link
Contributor

@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

@zimbatm
Copy link
Author

zimbatm commented Dec 21, 2021

First, we need to add a GHA to the repo. So I created #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
Copy link
Author

zimbatm commented Dec 21, 2021

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/

jwieringa added a commit to jwieringa/nixos-config that referenced this pull request Dec 9, 2022
These configurations were copied[1] and heavily modified.
The general modification strategy was to remove as much
as I could without breaking things. Later, I'll add
customizations back go the nixos configurations.

The VMware build comes from comments[2]. This commit tests
if the vmware build works. I am editing from a Mac, so
I am relying on Github actions to test the nixos and
vmware artifact build.

References:
1. https://github.com/mitchellh/nixos-config/tree/01fcaea3bdcd47540da39446d80e85d042a70cc1
2. mitchellh/nixos-config#1
@jtara1
Copy link

jtara1 commented Feb 22, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants