Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
NixOS-generators – Collection of VM and Container disk image builders for NixOS (github.com/nix-community)
62 points by peter_d_sherman on March 26, 2024 | hide | past | favorite | 11 comments


This is one of the “magical” capabilities provided by Nix and NixOS imo.

I recently used this NixOS module to build a new machine as a Proxmox VMA all while sharing the common config with my existing NixOS machine. I then imported the VM into Proxmox, expanded the disk size, and it booted immediately! There were a few manual things I had to do to get secrets working, but end-to-end, it took me about 5 minutes.

You can do the exact same thing for other formats. For example, you could have a bootable installer ISO that takes your base config and adds specific tools on top that you’d want on a portable USB.


Related:

Building NixOS qcow2 images with flakes:

https://tarnbarford.net/journal/building-nixos-qcow2-images-...

Build a bare bones bootable nixos qcow2 image suitable for running with libvirt/qemu/kvm:

https://gist.github.com/tarnacious/f9674436fff0efeb4bb6585c7...

A Journey into Nix and NixOS (Building a QEMU image):

https://williamvds.me/blog/journey-into-nix/#:~:text=Buildin...

Setting up qemu VM using nix flakes:

https://gist.github.com/FlakM/0535b8aa7efec56906c5ab5e32580a...


Another note, NixOS containers with systemd-nspawn cpmpatibility: https://nixos.wiki/wiki/NixOS_Containers

There is a good blog post here about how these work: https://www.tweag.io/blog/2020-07-31-nixos-flakes/

And of course, it is just a tarball, so it works on every systemd based distro.


There's also this:

"Not-OS – NixOS-based OS generator that outputs an OS with 47MB squashfs":

https://news.ycombinator.com/item?id=34679031

https://github.com/cleverca22/not-os

For memory constrained VMs and containers based on NixOS...

Of course, even that isn't as small as Alpine's absolutely tiny 5MB Docker image:

https://hub.docker.com/_/alpine


I've recently been experimenting with nix generators. It's nice.

What's the most pleasant way to develop and build nix images if your dev env is a regular Linux distro without nix installed?

So far the least bad seems to be running Nixos in a VM with VS Code remote via SSH and scp'ing images around. At least quickemu makes getting the VM pleasant. But VMs are cumbersome.

Docker would be great, but nix from the official Docker container doesn't seem to like running as non-root, which means you can't use volume mounts for the code and change the user ID so that the file permissions are right from inside the container.


Nix generators works on regular Linux distros with nix installed.


This caught my attention, and now I want to dive into NixOS more. Can anyone suggest a solid set of starting resources for someone with a (probably overly complex) home lab and experience with macOS and Ubuntu/Debian?


I would recommend this as a starting point for learning about Nix and NixOS: https://zero-to-nix.com/

And this as a second reference: https://nix.dev/tutorials/first-steps/index.html


I’ve found it most helpful to review other people’s configurations to learn Nix.

Some specific ones I really like:

https://github.com/malob/nixpkgs

https://github.com/fufexan/dotfiles

I keep a not comprehensive GitHub Stars list of Nix stuff I find here if you want more:

https://github.com/stars/heywoodlh/lists/nix

If you aren’t familiar, Nix-Darwin allows you to codify your MacOS deployments in a fashion comparable to NixOS. As a huge Nix-Darwin user myself, I have found malob’s repo extremely helpful for ideas with MacOS configuration. Nix-Darwin has made me so happy as a MacOS user. :)

Some other unsolicited tips:

1. Start with Nix flakes for configuration

2. Invest in Home-Manager before NixOS or Nix-Darwin

3. Ask people for help in Matrix or Discourse — my experience is that Nix-related folk are very welcoming and understanding

Good luck!


You can use this repo to build a raspberry pi SD card image. It will build through an arm qemu instance, and works perfectly.


NIXOS, NIXOS, NIXOS!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: