Background:
- I'd like to use NixOS to manage a 'container' with some services (e.g. Solr) on my headless server.
- I'm currently running lxc, lxd and docker containers which is tech that I'm familiar with.
- I'm assuming Nix can provide similar experience: presumably a pure λ(nix-config) -> reproducible container.
a) LXC:
> lxc-create -t download -n my-container
> lxc-start -n my-container
> lxc-attach -n my-container
> lxc-destroy -n my-container
b) LXD:
> lxc launch ubuntu:20.04 my-container
> lxc start my-container
> lxc exec my-container /bin/bash
> lxc delete my-container
c) Docker:
> docker pull busybox
> docker run busybox
> docker image rm busybox
d) NixOS
> ?????
> ????
> ???
Most of these tools have some sort of quick getting started tutorial that get you up and running by copy pasting a few lines of code. NixOS doesnt.
I looked at several tutorials on how to get started with an image:
- https://github.com/brainrape/nixos-tutorial
- https://www.thedroneely.com/posts/running-nixos-linux-containers/
Apparently there's no pre-built or installable chroot/systemd-nspawn/lxc/container image.
Both tutorials require to fiddle with VirtualBox...
I can't run VirtualBox NixOS image with X-server on a my headless server.
Next I looked at:
It's just a huge wall of text explaining UEFI partitioning, formatting disks, booting from USB drives, etc.
Nothing about how to install it into a container.
This doesn't look like the document I'm looking for.
Next is:
Now that's more promising. At least it's short.
Too short.
It doesn't say what will happen when I run these commands - will it launch nuclear missiles?
It appears to be a shell script type install, and I don't know where it will install its stuff.
I won't be able to apt-get remove --purge
it later.
Let's try it out...
Since I don't know where this will lead to (i.e. is it irreversible), I'll create a LXD container and install Nix into it.
This is certainly not what I wanted, because I wanted NixOS image, not Ubuntu image with Nix, but at least it is reversible (I can delete the LXD image after finding out what it does).
Create a container and install Nix:
> lxc launch ubuntu:20.04 nix
> lxc exec nix /bin/bash
root@nix> sh <(curl -L https://nixos.org/nix/install) --daemon
...
Nope, it won't install as root. Let's try a as a normal user:
root@nix> su - ubuntu
ubuntu@nix> sh <(curl -L https://nixos.org/nix/install) --daemon
Then after a while:
---- sudo execution ------------------------------------------------------------
I am executing:
$ sudo HOME=/root /nix/store/4vz8sh9ngx34ivi0bw5hlycxdhvy5hvz-nix-2.3.7/bin/nix-env -i /nix/store/4vz8sh9ngx34ivi0bw5hlycxdhvy5hvz-nix-2.3.7
to installing a bootstrapping Nix in to the default Profile
sudo: setrlimit(RLIMIT_CORE): Operation not permitted
installing 'nix-2.3.7'
error: while setting up the build environment: mounting /proc: Operation not permitted
---- oh no! --------------------------------------------------------------------
Jeeze, something went wrong. If you can take all the output and open
an issue, we'd love to fix the problem so nobody else has this issue.
:(
We'd love to help if you need it.
If you can, open an issue at https://github.com/nixos/nix/issues
Or feel free to contact the team,
- on IRC #nixos on irc.freenode.net
- on twitter @nixos_org
ubuntu@nix>
It didn't work. Mounting '/proc' probably means that it wishes to run a container inside a container.
I wanted a pure NixOS container anyway, not Nix inside Ubuntu container.
> lxc stop nix
> lxc delete nix
Maybe I should get back to Google, or ask community.
Note, there was a
sudo: setrlimit(RLIMIT_CORE): Operation not permitted
issue with sudo inside container.Even after applying the following workaround
AzuraCast/AzuraCast@6046746
the result is exactly the same except for the
sudo: setrlimit(RLIMIT_CORE): Operation not permitted
not appearing in the nixos install output. Everything else is the same.