Skip to content

Instantly share code, notes, and snippets.

@pkese
Last active July 25, 2020 23:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pkese/32f9da925224f36bba53d4c2618c7624 to your computer and use it in GitHub Desktop.
Save pkese/32f9da925224f36bba53d4c2618c7624 to your computer and use it in GitHub Desktop.
My NixOS experience

My first steps with NixOS

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.

Ideally there'd be a short getting started tutorial. My familiarity is:

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.


So what I did...

I looked at several tutorials on how to get started with an image:

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.

@pkese
Copy link
Author

pkese commented Jul 25, 2020

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.

@pkese
Copy link
Author

pkese commented Jul 25, 2020

I also tried following https://www.thedroneely.com/posts/running-nixos-linux-containers/
and used nixos:release-20.03:nixos.containerTarball.x86_64-linux from https://hydra.nixos.org/job/nixos/release-20.03/nixos.containerTarball.x86_64-linux
instead of rolling my own image (due to the chicken and egg problem)
but that container failed to boot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment