Incus: Difference between revisions
added install, initialize, network/firewall. cleaned up image and instance info. |
|||
Line 1: | Line 1: | ||
Incus is a next generation system container and virtual machine manager. It is a community driven alternative to Canonical's LXD. | Incus is a next generation system container and virtual machine manager. It is a community driven alternative to Canonical's LXD, created by those who started LXD. | ||
This document aims to provide NixOS specific information related to Incus. For non-NixOS specific documentation, please see the upstream documentation: https://linuxcontainers.org/incus/docs/main/ | |||
== NixOS | == Installation == | ||
The service can be enabled and started by adding the service to your NixOS configuration. It must still be initialized. | |||
virtualisation.incus.enable = true; | |||
To provide non-root access to the Incus server, you will want to add your user to the incus-admin group. Don't forget to logout and log back in. | |||
users.users.YOUR_USERNAME.extraGroups = ["incus-admin"]; | |||
You should now be able to use the incus client to talk to the server.<syntaxhighlight lang="shell-session"> | |||
[root@nixos:/etc/nixos]# incus version | |||
If this is your first time running Incus on this machine, you should also run: incus admin init | |||
To start your first container, try: incus launch images:ubuntu/22.04 | |||
Or for a virtual machine: incus launch images:ubuntu/22.04 --vm | |||
Client version: 6.0.0 | |||
Server version: 6.0.0 | |||
</syntaxhighlight> | |||
< | == Initialization == | ||
As you can see in the above code block, adding the Incus service will provide a working instance of the server, but is not sufficient on its own to have a complete setup. | |||
+-------------------------------+--------------+--------+---------------------------------------+--------------+-----------------+-----------+ | |||
| ALIAS | FINGERPRINT | PUBLIC | DESCRIPTION | ARCHITECTURE | TYPE | SIZE | | For more complex setups, please refer to https://linuxcontainers.org/incus/docs/main/howto/initialize/ | ||
+-------------------------------+--------------+--------+---------------------------------------+--------------+-----------------+-----------+ | |||
| nixos/23.11 (3 more) | | === Minimal === | ||
+-------------------------------+--------------+--------+---------------------------------------+--------------+-----------------+-----------+ | The simplest way to initialize, Incus will provide a basic directory backed storage pool and a bridged NAT network with DHCP. | ||
| nixos/23.11 (3 more) | | incus admin init --minimal | ||
=== Preseed === | |||
NixOS has an option for providing a preseed to Incus, as documented in the initialize link above. This is a declarative initialization, with the caveat that Incus preseed will never remove a resource created. Here is an example that is similar to the Minimal initialization option.<syntaxhighlight lang="nix"> | |||
virtualisation.incus.preseed = { | |||
networks = [ | |||
{ | |||
config = { | |||
"ipv4.address" = "10.0.100.1/24"; | |||
"ipv4.nat" = "true"; | |||
}; | |||
name = "incusbr0"; | |||
type = "bridge"; | |||
} | |||
]; | |||
profiles = [ | |||
{ | |||
devices = { | |||
eth0 = { | |||
name = "eth0"; | |||
network = "incusbr0"; | |||
type = "nic"; | |||
}; | |||
root = { | |||
path = "/"; | |||
pool = "default"; | |||
size = "35GiB"; | |||
type = "disk"; | |||
}; | |||
}; | |||
name = "default"; | |||
} | |||
]; | |||
storage_pools = [ | |||
{ | |||
config = { | |||
source = "/var/lib/incus/storage-pools/default"; | |||
}; | |||
driver = "dir"; | |||
name = "default"; | |||
} | |||
]; | |||
}; | |||
</syntaxhighlight> | |||
== Networking/Firewall == | |||
When using Incus on NixOS, nftables is required to ensure broadest compatibility with other services that manage firewall rules from release 24.05. Trying to use iptables will fail eval, and this can be fixed by switching to nftables and for simple firewalls should be a drop-in replacement for iptables. | |||
networking.nftables.enable = true; | |||
By default the NixOS firewall will block DHCP requests to the Incus network, meaning instances will not get an IPv4 address. The simplest fix for this is to mark the Incus bridged interface as trusted. This interface name should match the name given during initialization or configured through the incus command line. | |||
networking.firewall.trustedInterfaces = [ "incusbr0" ]; | |||
== NixOS Images == | |||
=== Pre-built Images === | |||
NixOS images are available at https://images.linuxcontainers.org/ providing VM and Container images for both stable and unstable NixOS.<syntaxhighlight lang="shell-session"> | |||
[root@nixos:/etc/nixos]# incus image list images:nixos | |||
+-------------------------------+--------------+--------+---------------------------------------+--------------+-----------------+-----------+----------------------+ | |||
| ALIAS | FINGERPRINT | PUBLIC | DESCRIPTION | ARCHITECTURE | TYPE | SIZE | UPLOAD DATE | | |||
+-------------------------------+--------------+--------+---------------------------------------+--------------+-----------------+-----------+----------------------+ | |||
| nixos/23.11 (3 more) | 1e606df4d91a | yes | Nixos 23.11 amd64 (20240521_01:02) | x86_64 | CONTAINER | 124.84MiB | 2024/05/21 00:00 UTC | | |||
+-------------------------------+--------------+--------+---------------------------------------+--------------+-----------------+-----------+----------------------+ | |||
| nixos/23.11 (3 more) | a96494ff3c46 | yes | Nixos 23.11 amd64 (20240521_01:02) | x86_64 | VIRTUAL-MACHINE | 452.43MiB | 2024/05/21 00:00 UTC | | |||
</syntaxhighlight> | |||
==== Creation ==== | |||
Container and VM images are built by Hydra as part of the [https://github.com/NixOS/nixpkgs/blob/master/nixos/release.nix NixOS release]. | |||
https://hydra.nixos.org/job/nixos/trunk-combined/nixos.lxdContainerImage.x86_64-linux | |||
https://hydra.nixos.org/job/nixos/trunk-combined/nixos.lxdVirtualMachineImage.x86_64-linux | |||
The LXC Image Server then consumes them and repackages them using their CI. | |||
Definition: https://github.com/lxc/lxc-ci/blob/main/jenkins/jobs/image-nixos.yaml | |||
CI: https://jenkins.linuxcontainers.org/job/image-nixos/ | |||
=== Custom Images === | |||
== NixOS Instances == | |||
To launch a new NixOS container use the following command. | |||
<pre> | <pre> | ||
incus launch images:nixos/unstable nixos -c security.nesting=true | |||
</pre> | </pre> | ||
A NixOS virtual machine is launched with the following. | |||
incus launch images:nixos/unstable nixos -c security.secureboot=false | |||
[[Category:Server]] | [[Category:Server]] | ||
[[Category:Container]] | [[Category:Container]] |
Revision as of 12:53, 21 May 2024
Incus is a next generation system container and virtual machine manager. It is a community driven alternative to Canonical's LXD, created by those who started LXD.
This document aims to provide NixOS specific information related to Incus. For non-NixOS specific documentation, please see the upstream documentation: https://linuxcontainers.org/incus/docs/main/
Installation
The service can be enabled and started by adding the service to your NixOS configuration. It must still be initialized.
virtualisation.incus.enable = true;
To provide non-root access to the Incus server, you will want to add your user to the incus-admin group. Don't forget to logout and log back in.
users.users.YOUR_USERNAME.extraGroups = ["incus-admin"];
You should now be able to use the incus client to talk to the server.
[root@nixos:/etc/nixos]# incus version
If this is your first time running Incus on this machine, you should also run: incus admin init
To start your first container, try: incus launch images:ubuntu/22.04
Or for a virtual machine: incus launch images:ubuntu/22.04 --vm
Client version: 6.0.0
Server version: 6.0.0
Initialization
As you can see in the above code block, adding the Incus service will provide a working instance of the server, but is not sufficient on its own to have a complete setup.
For more complex setups, please refer to https://linuxcontainers.org/incus/docs/main/howto/initialize/
Minimal
The simplest way to initialize, Incus will provide a basic directory backed storage pool and a bridged NAT network with DHCP.
incus admin init --minimal
Preseed
NixOS has an option for providing a preseed to Incus, as documented in the initialize link above. This is a declarative initialization, with the caveat that Incus preseed will never remove a resource created. Here is an example that is similar to the Minimal initialization option.
virtualisation.incus.preseed = {
networks = [
{
config = {
"ipv4.address" = "10.0.100.1/24";
"ipv4.nat" = "true";
};
name = "incusbr0";
type = "bridge";
}
];
profiles = [
{
devices = {
eth0 = {
name = "eth0";
network = "incusbr0";
type = "nic";
};
root = {
path = "/";
pool = "default";
size = "35GiB";
type = "disk";
};
};
name = "default";
}
];
storage_pools = [
{
config = {
source = "/var/lib/incus/storage-pools/default";
};
driver = "dir";
name = "default";
}
];
};
Networking/Firewall
When using Incus on NixOS, nftables is required to ensure broadest compatibility with other services that manage firewall rules from release 24.05. Trying to use iptables will fail eval, and this can be fixed by switching to nftables and for simple firewalls should be a drop-in replacement for iptables.
networking.nftables.enable = true;
By default the NixOS firewall will block DHCP requests to the Incus network, meaning instances will not get an IPv4 address. The simplest fix for this is to mark the Incus bridged interface as trusted. This interface name should match the name given during initialization or configured through the incus command line.
networking.firewall.trustedInterfaces = [ "incusbr0" ];
NixOS Images
Pre-built Images
NixOS images are available at https://images.linuxcontainers.org/ providing VM and Container images for both stable and unstable NixOS.
[root@nixos:/etc/nixos]# incus image list images:nixos
+-------------------------------+--------------+--------+---------------------------------------+--------------+-----------------+-----------+----------------------+
| ALIAS | FINGERPRINT | PUBLIC | DESCRIPTION | ARCHITECTURE | TYPE | SIZE | UPLOAD DATE |
+-------------------------------+--------------+--------+---------------------------------------+--------------+-----------------+-----------+----------------------+
| nixos/23.11 (3 more) | 1e606df4d91a | yes | Nixos 23.11 amd64 (20240521_01:02) | x86_64 | CONTAINER | 124.84MiB | 2024/05/21 00:00 UTC |
+-------------------------------+--------------+--------+---------------------------------------+--------------+-----------------+-----------+----------------------+
| nixos/23.11 (3 more) | a96494ff3c46 | yes | Nixos 23.11 amd64 (20240521_01:02) | x86_64 | VIRTUAL-MACHINE | 452.43MiB | 2024/05/21 00:00 UTC |
Creation
Container and VM images are built by Hydra as part of the NixOS release.
https://hydra.nixos.org/job/nixos/trunk-combined/nixos.lxdContainerImage.x86_64-linux
https://hydra.nixos.org/job/nixos/trunk-combined/nixos.lxdVirtualMachineImage.x86_64-linux
The LXC Image Server then consumes them and repackages them using their CI.
Definition: https://github.com/lxc/lxc-ci/blob/main/jenkins/jobs/image-nixos.yaml
CI: https://jenkins.linuxcontainers.org/job/image-nixos/
Custom Images
NixOS Instances
To launch a new NixOS container use the following command.
incus launch images:nixos/unstable nixos -c security.nesting=true
A NixOS virtual machine is launched with the following.
incus launch images:nixos/unstable nixos -c security.secureboot=false