tfc / nspawn-nixos

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

Using nspawn-nixos on Unifi devices #7

Closed NicolasGuilloux closed 3 weeks ago

NicolasGuilloux commented 1 month ago

Hi there!

I'm trying to use your repository to start it on a UDM Pro. I tried several things without success, so I'm just posting here whatever I found. I would love to be able to manage a small NixOS VM within the UDM for vital network applications (such as network.xyz, Adguard, cloudflared, traefik, ...)

       _,met$$$$$gg.          root@Dream-Machine-Special-Edition
    ,g$$$$$$$$$$$$$$$P.       ----------------------------------
  ,g$$P"     """Y$$.".        OS: Debian GNU/Linux 11 (bullseye) aarch64
 ,$$P'              `$$$.     Host: Annapurna Labs Alpine V2 UBNT
',$$P       ,ggs.     `$$b:   Kernel: 4.19.152-ui-alpine
`d$$'     ,$P"'   .    $$$    Uptime: 8 days, 14 hours, 39 mins
 $$P      d$'     ,    $$P    Packages: 586 (dpkg)
 $$:      $$.   -    ,d$$'    Shell: bash 5.1.4
 $$;      Y$b._   _,d$P'      Terminal: /dev/pts/1
 Y$$.    `.`"Y$$$$P"'         CPU: (4)
 `$$b      "-.__              Memory: 2921MiB / 3946MiB
  `Y$$
   `Y$$.
     `$$b.
       `Y$$b.
          `"Y$b._
              `"""

Importing tar

There is an error while importing the tar file with a lot of lines similar to the following:

tar: nix/store/wlxpsdzfvdanfzh704qmgyzb42qvy4fr-python3-3.10.12/include/python3.10: Directory renamed before its status could be extracted
tar: nix/store/wlxpsdzfvdanfzh704qmgyzb42qvy4fr-python3-3.10.12/include: Directory renamed before its status could be extracted
tar: nix/store/vzgyz71zc2f7l5ydk5kx8b1rkjv14yyj-tzdata-2023c/share/zoneinfo/posix: Directory renamed before its status could be extracted
tar: nix/store/vzgyz71zc2f7l5ydk5kx8b1rkjv14yyj-tzdata-2023c/share/zoneinfo: Directory renamed before its status could be extracted
tar: nix/store/vzgyz71zc2f7l5ydk5kx8b1rkjv14yyj-tzdata-2023c/share: Directory renamed before its status could be extracted
tar: nix/store/vzgyz71zc2f7l5ydk5kx8b1rkjv14yyj-tzdata-2023c: Directory renamed before its status could be extracted
tar: nix/store/vhj0sjllqakkw4vvzs96xsf3j2f2f3zw-coreutils-full-9.3/share/locale/zh_TW/LC_TIME: Directory renamed before its status could be extracted
tar: nix/store/vhj0sjllqakkw4vvzs96xsf3j2f2f3zw-coreutils-full-9.3/share/locale/zh_TW: Directory renamed before its status could be extracted
tar: nix/store/vhj0sjllqakkw4vvzs96xsf3j2f2f3zw-coreutils-full-9.3/share/locale/zh_CN/LC_TIME: Directory renamed before its status could be extracted
tar: nix/store/vhj0sjllqakkw4vvzs96xsf3j2f2f3zw-coreutils-full-9.3/share/locale/zh_CN: Directory renamed before its status could be extracted
...

I have no idea why it does this. I tried to loop online without success either.

Extracting by hand

I used tar -xf nixos.tar.xz to extract the folder, and then I directly used systemd-nspawn to start it. I get the following error:

root@Dream-Machine-Special-Edition:/data/custom/machines# systemd-nspawn -M nixos -D ./nixos
Spawning container nixos on /data/custom/machines/nixos.
Press ^] three times within 1s to kill container.
execv(/usr/lib/systemd/systemd, /lib/systemd/systemd, /sbin/init) failed: Exec format error
Container nixos failed with error code 1.
tfc commented 1 month ago

You are running the x86_64 image on an aarch64 system. This will not work.

I did not upload images for both architectures. But you can always build your own on your architecture if you have Nix already installed somewhere.

I could upload a new release for x86_64 and one for ARM, or you can simply build your own in the mean time.

NicolasGuilloux commented 3 weeks ago

Here is a PR to build the aarch64-linux from the Github Actions.

Just to point that I had to extract manually the tar.xz file in /data/custom/machines before hand, the import-tar does not seem to work on the UDM. Please refer to the following doc for installing on your Unifi device: https://github.com/unifi-utilities/unifios-utilities/blob/main/nspawn-container/README.md