Browse Source

NixOS LXC: Minor changes

main
Victor Roest 2 years ago
parent
commit
fd6ff7f617
Signed by: 0x76 GPG Key ID: A3923C699D1A3BDA
  1. 26
      content/posts/proxmox-nixos-lxc.md

26
content/posts/proxmox-nixos-lxc.md

@ -9,9 +9,10 @@ categories:
- tutorial
---
This tutorial will go through on how to install NixOS as an LXC container inside of proxmox.
This tutorial will explain on how to install NixOS as an LXC container inside of proxmox.
Do be warned that this setup isn't entirely stable or supported.
## Getting the container tarball
# Getting the container tarball
Go to the pipeline for the [NixOS 20.09 Container Tarball][nixos-tar]
Then click on the latest successful build and download the corresponding `.tar.xz`.
{{< img path="images/nixos-buildproduct.png" >}}
@ -21,11 +22,11 @@ After it's downloaded we should rename the file to follow proxmox conventions (r
mv nixos-system-x86_64-linux.tar.xz nixos-$RELEASE-default_$BUILDID_amd64.tar.xz
```
### Uploading to proxmox
## Uploading to proxmox
Uploading it to proxmox is quite easy just go to your storage,
most likely called "local" then in "CT Templates" and click on upload and upload the tarball.
most likely called "local" then in "CT Templates" and click on upload and upload the tarball.
## Creating the container
# Creating the container
To create the container on proxmox we need to either `ssh` into it or use the web shell.
After in a shell on the proxmox host execute the following command. But, make sure you understand what the options
do before executing it. You can see the [proxmox docs][proxmox-lxc] if you are unsure.
@ -43,7 +44,7 @@ pct create $(nextid) \
after running this the container should show up in the Proxmox Web UI.
### Fix LXC config
## Fix LXC config
After creating the container we need to make a simple edit to the lxc config file located in `/etc/pve/lxc/$ID.conf`,
`$ID` being the ID you passed in the previous step, if unsure you can check the web UI.
@ -53,15 +54,15 @@ lxc.init.cmd: /init
```
This will point proxmox to the correct init binary.
### Fix Network settings
## Fix Network settings
If you didn't specify a full network configuration during container creation you must now
do so in the web UI or else the container won't start. The easiest being to just set ipv4 and ipv6 to dhcp.
### In-Container tweaks
## In-Container tweaks
Now you can finally start up the container! But we are not done yet, we need to set some minor settings
to make NixOS play nice with the fact that it is running inside of an lxc container.
#### /proc fix
### /proc fix
For some reason `/proc` is mounted with (to NixOS) unexpected permissions to fix this we need to
run the following:
```bash
@ -69,14 +70,14 @@ mkdir -p /mnt/proc
mount -t proc proc /mnt/proc
```
#### Populate Nixpkgs
### Populate Nixpkgs
`nixpkgs` isn't properly initialized when booting a fresh container, which would result in errors when running other
nix commands, to fix this simply run:
```bash
nix-channel --update
```
#### configuration.nix tweaks
### configuration.nix tweaks
Finally we will add some tweaks inside of `/etc/nixos/configuration.nix`. The first one being simply making
the previously done `/proc` hack permanent, and the second one suppresses some annoying systemd service warnings.
```nix
@ -98,7 +99,7 @@ the previously done `/proc` hack permanent, and the second one suppresses some a
];
```
## Expected Errors
# Expected Errors
As this setup is fairly unconvential there are some errors that will occur when running nix,
especially `nixos-rebuild switch`. However as far as I can tell these don't seem to pose any real problem.
@ -122,7 +123,6 @@ setting up tmpfiles
fchownat() of /run/keys failed: Read-only file system
fchownat() of /run/keys failed: Read-only file system
warning: error(s) occurred while switching to the new configuration
nixos-rebuild switch 14.80s user 12.45s system 17% cpu 2:38.52 total
```
Some (or all) of these errors can be fixed by running a privileged and apparmor unconstrained container,

Loading…
Cancel
Save