1
0
Fork 0
mirror of https://github.com/ciderale/nixos-utm.git synced 2024-12-14 11:37:37 +00:00
Automate creation of UTM based NixOS VMs
Find a file
Alain Lehmann 140ee090f5 add UTM_CONFIG environment variable for VM config
this allows to define a custom nix configuration file
to set the UTM VM configuration parameters. The content
of this nix file is merged with the config.plist of the VM.
The merging is done using json representation.
2024-10-11 01:15:54 +02:00
example improve documentation 2023-10-15 23:19:22 +02:00
.envrc initial draft 2023-10-06 21:43:38 +02:00
.gitignore initial draft 2023-10-06 21:43:38 +02:00
flake.lock update flake lock: nixpkgs & nixos-anywhere 2024-10-10 22:41:03 +02:00
flake.nix add UTM_CONFIG environment variable for VM config 2024-10-11 01:15:54 +02:00
README.md add UTM_CONFIG environment variable for VM config 2024-10-11 01:15:54 +02:00
removeIso.osa automate setup process of utm nixos vm 2023-10-07 02:14:36 +02:00
setupVM.osa create VM completly with setupVM.osa 2023-10-15 18:08:02 +02:00
utm.config.nix add UTM_CONFIG environment variable for VM config 2024-10-11 01:15:54 +02:00

NixOS-UTM : Conveniently create UTM VM with NixOS

This repository provides a small wrapper around nixos-anywhere to automate creation of NixOS VMs on MacOS hosts using UTM with the Apple virtualization backend (supporting Rosetta2).

Using the apple virtualsation (insted of qemu) provides access to Rosetta2 and thus efficient x86_64 support within the VM. Unfortunately, the utmctl does not yet provide full functionality (e.g. ip-address) for the appble backend. That complicates automatic vm creation and this repo provides utilities to automate as much as possible for a simple automation setup.

How to create a VM

  • create a nix flake with a nixosConfiguration defined
    • the ./example folder provides a flake with minimal example config
    • use it with nix flake new -t github:ciderale/nixos-utm my-utm-vm
    • adjust ./configuration.nix (atleast set your ssh public key)
  • define an environment variable VM_NAME to name the UTM VM
    • maybe configure this env var within your project/system setup
  • (optionally) define an environment variable UTM_CONFIG to set UTM VM parameters
    • fallback to UTM_CONFIG=./utm.config.nix (which is merged using plutil)
  • kickoff the installation process with the following command
    • assuming your flake is the current directory . with config utm
export VM_NAME=myVM
nix run github:ciderale/nixos-utm#nixosCreate .#utm

Retrieve the VMs IP address

VM_NAME=myVM nix run github:ciderale/nixos-utm#nixosIP

This command uses the arp cache to lookup the ip address based on the mac address that is found in the VMs configuration folder.

How to rebuild the configuration for an existing configuration

VM_NAME=myVM nix run github:ciderale/nixos-utm#nixosDeploy .#utm

Some aspects that can be improved

  • Make VM configuration configurable (currently hardcoded in nixosCreate)
  • Improve example configuration for simpler onboarding
  • Provide utility to deploy an updated configuration
  • Directory sharing between VM and host system.
    • it's a UTM system configuration, not a VM configuration
    • uses some binary coded "bookmark" format