December 09, 2024, 12:12:19 PM

Experimental NixOS support

Started by Thra11, July 18, 2019, 10:05:15 AM

Previous topic - Next topic

Thra11

I have been working on getting NixOS running on the Teres I laptop. It's still early days, but it seems to be basically working (I'm writing this forum post on my Teres running NixOS). As you can see from the small number of commits required to get it working, most of the work has already been done by others. I have essentially followed the instructions for installing NixOS on Allwinner devices, and referred to the Armbian build to choose which kernel sources and patches to build from. U-boot is 2019.07-rc4.

Current State:

  • It works
  • No DE by default. Choose your own! (I've tested KDE plasma5 and lxqt. Both run fine, although plasma is a little sluggish without hardware acceleration)
  • Relatively untested. If you find issues, please fix them! Or report them in this thread or here.

A prebuilt sd-card image can be downloaded here. Alternatively, you can build your own image on any system with nix installed (NixOS or other Linux host). Building should be possible on any host which can compile for aarch64, although I've only tested it on an aarch64 host myself (The Teres should be able to build the image itself, although I've been using a faster machine to save time).

To build your own image (with any modifications you may wish to make), checkout the nixos-teres branch from my copy of nixpkgs:

git clone https://github.com/Thra11/nixpkgs/
cd nixpkgs
git checkout nixos-teres
nix-build '<nixpkgs/nixos>' -A config.system.build.sdImage -I nixos-config=nixos/modules/installer/cd-dvd/sd-image-teres.nix

This should produce (after some time) a symlink, result in the current working directory, pointing to something like /nix/store/95vcwhkfr36092qvzh9qhv08jv60jbik-nixos-sd-image-19.09.git.dde1490-aarch64-linux.img. This should contain a disk image which can be written to a micro-SD card. e.g. as root (with /dev/sdX replaced with the actual device):

# dd if=result/sd-image/nixos-sd-image-19.09.git.dde1490-aarch64-linux.img of=/dev/sdX status=progress


On the first boot, it will expand the main partition to fill the SD card. Once it has booted, you can edit /etc/nixos/configuration.nix to define your system, then run nixos-rebuild to make it a reality.

For general NixOS documentation, see the manual and wiki. There is information about running NixOS on Arm (including Aarch64) here.

Some things I like about using NixOS:

  • Most operations are non-destructive and can be rolled back, so it's easy to try a new kernel version or a different kernel config without any risk (NixOS uses extlinux to offer a list of available `generations` in u-boot)
  • You can build an sd-image with a single command, so it's easy to tweak the config and rebuild without having to remember to rerun multiple build steps.

Depending how many package you have in your configuration and how many past generations you like to keep, NixOS can be quite disk-space hungry: You may need a decent-sized microSD card to be able to use NixOS conveniently on the Teres.

Things you might want to change in nixpkgs:

Choice of kernel package, content of config files on the boot partition:

nixos/modules/installer/cd-dvd/sd-image-teres.nix


Creation of the disk image:

nixos/modules/installer/cd-dvd/sd-image.nix


The base configuration of the linux-sunxi kernel (can easily be pointed at different linux repos, or patches added or removed)

pkgs/os-specific/linux/kernel/linux-sunxi


I did try the vanilla linuxPackages_4_19: It booted (observed via the audio-jack serial debug), but (unsurprisingly) the display didn't work.

Things to be done

  • Tidy up changes to nixpkgs, refactor them to override existing derivations instead of changing them. Upstream changes where appropriate.
  • The version of U-Boot I've used is currently a release candidate. Once there is a release and nixpkgs switches to it, there should be no need to override the u-boot version.
  • Add a Teres page to the NixOS wiki.
  • Keyboard input in u-boot doesn't seem to work (TODO: Test with an external USB keyboard)
  • Fix all the other things which don't work (backlight, some error about sun6i-rtc, etc., etc.)
  • I have observed kernel panics a couple of times, but when I went back to record the output, it didn't happen, and hasn't happened since.
  • Keep an eye on the sunxi mainlining effort and hopefully switch to newer versions of the kernel and reduce the patchset as things get integrated (vanilla build of latest kernel being the ultimate goal).

In case it isn't obvious, this is not officially supported by anyone and comes with no guarantees whatsoever. Enjoy...  :)

berce

#1
Great work. Thank you!

Several attempts with kernel 5.1 and 5.2 didn't result in a working display.
Thanks to your work, I now finally have a fully functional Nixos installed on my Teres.

Steps to follow:

1. Get wifi with wpa_supplicant. The man page has all information needed: man wpa_supplicant.

vim /etc/wpa_supplicant.conf
wpa_supplicant -iwlan0 -c/etc/wpa_supplicant.conf &


2. Clone the nixpkgs repo for teres.

git clone -b nixos-teres --depth 1 --single-branch https://github.com/Thra11/nixpkgs

3. Configure Nixos, using nixpkgs/nixos/modules/installer/cd-dvd/sd-image-teres.nix as inspration.

nixos-generate-config
vim nixos_config/configuration.nix


4. Rebuild Nixos

nixos-rebuild switch -I nixpkgs=/root/nixpkgs

5. Install on emmc

mount /dev/mmcblk2p1 /mnt
# destructive: rm -r /mnt/*
rsync -aAXv  --info=progress2 --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} / /mnt
nixos-generate-config --root /mnt
mv /mnt/etc/nixos/configuration.nix /mnt/etc/nixos/generated-configuration.nix
cp /etc/nixos/configuration.nix /mnt/etc/nixos/configuration.nix
nixos-install -I /home/bert/nixpkgs/nixpkgs/ --root /mnt


sidenote: 'fully functional' might be misleading. Sound and videoplayback have not been tested; the camera works fine with vlc. Certainly working software: XMonad, dmenu, emacs, vim, inkscape, qutebrowser, slim display manager, networkmanager.

Thra11

I'm glad it was helpful for you. Thanks for taking the time to write up some proper instructions!

I have experimented with a few other kernel builds, though without any real success so far:

  • Linux 5.2 with anx6345 patchset from the linux kernel mailing list - Boots. Backlight control works, but display output doesn't (Using the debug uart to write values into /sys/class/backlight/ changes the brightness correctly). Sorting the display out might just need some tweaks to the dtb, or it might be something more...
  • Linux 3.10 from Olimex' sources. Encountered some issues building such an old kernel with the current nixpkgs kernel derivations. Fixed a few, but ultimately gave up without building successfully.

Somewhat messy, but derivations can be found in this branch if interested.