erikarvstedt / extra-container

Run declarative NixOS containers without full system rebuilds

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

extra-container on non-NixOS

danbst opened this issue · comments

I'm documenting here what had to be done to launch container via extra-container on Ubuntu 17.10

  1. First, install from this repo doesn't work. I expected nix-env -if . to work here
  2. Running extra-container requires sudo. But due to bad sudo+Nix integration in Ubuntu, the command to run is more complicated:
$ sudo -E env PATH="$PATH" extra-container create path/to/container --start

I've made an alias alias sudo-extra-container='sudo -E env PATH="$PATH" extra-container' which solved a problem for me, but that wasn't obvious.
3. It depends on nixos-container, but I don't see reasons why it should. For example, restart command is handled by extra-container, but start is delegated to nixos-container. It is possible to add nixos-container as propagated build input, but nixos-container doesn't work great on non-NixOS (actually, doesn't work but I know folks did use it somehow).
4. The /etc/systemd-mutable should be /usr/lib/systemd/system on non-NixOS (see https://www.freedesktop.org/software/systemd/man/systemd.unit.html). Without that containers are not registered in systemd.

  1. Need create /etc/static/os-release file.
# mkdir /etc/static
# touch /etc/static/os-release

This is buggy situation in nixos container launch script (but it is invisible on NixOS, because this file already exists):

# ls -la /var/lib/containers/CONTAINER_NAME/etc/os-release
lrwxrwxrwx 1 root root 22 Oct  2 05:02 /var/lib/containers/CONTAINER_NAME/etc/os-release -> /etc/static/os-release

The link will work after bind-mount, but until bind mount active, it points to /etc/static/os-release in host system. NixOS contains that file, but other distros don't. [ -e ... ] detects invalid symlink as no file and succeeds

  • touch ... then fails
Oct 02 05:03:21 host systemd[1]: Stopped Container 'CONTAINER_NAME'.
Oct 02 05:03:21 host systemd[1]: Starting Container 'CONTAINER_NAME'...
Oct 02 05:03:21 host container CONTAINER_NAME[31290]: touch: cannot touch '/var/lib/containers/CONTAINER_NAME/etc/os-release': No such file or directory
Oct 02 05:03:21 host systemd[1]: container@CONTAINER_NAME.service: Main process exited, code=exited, status=1/FAILURE
Oct 02 05:03:21 host systemd[1]: Failed to start Container 'CONTAINER_NAME'.
Oct 02 05:03:21 host systemd[1]: container@CONTAINER_NAME.service: Unit entered failed state.
Oct 02 05:03:21 host systemd[1]: container@CONTAINER_NAME.service: Failed with result 'exit-code'.

The /etc/os-release issue should be nicely solved by NixOS/nixpkgs#35364

May also require a touch /nix/var/nix/daemon-socket if that doesn't exist for you.

Implemented in release 0.5.