Incus: Difference between revisions

Mel (talk | contribs)
m Fix minor typo. "intreface" -> "interface"
DHCP (talk | contribs)
m style fixes
 
Line 5: Line 5:
== Installation ==
== Installation ==
The service can be enabled and started by adding the service to your NixOS configuration. It must still be initialized.
The service can be enabled and started by adding the service to your NixOS configuration. It must still be initialized.
virtualisation.incus.enable = true;
<syntaxhighlight lang=nix>
networking.nftables.enable = true;
virtualisation.incus.enable = true;
networking.nftables.enable = true;
</syntaxhighlight>
 
See [[#Networking/Firewall]] for more information on the latter option.
See [[#Networking/Firewall]] for more information on the latter option.


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 reboot.
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 reboot.
users.users.YOUR_USERNAME.extraGroups = ["incus-admin"];
<syntaxhighlight lang=nix>
You should now be able to use the incus client to talk to the server.<syntaxhighlight lang="shell-session">
users.users.YOUR_USERNAME.extraGroups = ["incus-admin"];
</syntaxhighlight>
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
[root@nixos:/etc/nixos]# incus version
If this is your first time running Incus on this machine, you should also run: incus admin init
If this is your first time running Incus on this machine, you should also run: incus admin init
Line 29: Line 35:
=== Minimal ===
=== Minimal ===
The simplest way to initialize, Incus will provide a basic directory backed storage pool and a bridged NAT network with DHCP.  
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
 
<syntaxhighlight lang=console>
$ incus admin init --minimal
</syntaxhighlight>


=== Preseed ===
=== Preseed ===
Line 98: Line 107:
To launch a new NixOS container use the following command.
To launch a new NixOS container use the following command.


<pre>
<syntaxhighlight lang=shell-session>
incus launch images:nixos/unstable nixos -c security.nesting=true
$ incus launch images:nixos/unstable nixos -c security.nesting=true
</pre>
</syntaxhighlight>


A NixOS virtual machine is launched with the following.
A NixOS virtual machine is launched with the following.
incus launch --vm images:nixos/unstable nixos -c security.secureboot=false
 
<syntaxhighlight lang=console>
$ incus launch --vm images:nixos/unstable nixos -c security.secureboot=false
</syntaxhighlight>


== NixOS Images ==
== NixOS Images ==
Line 125: Line 137:


https://hydra.nixos.org/job/nixos/trunk-combined/nixos.incusVirtualMachineImage.x86_64-linux
https://hydra.nixos.org/job/nixos/trunk-combined/nixos.incusVirtualMachineImage.x86_64-linux


The LXC Image Server then consumes them and repackages them using their CI.
The LXC Image Server then consumes them and repackages them using their CI.
Line 139: Line 148:
=== VMs ===
=== VMs ===
All the necessary build infrastructure exists in nixpkgs to build custom images.
All the necessary build infrastructure exists in nixpkgs to build custom images.


Define some NixOS systems.<syntaxhighlight lang="nix">
Define some NixOS systems.<syntaxhighlight lang="nix">
Line 178: Line 185:
/nix/store/2snjw9y8brfh5gia44jv6bhdhmmdydva-tarball
/nix/store/2snjw9y8brfh5gia44jv6bhdhmmdydva-tarball


</syntaxhighlight>Finally, you can manually import into an Incus storage pool and used to launch instances.<syntaxhighlight lang="bash">
</syntaxhighlight>Finally, you can manually import into an Incus storage pool and used to launch instances.
<syntaxhighlight lang=console>
$ incus image import --alias nixos-gen/custom/jellyfin /nix/store/2snjw9y8brfh5gia44jv6bhdhmmdydva-tarball/tarball/nixos-system-x86_64-linux.tar.xz /nix/store/znk28bp34bycb3h5k0byb61bwda23q5l-nixos-disk-image/nixos.qcow2
$ incus image import --alias nixos-gen/custom/jellyfin /nix/store/2snjw9y8brfh5gia44jv6bhdhmmdydva-tarball/tarball/nixos-system-x86_64-linux.tar.xz /nix/store/znk28bp34bycb3h5k0byb61bwda23q5l-nixos-disk-image/nixos.qcow2
 
</syntaxhighlight>
 
To build and import the VM in one command, follow the steps below.
 
<syntaxhighlight lang=console>
 
 
</syntaxhighlight>To build and import the VM in one command, follow the steps below.<syntaxhighlight lang="bash">
$ incus image import --alias nixos-gen/custom/jellyfin $(nix build .#nixosConfigurations.vm.config.system.build.metadata --print-out-paths)/tarball/nixos-system-x86_64-linux.tar.xz $(nix build .#nixosConfigurations.vm.config.system.build.qemuImage --print-out-paths)/nixos.qcow2
$ incus image import --alias nixos-gen/custom/jellyfin $(nix build .#nixosConfigurations.vm.config.system.build.metadata --print-out-paths)/tarball/nixos-system-x86_64-linux.tar.xz $(nix build .#nixosConfigurations.vm.config.system.build.qemuImage --print-out-paths)/nixos.qcow2


# Image imported with fingerprint: ***
$ # Image imported with fingerprint: ***
</syntaxhighlight>You can verify the import with the commands below. <syntaxhighlight lang="bash">
</syntaxhighlight>
You can verify the import with the commands below.
<syntaxhighlight lang=shell-session>
$ incus image list nixos/custom/vm
$ incus image list nixos/custom/vm
+------------------------+--------------+--------+--------------------------------------------------+--------------+-----------+-----------+----------------------+
+------------------------+--------------+--------+--------------------------------------------------+--------------+-----------+-----------+----------------------+
Line 208: Line 215:


=== Containers ===
=== Containers ===
<syntaxhighlight lang="bash">
<syntaxhighlight lang="console">
$ nix build .#nixosConfigurations.container.config.system.build.squashfs --print-out-paths
$ nix build .#nixosConfigurations.container.config.system.build.squashfs --print-out-paths
/nix/store/24djf2qlpkyh29va8z6pxrqp8x5z6xyv-nixos-lxc-image-x86_64-linux.img
/nix/store/24djf2qlpkyh29va8z6pxrqp8x5z6xyv-nixos-lxc-image-x86_64-linux.img
Line 234: Line 241:
/run/current-system/sw/bin/vim
/run/current-system/sw/bin/vim


</syntaxhighlight>Or, the all in one command:<syntaxhighlight lang="bash">
</syntaxhighlight>Or, the all in one command:<syntaxhighlight lang="console">
incus image import --alias nixos/custom/vm $(nix build .#nixosConfigurations.vm.config.system.build.metadata --print-out-paths)/tarball/nixos-system-x86_64-linux.tar.xz $(nix build .#nixosConfigurations.vm.config.system.build.qemuImage --print-out-paths)/nixos.qcow2
$ incus image import --alias nixos/custom/vm $(nix build .#nixosConfigurations.vm.config.system.build.metadata --print-out-paths)/tarball/nixos-system-x86_64-linux.tar.xz $(nix build .#nixosConfigurations.vm.config.system.build.qemuImage --print-out-paths)/nixos.qcow2
</syntaxhighlight>
</syntaxhighlight>
[[Category:Server]]
[[Category:Server]]
[[Category:Container]]
[[Category:Container]]
[[Category:Virtualization]]
[[Category:Virtualization]]