Skip to content

Build and manage NixOS-based virtual machines on UTM without leaving the terminal

Notifications You must be signed in to change notification settings

schrenker/nix-factory

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nix-Factory: CLI-based Management of NixOS VMs for UTM.app

Overview

Nix-Factory is a Nix-based project for building and running NixOS virtual machines. It leverages nixos-generators to produce QEMU-compatible images, primarily for use with UTM.app on macOS.

Why

I am not happy with any solution for managing Virtual Machines on MacOS. Most of existing tools either focus on GUI, have limited scripting/CLI capabilities or are just weird gimmicks that use custom image format, without NixOS support.

Features

  • Build QCOW2 (and other formats supported by nixos-generators) VM images via nix flakes.
  • Manage UTM.app VMs through simple CLI scripts, without need to use GUI at all.
  • Preconfigured NixOS user with password and SSH key preinstalled (modifiable in configurations/base.nix).

Usage

Build an Image

Build image based on nixosConfiguration in flake.nix.

./scripts/build-vm.sh <MACHINE>
<MACHINE>
Name of nixosConfiguration (see flake.nix).

Start a Virtual Machine

Start a VM based on image built from nixosConfiguration. By default, machine will be named after an image it’s created from. Optionally provide unique name for the VM, so that multiple VMs can be created using the same image.

./scripts/start-vm.sh <MACHINE> [<NAME>]
<MACHINE>
Name of the nixosConfiguration built using build-vm.sh.
<NAME> (optional)
A unique identifier for the VM instance.

Stop and Delete a VM

./scripts/delete-vm.sh <NAME>
<NAME>
Name of the VM, matching <MACHINE> unless specified during startup.

Cleanup All VMs

Remove all UTM machines, built images, and unused Nix store references. Then run the nix garbage collector.

./scripts/cleanup.sh

Structure

flake.nix
Defines the configurations and flake outputs.
configurations/
Contains base.nix configuration for all machines, as well as additional specialized configurations.
scripts/
Scripts used to build images and to manage virtual machines.

Credits

About

Build and manage NixOS-based virtual machines on UTM without leaving the terminal

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published