tfc / nspawn-nixos

Accompanying Code for Nixcademy.com Blog Article
https://nixcademy.com/2023/08/29/nixos-nspawn/
42 stars 6 forks source link

Can not add on Linux AMI 2023, Linux AMI 2 and Ubuntu 22.04 on AWS #2

Open YordanCheyrekov opened 10 months ago

YordanCheyrekov commented 10 months ago

On Amazon Linux 2023 do not start to download at all; machinectl pull-tar https://github.com/tfc/nspawn-nixos/releases/download/v1.0/nixos-system-x86_64-linux.tar.xz nixos --verify=no Failed to transfer image: The name is not activatable

On Amazon Linux AMI 2 : machinectl pull-tar https://github.com/tfc/nspawn-nixos/releases/download/v1.0/nixos-system-x86_64-linux.tar.xz nixos --verify=no Enqueued transfer job 3. Press C-c to continue download in background. Pulling 'https://github.com/tfc/nspawn-nixos/releases/download/v1.0/nixos-system-x86_64-linux.tar.xz', saving as 'nixos'. tar: nix/store/00nz390ib96gqzhh4kri93v9ry9pgflq-unit-systemd-update-utmp.service/systemd-update-utmp.service: Cannot open: Permission denied tar: nix/store/022qyk34rpid0j248p00arjy1v5l5f10-system-units/-.slice: Cannot open: Permission denied tar: nix/store/022qyk34rpid0j248p00arjy1v5l5f10-system-units/audit.service: Cannot open: Permission denied tar: nix/store/022qyk34rpid0j248p00arjy1v5l5f10-system-units/autovt@.service: Cannot open: Permission denied tar: nix/store/022qyk34rpid0j248p00arjy1v5l5f10-system-units/basic.target: Cannot open: Permission denied tar: nix/store/022qyk34rpid0j248p00arjy1v5l5f10-system-units/basic.target.wants: Cannot mkdir: Permission denied tar: nix/store/022qyk34rpid0j248p00arjy1v5l5f10-system-units/basic.target.wants: Cannot mkdir: Permission denied tar: nix/store/022qyk34rpid0j248p00arjy1v5l5f10-system-units/basic.target.wants/audit.service: Cannot open: No such file or directory tar: nix/store/022qyk34rpid0j248p00arjy1v5l5f10-system-units/bluetooth.target: Cannot open: Permission denied tar: nix/store/022qyk34rpid0j248p00arjy1v5l5f10-system-units/console-getty.service: Cannot open: Permission denied tar: nix/store/022qyk34rpid0j248p00arjy1v5l5f10-system-units/console-getty.service.d: Cannot mkdir: Permission denied tar: nix/store/022qyk34rpid0j248p00arjy1v5l5f10-system-units/console-getty.service.d: Cannot mkdir: Permission denied tar: nix/store/022qyk34rpid0j248p00arjy1v5l5f10-system-units/console-getty.service.d/overrides.conf: Cannot open: No such file or directory tar: nix/store/022qyk34rpid0j248p00arjy1v5l5f10-system-units/container-getty@.service: Cannot open: Permission denied tar: nix/store/022qyk34rpid0j248p00arjy1v5l5f10-system-units/container-getty@.service.d: Cannot mkdir: Permission denied tar: nix/store/022qyk34rpid0j248p00arjy1v5l5f10-system-units/container-getty@.service.d: Cannot mkdir: Permission denied ........................

On ubuntu-jammy-22.04-amd64-server-20230919: Nov 21 17:23:09 ip-172-31-39-210 systemd-nspawn[800]: Failed to create directory at /var/lib/machines/nixos/usr: Value too large for defined data type Nov 21 17:23:09 ip-172-31-39-210 systemd[1]: systemd-nspawn@nixos.service: Main process exited, code=exited, status=1/FAILURE

jrbp commented 7 months ago

I just had this problem myself. It seems the problem is in the version of systemd on ubuntu 22.04. Apparently the issue was fixed in this pr, but didn't make it in to 22.04. I saw here that there's an (unsatisfying) workaround which is to run essentially any command in the container before starting it. With this nixos this also won't work until you create a usr directory in the container.

I was able to get the container to start by running the following after the machinectl pull-tar ... command and before the machinectl start nixos command:

sudo mkdir /var/lib/machines/nixos/usr
sudo chmod 755 /var/lib/machines/nixos/usr
sudo systemd-nspawn -M nixos --as-pid2 echo "...sigh"

The last command should fail, but it seems to not matter machinectl start nixos works for me after this.

I've also noticed that if I edit my nixos.nspawn file to bind certain host directories somewhere which isn't already present in the container that I need to create these directories manually in addition to usr.