Skip to content

msgilligan/nixos-lima

 
 

Repository files navigation

Run NixOS on a Lima VM

A NixOS flake for building a Lima-compatible system image.

This is a based on kasuboski/nixos-lima and there are about a half-dozen forks of that repo, but none of them (yet) seem to be making much of an effort to be generic/reusable, accept contributions, create documentation, etc. So I created this repo to try to create something that multiple developers can use and contribute to. (So now there are a half-dozen plus one projects 🤣 -- see xkcd "Standards")

There has been ongoing discussion in lima-vm/lima#430, and I have proposed there to create a "unified" project. If you have input or want to collaborate, please comment there or open an issue or pull request here. I'm also happy to archive this project and contribute to another one if other collaborators think that is a better path forward.

Currently, this flake supports building and booting a Lima NixOS image on both Linux and macOS and rebuilding NixOS from inside the VM. (I have not tested on x86, but it should work with minor tweaks.) Several of the existing forks contain features I would like to see integrated.

Design Goals

The following are the design goals that I think are important, but I'm definitely open to suggestions for changing these. (Just open an issue.)

  1. Nix flake that can build a bootable NixOS Lima-compatible image
  2. Be as generic and reusable by others as possible
  3. Nix modules for the systemd services that initialize and configure the system
  4. User customization of NixOS Lima instance is done separately from initial image creation
  5. Track the current nixos-unstable branch in Nix

Prerequisites

A working Nix installation capable of building Linux systems. This includes:

  • Linux system with Nix installed
  • Linux VM with Nix installed (e.g. under macOS)
  • macOS system with linux-builder installed via Nix Darwin

Flakes must be enabled.

Generating the image

nix build .#packages.aarch64-linux.img

If you built the image on another system:

mkdir result
# copy image to result/nixos.img

Running NixOS

limactl start --name=nixos nixos.yaml

limactl shell nixos

Rebuilding NixOS inside the Lima instance

# Using a VM shell, cd to this repository directory
nixos-rebuild switch --flake .#nixos --use-remote-sudo

Managing your NiXOS Lima VM instance

See the NixOS Lima VM Config Sample.

Fork and clone that repository, check it out either to your macOS host or to a directory within you NixOS VM instance. Then use:

nixos-rebuild switch --flake .#sample --use-remote-sudo

Or change the name sample to match the hostname of your NixOS Lima guest.

References

Credits

The unmodified, upstream README is in README_upstream.md.

Fixes/patches from:

About

Create a NixOS VM using Lima

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Nix 100.0%