Olimex Support Forum

Others => TERES DIY Laptop => Topic started by: Thra11 on July 18, 2019, 10:05:15 am

Title: Experimental NixOS support
Post by: Thra11 on July 18, 2019, 10:05:15 am
I have been working on getting NixOS (https://nixos.org/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 (https://github.com/Thra11/nixpkgs/commits/nixos-teres) 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:


A prebuilt sd-card image can be downloaded here (https://github.com/Thra11/nixpkgs/releases/download/v19.09-teres-alpha.1/nixos-sd-image-19.09.git.c916e3c-aarch64-linux.img.xz). 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 (https://nixos.org/nixos/manual/) and wiki (https://nixos.wiki/wiki). There is information about running NixOS on Arm (including Aarch64) here (https://nixos.wiki/wiki/NixOS_on_ARM).

Some things I like about using NixOS:


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


In case it isn't obvious, this is not officially supported by anyone and comes with no guarantees whatsoever. Enjoy...  :)
Title: Re: Experimental NixOS support
Post by: berce on August 11, 2019, 02:42:14 pm
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.
Title: Re: Experimental NixOS support
Post by: Thra11 on August 31, 2019, 12:33:00 am
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:


Somewhat messy, but derivations can be found in this branch (https://github.com/Thra11/nixpkgs/tree/nixos-teres-testing) if interested.