nixpkgs/nixos/modules/virtualisation
Eelco Dolstra 9ee30cd9b5 Add support for lightweight NixOS containers
You can now say:

  systemd.containers.foo.config =
    { services.openssh.enable = true;
      services.openssh.ports = [ 2022 ];
      users.extraUsers.root.openssh.authorizedKeys.keys = [ "ssh-dss ..." ];
    };

which defines a NixOS instance with the given configuration running
inside a lightweight container.

You can also manage the configuration of the container independently
from the host:

  systemd.containers.foo.path = "/nix/var/nix/profiles/containers/foo";

where "path" is a NixOS system profile.  It can be created/updated by
doing:

  $ nix-env --set -p /nix/var/nix/profiles/containers/foo \
      -f '<nixos>' -A system -I nixos-config=foo.nix

The container configuration (foo.nix) should define

  boot.isContainer = true;

to optimise away the building of a kernel and initrd.  This is done
automatically when using the "config" route.

On the host, a lightweight container appears as the service
"container-<name>.service".  The container is like a regular NixOS
(virtual) machine, except that it doesn't have its own kernel.  It has
its own root file system (by default /var/lib/containers/<name>), but
shares the Nix store of the host (as a read-only bind mount).  It also
has access to the network devices of the host.

Currently, if the configuration of the container changes, running
"nixos-rebuild switch" on the host will cause the container to be
rebooted.  In the future we may want to send some message to the
container so that it can activate the new container configuration
without rebooting.

Containers are not perfectly isolated yet.  In particular, the host's
/sys/fs/cgroup is mounted (writable!) in the guest.
2013-11-27 17:14:10 +01:00
..
amazon-config.nix
amazon-image.nix Don't set an initial null root password for Amazon / VirtualBox images 2013-11-01 15:04:21 +01:00
containers.nix Add support for lightweight NixOS containers 2013-11-27 17:14:10 +01:00
ec2-data.nix Remove remaining references to Upstart 2013-10-31 13:26:06 +01:00
libvirtd.nix nixos/libvirtd-service: fix for dnsmasq (dir perms 700 -> 755) 2013-11-10 14:07:29 +01:00
nova-config.nix
nova-image.nix Rename environment.nix -> nix.package 2013-10-28 22:45:57 +01:00
nova.nix nixos: capitalize a bunch of service descriptions 2013-11-09 20:45:50 +01:00
qemu-opts
qemu-vm.nix nixos-rebuild build-vm: Ignore the user's LUKS devices 2013-10-29 13:31:01 +01:00
virtualbox-guest.nix Don't enable acpid for VirtualBox guests 2013-10-17 14:41:58 +02:00
virtualbox-image.nix Don't set an initial null root password for Amazon / VirtualBox images 2013-11-01 15:04:21 +01:00
xen-dom0.nix nixos: capitalize a bunch of service descriptions 2013-11-09 20:45:50 +01:00
xen-domU.nix