What is the best way to run nixos in a container?

For educational purposes I would like to run nixos in a container with the possibility to run nix build inside a container. With that option students should solve “quizzes” in form of low-complexity nixos configurations.

With nixos containers its possible to build a container from a configuration.nix file but not to build it inside. Although the build command is available, it says error bc of write protected file system. Is that because it attemts to write to the nix store of the host machine? And would somebody know a work arround?

And the nixos official docker container is just using the nix package manager on a alpine distro is that correct or are there other container builds?

Best David

It’s more of a full management solution, but we have decent support for Incus either on a NixOS host or as container instance.

Thats a great solution thx!