Nixos base or toolbox container

I am a fan of toolbox (a nice way of running/testing other distros (and different versions) locally). ((Unfortunately the version of toolbox in nixpkgs is a bit old, though distrobox is fresh and does similar things.))

I have been wondering for a while: why there is no base nixos container?
I get that that might not be very “nix idiomatic”… but useful nevertheless for non-nixos users. I guess the nix container (nixos/nix) is somewhat close,
but I would like to have a nixos/nixos:25.05 container available say.

Has anyone tried to make a nixos toolbox (or base) container image: I think that would be quite useful and a simple “gateway drug” for nixos. (Sure, I could try to roll my own, but bootstrapping a container image by hand is also somewhat non-trivial, and having an official image like most distros do seems meaningful to have.)

I suppose a follow-up question: is there something like a nixos-bootstrap tool for generating a bootstrap tarball or something?

(In Fedora for example we are now using Kiwi to generate our OS container and installation images.)

Also nerd sniping, but coming from other distros, it is extremely surprising that no standard nixos container image exists. ;o)
But I get that the philosophy is “containers should be single service”… but that is not the use-case I am interested in. I want a nixos container as a kind of distro “playground”.

I suppose the nix container could a reasonable starting point, I am just not well versed in how to go from there.

Are you looking to build a custom image from a NixOS config, via system.build.images.lxc or similar? Or are you interested in pre-built images, like the containerTarball images Hydra builds?

Ideally I would like to build an OCI nixos container directly with nix: is that easy to do?

you mean this?

you could also experiment building VMs from nixos-rebuild build-vm --flake <flake>, which can also contain the containers

Creating images with Nix?

1 Like

@rhendric Thanks that looks good and helpful.

But is there something “nixos canonical” I should populate it with?

Anyway I will try to give it a go.

There is this for building NixOS docker images too. I think this might actually be closer to what you want.

1 Like

I put up a gist: nixos container · GitHub
The image tarball is about 86MB, which seems okay (including nix).

I can’t say it is all beautiful but it seems to do roughly what I had in mind, at least for v0.
How can it be improved? Perhaps I should just paste here…

Maybe I need to look closer at dockerTools, etc.
Hoping for some better abstracts without too much bloat.

Okay but erm… I guess the nix container may be better or already does all of what my experiment does and more - and I found the docker.nix, which is more configurable and complete of course. Haven’t quite worked out yet exactly how it is used to build the offficial images, but the manual installation does reference docker.nix

Ahhh but the nix container is about double the size for mine, probably because I cut out python and perl.