Convert NixOS configuration into an image?

So we have nixos-container for generating a chroot container, pkgs.dockerTools.buildImage for building a Docker image with Nix expression, but is it possible to build an image with NixOS’s configuration?

For example, I was reading about services.vikunja, this configuration is well written, and to translate this into a docker image manually takes some work. I will be awesome if we can use that to create a docker image right away.

Not only would this make a deployment with Docker easy, and those images can be run on other distro as well?

2 Likes

You can have a look to Arion. It allows to run NixOS configuration in Docker with some constraints.

Yes actually I have tried this and asked the author directly. They don’t seem to have a NixOS module right now, and arion now is mainly used for deploying to Non-NixOS system, if I understand it correctly.

I’m also looking for doing this.

You have some new candidates to consider:

For some discussion: https://www.reddit.com/r/NixOS/comments/1bxn8l7/introducing_flakecontainers_a_simple_poc/

Basically, I’m looking for a way to create an OCI container with a specific user, and a specific home-manager configuration.

I tested multiple things, without luck so far.

I opened an issue here: Installation in an OCI container · Issue #5258 · nix-community/home-manager · GitHub

If you have a clue with that, just let me know.

I checked flake-containers, but this is not what I’m looking for. I’m looking for build OCI containers only, based on a NixOS configuration so I can create a user and install a Home Manager profile. I can’t believe why such a thing is so hard to achieve. I must be doing something wrong.

1 Like