Difference between revisions of "Proxmox Linux Container"

From NixOS Wiki
Jump to: navigation, search
(Make it clearer where to find the system tarball)
Line 3: Line 3:
 
== Finding a container tarball ==
 
== Finding a container tarball ==
  
First, choose a channel in https://nixos.org/channels/. You will then need to either follow the <em>via Hydra evaluation XXXX</em> link, or go to the URL listed in the <tt>src-url</tt> file.
+
Go to https://hydra.nixos.org/project/nixos, choose a release (small ones don't have the tarball we need), and open its Jobs tab.
 
+
On that page, search for <strong>nixos.containerTarball</strong>, open the link corresponding to your architecture (probably x86_64). Choose the latest success and click on the number. That is the ID of the result. Under <em>Build products</em>, download the <strong>system-tarball</strong>, which will be named <tt>nixos-system-x86_64-linux.tar.xz</tt>.
On that page, use the search box to search for <strong>containerTarball.x86_64</strong>. In the results page, follow the link that is the ID of the result. Under <em>Build products</em>, download the <strong>system-tarball</strong>, which will be named <tt>nixos-system-x86_64-linux.tar.xz</tt>.
 
  
 
Note the Build ID, it will be used when renaming the tarball... right when it's downloaded:
 
Note the Build ID, it will be used when renaming the tarball... right when it's downloaded:
  
 
<pre>
 
<pre>
mv nixos-system-x86_64-linux.tar.xz nixos-18.03-default_$BUILDID_amd64.tar.xz
+
mv nixos-system-x86_64-linux.tar.xz nixos-$RELEASE-default_$BUILDID_amd64.tar.xz
 
</pre>
 
</pre>
  
Line 28: Line 27:
 
pct create 99999 \
 
pct create 99999 \
 
   --description nixos-template \
 
   --description nixos-template \
   local:vztmpl/nixos-18.03-default_$BUILDID_amd64.tar.xz \
+
   local:vztmpl/nixos-$RELEASE-default_$BUILDID_amd64.tar.xz \
 
   -ostype unmanaged \
 
   -ostype unmanaged \
 
   -net0 name=eth0 \
 
   -net0 name=eth0 \

Revision as of 18:23, 1 June 2020

With a small amount of work, it is possible to use NixOS as a LXC container under Proxmox.

Finding a container tarball

Go to https://hydra.nixos.org/project/nixos, choose a release (small ones don't have the tarball we need), and open its Jobs tab. On that page, search for nixos.containerTarball, open the link corresponding to your architecture (probably x86_64). Choose the latest success and click on the number. That is the ID of the result. Under Build products, download the system-tarball, which will be named nixos-system-x86_64-linux.tar.xz.

Note the Build ID, it will be used when renaming the tarball... right when it's downloaded:

mv nixos-system-x86_64-linux.tar.xz nixos-$RELEASE-default_$BUILDID_amd64.tar.xz

This is a proxmox convention, and is useful to follow.

Preparing the container

But first, you will need to upload the container tarball to the storage.

Then, once this is done, you will need to access the CLI for the proxmox host. SSH or the web CLI will be fine.

CLI operations

In the CLI, create a container using the following command. If created as a template, I recommend setting a memorable ID.

pct create 99999 \
  --description nixos-template \
  local:vztmpl/nixos-$RELEASE-default_$BUILDID_amd64.tar.xz \
  -ostype unmanaged \
  -net0 name=eth0 \
  -storage local-lvm

Note that in the previous command, the -ostype option is necessary; this way Proxmox will not try to do fancy stuff to the system.

The last step using the CLI, edit /etc/pve/lxc/99999.conf to add this line:

lxc.init.cmd: /init

Creating a template

It is not be possible to use the facilities to create a NixOS container under Proxmox. It is possible, though, to create a template that may be cloned as a base. In the GUI, with the container selected, click the More menu at the top, then Convert to template. Accept.

To create a new NixOS container, you can then clone the template instead of doing the preceding steps.

Expected issues

nixos-rebuild switch may fail with errors for special mount points. This does not look like it affects the container.

[root@nixos:/]# nixos-rebuild switch
building Nix...
building the system configuration...
activating the configuration...
setting up /etc...
mount: /dev: cannot remount devtmpfs read-write, is write-protected.
mount: /dev/pts: cannot remount devpts read-write, is write-protected.
mount: /dev/shm: cannot remount tmpfs read-write, is write-protected.
mount: /proc: cannot remount proc read-write, is write-protected.
mount: /run: cannot remount tmpfs read-write, is write-protected.
mount: /run/keys: cannot mount ramfs read-only.
mount: /run/wrappers: cannot remount tmpfs read-write, is write-protected.
setting up tmpfiles
warning: error(s) occurred while switching to the new configuration