Skip to content
Tech News
← Back to articles

I can haz smoller NixOS ISOs?

read original more articles
Why This Matters

This article highlights how NixOS enables users to create minimal and customizable ISO images, making it easier to deploy or distribute tailored Linux environments without unnecessary components. This flexibility is significant for developers and system administrators seeking lightweight, portable, and adaptable OS images for diverse use cases.

Key Takeaways

In which I painstakingly remove functionality from a Linux live image. Like a normal person.

But first, I can haz ISO at all

One of NixOS' cooler party tricks is that you can trivially take some configuration and run it as a virtual machine (VM). nixos-rebuild build-vm will give you one for your system configuration . But you can also do it for any given configuration you want, system or not!

let pkgs = import ( fetchTarball { url = "https://github.com/NixOS/nixpkgs/archive/567a49d1913ce81ac6e9582e3553dd90a955875f.tar.gz" ; sha256 = "1vq77hlx8mi3z03pw2nf6r5h7473r1p9yxyf58ym3fh01zppmfln" ; }) {}; in pkgs . nixos { system . stateVersion = "26.05" ; services . getty . autologinUser = "root" ; }

That's enough to get a minimal VM, you can run it yourself with $(nix-build basic-vm.nix --attr vm --log-format bar --no-out-link)/bin/run-nixos-vm .

This will create a "thin" VM: there's a disk image, but it only contains the files you've made yourself once you're inside of the VM. Everything else (cough /nix/store ) gets mounted in from your host OS instead.

And that's great when it fits, but sometimes we just need something a bit more normal. Something we can just run in libvirt , or even ship off to some remote host that might not have Nix. It might not even run Linux at all. Hell, there might not even be a hypervisor!

In short, I just want a damn ISO.

Thankfully, NixOS still has my back here:

let pkgs = import ( fetchTarball { url = "https://github.com/NixOS/nixpkgs/archive/567a49d1913ce81ac6e9582e3553dd90a955875f.tar.gz" ; sha256 = "1vq77hlx8mi3z03pw2nf6r5h7473r1p9yxyf58ym3fh01zppmfln" ; }) {}; in pkgs . nixos ({ lib , ... }: { system . stateVersion = "26.05" ; services . getty . autologinUser = "root" ; imports = [ " ${pkgs . path} /nixos/modules/installer/cd-dvd/iso-image.nix" ]; image . baseName = lib . mkForce "nixos" ; })

... continue reading