Skip to content

Commit

Permalink
rp3: rebuild from scratch and update the installation instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
wagdav committed Nov 13, 2023
1 parent 98b1e2b commit 8dcf2ec
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 44 deletions.
64 changes: 41 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,43 +175,59 @@ router/setup.sh

## Raspberry Pi 3 Model B

### Raspbian
### NixOS

The installation instructions are based those from
[nix.dev](https://nix.dev/tutorials/nixos/installing-nixos-on-a-raspberry-pi.html).

Setup SD card:
Download the latest aarch64 SD card image from
[Hydra](https://hydra.nixos.org/search?query=sd_image) and flash it on an SD
card:

```
wget https://downloads.raspberrypi.org/raspbian_lite_latest
unzip -p raspbian_lite_latest | sudo dd of=/dev/mmcblk0 bs=4M conv=fsync status=progress
# remove then reinsert SD card
pmount /dev/mmcblk0p1
touch /media/mmcblk0p1/ssh
pumount /dev/mmcblk0p1
wget https://hydra.nixos.org/build/226381178/download/1/nixos-sd-image-23.11pre500597.0fbe93c5a7c-aarch64-linux.img.zst
unzstd nixos-sd-image-23.11pre500597.0fbe93c5a7c-aarch64-linux.img
sudo dd \
if=nixos-sd-image-23.11pre500597.0fbe93c5a7c-aarch64-linux.img \
of=/dev/mmcblk0 bs=4096 conv=fsync status=progress
```

### NixOS

The official NixOS images boot without any problems. Download the latest
aarch64 SD card image from
[Hydra](https://hydra.nixos.org/search?query=sd_image).

Flash the image to an SD card as described in the [previous section](#raspbian).

Boot the system then start an SSH server and set a temporary password for the
root user:
Insert the SD card in the Raspberry Pi and power it up. The installer runs
already an SSH server. Set a temporary password for the root user:

```
systemctl start sshd
passwd root
```

The password is only used for the first time access. Password authentication
will be disabled later. Connect to the freshly booted system using SSH.

If you want to manage Pi using NixOps, there's some extra steps required.
Folow [these instructions][NixOSBootWifi] to connect to a Wifi network. When
connected the system will have the hostname `nixos`.

Using the password authentication, deploy your SSH public keys:

```
ssh-copy-id root@nixos
```

On the Raspberry Pi, store the WIFI SSID and password in the file
`/etc/secrets/wireless.env` with the following format:

```
WIFI_SSID=...
WIFI_KEY=...
```

NixOps compiles all managed systems on the control PC where it runs. Then, it
copies the binaries to the target systems. This works well for i686 and amd64
architectures but it doesn't work for aarch64.
Finally, build the system with the custom configuration:

```
nixos-rebuild switch
--flake ".#rp3" \
--target-host "root@nixos" \
--build-host "root@nixos" \
--fast
```

I tried to setup cross-compilation to aarch64, but it didn't work.

Expand Down Expand Up @@ -298,3 +314,5 @@ dashboard configuration in this repository:
```
nix run .#mqtt-dash-listen > nodemcu/mqtt-dash.json
```

[NixOSBootWifi]: https://nixos.org/manual/nixos/stable/#sec-installation-booting-networking
36 changes: 17 additions & 19 deletions hardware/rp3.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,27 @@ in
nixpkgs.system = "aarch64-linux";

boot = {
initrd = {
availableKernelModules = [
"bcm2835_dma"
"i2c_bcm2835"
"usbhid"
"vc4"
];
kernelModules = [ ];
initrd.kernelModules = [ "vc4" "bcm2835_dma" "i2c_bcm2835" ];
loader = {
grub.enable = false;

raspberryPi = {
enable = true;
uboot.enable = true;
version = 3;
};
};
};

kernelParams = [ "cma=32M" ];

extraModulePackages = [ ];

loader.grub.enable = false;

loader.raspberryPi = {
enable = true;
uboot.enable = true;
version = 3;
};
networking.wireless = {
enable = true;
environmentFile = "/etc/secrets/wireless.env";
networks."@WIFI_SSID@".psk = "@WIFI_KEY@";
interfaces = [ "wlan0" ];
};

hardware.enableRedistributableFirmware = true;

environment.systemPackages = with pkgs; [
libraspberrypi
];
Expand Down
3 changes: 2 additions & 1 deletion host-rp3.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
./hardware/rp3.nix
./modules/common.nix
./modules/remote-builder
./modules/consul/client.nix
];

system.stateVersion = "22.05";
system.stateVersion = "23.11";
}
2 changes: 1 addition & 1 deletion modules/buildMachines.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

rp3 = {
hostNames = [ "rp3" "rp3.thewagner.home" ];
publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILK0illQrUbCmn+UHgM79tDecSItLUVNuWi/Sg+DW2tr";
publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJgVezT5bpUOihQmNEV6XC/RsUtFDcd9vcLZ7cUKPp83";
};

rp4 = {
Expand Down

0 comments on commit 8dcf2ec

Please sign in to comment.