NixOS on the Raspberry Pi Zero W - I'm stumped! - Written: 06 December 2022
I have been trying for the past couple of days to run NixOS on a RaspberryPi 0W. It was much more difficult than I expected!
Recently, I have been trying to run NixOS on a RaspberryPi 0W. I have been trying for the past couple of days, but I have been unable to get it to work. I have got so far, but I am stuck.
What I have tried
Downloading/Building the SD Card image
First, I tried compiling an SD card image using illegalprime’s nixos-on-arm repository and this command:
nix build -f . \
-I nixpkgs=nixpkgs \
-I machine=machines/raspberrypi-zerow \
-I image=images/rpi0-otg-serial
Then, after a while, I tried using this downloadable sd card image which had similar problems, but included more useful tools like vim
.
After writing my SD card, I connected my Raspberry Pi Zero W to a HDMI monitor and a keyboard. This worked great and soon got me to a terminal.
Setting up WiFi
Setting up WiFi was a bit of a hassle, however this is what I did to get it working:
Firstly, I created a config file for wpa_supplicant
:
mkdir /etc/wpa_supplicant
nano /etc/wpa_supplicant/wpa_supplicant.conf
I put these lines inside the file and saved it:
ctrl_interface=/run/wpa_supplicant
update_config=1
ap_scan=1
country=GB
network={
ssid="MY_SSID"
psk="MY_PASSWORD"
key_mgmt=WPA-PSK
}
Then, I ran these commands to clean the interface - thanks superuser.com!:
ip link set dev wlan0 down
ip addr flush dev wlan0
ip link set dev wlan0 up
And finally, I ran wpa_supplicant
:
wpa_supplicant -B -i wlan0 -Dnl80211,wext -c /etc/wpa_supplicant/wpa_supplicant.conf
Updating nix-channels
Now that I had a working internet connection, I ran these commands to update my nix-channels:
nix-channel --remove nixos
nix-channel --add https://channels.nixos.org/nixos19.09 nixos # This channel is the latest one that does not complain about the nix version.
nix-channel --update # Be very patient! This might take 5-10 minutes.
The trouble
Now, I generated a new configuration file using nixos-generate-config
and ran nixos-rebuild switch
to install it. This is where the trouble began. I got an error complaining that the command could not connect to http://nixos-arm.dezgeg.me/. I discovered (through archive.org) that the server used to redirect to https://www.cs.helsinki.fi/u/tmtynkky/nixos-arm/, so I followed the link and the webpage is still in operation (yay!). It appears, however that for some unknown reason, the images I have been using are somewhat hardcoded to use http://nixos-arm.dezgeg.me/. I tried to force nixos-rebuild to use https://www.cs.helsinki.fi/u/tmtynkky/nixos-arm/, however I was unable to do so. I tried:
nixos-rebuild switch --option substituters https://www.cs.helsinki.fi/u/tmtynkky/nixos-arm/channel
and I also added:
nix.settings.substituters = [ "https://www.cs.helsinki.fi/u/tmtynkky/nixos-arm/channel" ];
to my configuration.nix file, but neither of these worked. I tried building from source, but after two full days of compiling, I gave up.
Want to help?
If anyone out there has figured this out, or I am missing something obvious, raise an issue (or a pull request if you are feeling nice) on my dotfiles and I will try to fix it! I would love to get this working, as I have a few projects I would like to run on my Raspberry Pi Zero W using NixOS.
Also, I have found An armv7l cache server, but I have not been able to look into it yet.
What now?
For now, I will be using Raspbian on my Raspberry Pi Zero W. I might try to get NixOS working again in the far future (perhaps when support is better - although that is unlikely), but for now, it is just too much hassle.