Install Incus on Nixos
Contents
Incus, a manager and hypervisor for system containers (LXC) and virtual machines (QEMU), is an excellent tool for managing and orchestrating your applications and services. It is a fork of LXD by the original maintainers.
I found the documentation regarding NixOS lacking and thought I should put it somewhere for future reference. If you have experience with LXD, it will mostly be similar but expect things to get different as time passes.
Installation
Incus is already present in nixpkgs
and can be installed by adding
|
|
to your configuration.nix
. Consider adding yourself to incus-admin
group to avoid using sudo
every time. It can be done by
|
|
Of course, replace USER
with your username.
You need IP forwarding for NAT’ing to work
|
|
Enable kernel module for IP forwarding to work
|
|
Set up a bridge
|
|
This is used to provide NAT’d internet to the guest. It is manipulated directly by incus, so no need to specify any bridged interfaces here.
Add firewall rules to enable networking in the container
|
|
Incus on NixOS dropped iptables
support and recommends using nftables
. Enable nftables
and add incusbr0
to trusted interfaces.
|
|
Enable lxcfs to use it
|
|
Now switch to the new configuration with
|
|
Setting up incus
Incus requires initial setup for networking and storage. It can be done interactively by running
|
|
List all available images
|
|
Create a new image alpine
based on Alpine Linux
|
|
Interact with the newly created image
|
|
This will drop you in an ash
shell in the container.
You can copy containers by running
|
|
List containers
|
|
Stop container
|
|
Delete container
|
|
Configuration
Launch a new container with resource constrants
|
|
Check configuration
|
|
Update configuration
|
|
Interaction
Run arbitrary commands
|
|
Pull a file from container
|
|
Push file back to the container
|
|
Snapshots
Create a snapshot
|
|
Restore the container to the snapshot
|
|
Delete the snapshot
|
|
References
Author Aditya
LastMod 2024-03-16 (c9126cd)