From 85d54e039e3c615e7bd7e8e0b5f6384aa5706e66 Mon Sep 17 00:00:00 2001 From: Alex Nicolaou Date: Sat, 14 Feb 2026 15:29:40 -0500 Subject: [PATCH 1/2] Add Nix flake and NixOS SPI configuration guide --- RaspberryPi_JetsonNano/c/NIX_CONFIG.md | 78 ++++++++++++++++++++++++++ RaspberryPi_JetsonNano/c/flake.lock | 61 ++++++++++++++++++++ RaspberryPi_JetsonNano/c/flake.nix | 34 +++++++++++ 3 files changed, 173 insertions(+) create mode 100644 RaspberryPi_JetsonNano/c/NIX_CONFIG.md create mode 100644 RaspberryPi_JetsonNano/c/flake.lock create mode 100644 RaspberryPi_JetsonNano/c/flake.nix diff --git a/RaspberryPi_JetsonNano/c/NIX_CONFIG.md b/RaspberryPi_JetsonNano/c/NIX_CONFIG.md new file mode 100644 index 00000000..60364bee --- /dev/null +++ b/RaspberryPi_JetsonNano/c/NIX_CONFIG.md @@ -0,0 +1,78 @@ +# NixOS Configuration for Waveshare e-Paper (RaspberryPi_JetsonNano/c) + +This project now includes a Nix flake dev shell (`flake.nix` + `flake.lock`) that builds the C examples on NixOS. + +## 1. Use the dev shell without copying the whole git repo + +From `RaspberryPi_JetsonNano/c`, use: + +```bash +nix develop path:. +``` + +Do not use plain `nix develop .` in this mono-repo, because Nix may treat it as a git flake rooted at `/home/.../e-Paper` and spend time copying the full repo to the store. + +## 2. Build command + +Inside the dev shell: + +```bash +make -j4 EPD=epd5in65f +``` + +`flake.nix` exports `MAKEFLAGS=USELIB_RPI=USE_DEV_LIB` so default builds use the `libgpiod` backend (compatible with this environment). + +## 3. Persistent NixOS system config (SPI + non-root access) + +Add the following to `/etc/nixos/configuration.nix`. + +```nix +{ + # Ensure groups exist for device permissions. + users.groups.spi = {}; + users.groups.gpio = {}; + + # Add your user to the groups. + users.users.anicolao.extraGroups = [ "spi" "gpio" ]; + + # Device permissions for non-root SPI/GPIO access. + services.udev.extraRules = '' + KERNEL=="spidev*", GROUP="spi", MODE="0660" + KERNEL=="gpiochip*", GROUP="gpio", MODE="0660" + ''; + + # Load spidev module. + boot.kernelModules = [ "spidev" ]; + + # Raspberry Pi firmware/device-tree SPI enablement. + boot.loader.raspberryPi = { + enable = true; + version = 4; # adjust for your board generation + firmwareConfig = '' + dtparam=spi=on + ''; + }; +} +``` + +Apply and reboot: + +```bash +sudo nixos-rebuild switch +sudo reboot +``` + +After reboot, verify: + +```bash +ls -l /dev/spidev* /dev/gpiochip* +id +``` + +You should see `/dev/spidev0.0` and your user in `spi` + `gpio` groups. + +## 4. Why this is needed + +- `sudo ./epd` previously failed with `/dev/spidev0.0: No such file or directory`. +- That indicates SPI bus nodes were not enabled by firmware/device-tree. +- `modprobe spidev` alone is temporary and does not set persistent permissions/groups. diff --git a/RaspberryPi_JetsonNano/c/flake.lock b/RaspberryPi_JetsonNano/c/flake.lock new file mode 100644 index 00000000..43f833f0 --- /dev/null +++ b/RaspberryPi_JetsonNano/c/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1771008912, + "narHash": "sha256-gf2AmWVTs8lEq7z/3ZAsgnZDhWIckkb+ZnAo5RzSxJg=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "a82ccc39b39b621151d6732718e3e250109076fa", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/RaspberryPi_JetsonNano/c/flake.nix b/RaspberryPi_JetsonNano/c/flake.nix new file mode 100644 index 00000000..ae516e7d --- /dev/null +++ b/RaspberryPi_JetsonNano/c/flake.nix @@ -0,0 +1,34 @@ +{ + description = "Waveshare e-Paper C dev shell for NixOS"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, flake-utils }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { + inherit system; + }; + in { + devShells.default = pkgs.mkShell { + packages = with pkgs; [ + bun + gcc + gnumake + pkg-config + linuxHeaders + libgpiod_1 + wiringpi + ]; + + shellHook = '' + export MAKEFLAGS="USELIB_RPI=USE_DEV_LIB" + echo "Waveshare e-Paper C dev shell" + echo "Build example: make clean && make -j4 EPD=epd2in13V4" + ''; + }; + }); +} From dbe44ec8ca4d4102ec16ae7817e4aae7d34d5ef2 Mon Sep 17 00:00:00 2001 From: Alex Nicolaou Date: Sat, 14 Feb 2026 16:08:35 -0500 Subject: [PATCH 2/2] Update Nix SPI docs for raspberry-pi-nix --- RaspberryPi_JetsonNano/c/NIX_CONFIG.md | 58 ++++++++++++++++++-------- 1 file changed, 40 insertions(+), 18 deletions(-) diff --git a/RaspberryPi_JetsonNano/c/NIX_CONFIG.md b/RaspberryPi_JetsonNano/c/NIX_CONFIG.md index 60364bee..0799cd02 100644 --- a/RaspberryPi_JetsonNano/c/NIX_CONFIG.md +++ b/RaspberryPi_JetsonNano/c/NIX_CONFIG.md @@ -24,34 +24,56 @@ make -j4 EPD=epd5in65f ## 3. Persistent NixOS system config (SPI + non-root access) -Add the following to `/etc/nixos/configuration.nix`. +`boot.loader.raspberryPi` was removed from nixpkgs and no longer works. +Use `raspberry-pi-nix` for modern Raspberry Pi boot/device-tree configuration. + +### Option A: Use the dedicated image repo (recommended) + +Use `https://github.com/anicolao/nix-epaper`, which already includes: +- SPI firmware configuration +- `spidev` kernel module +- `spi`/`gpio` groups and udev rules + +### Option B: Add equivalent settings to your own system flake + +In your system `flake.nix`: + +```nix +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + raspberry-pi-nix = { + url = "github:nix-community/raspberry-pi-nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; +} +``` + +In your NixOS configuration module: ```nix { - # Ensure groups exist for device permissions. + imports = [ raspberry-pi-nix.nixosModules.raspberry-pi ]; + + # Pi 4; use "bcm2712" for Pi 5. + raspberry-pi-nix.board = "bcm2711"; + + # Enable SPI in generated config.txt. + hardware.raspberry-pi.config.all.base-dt-params.spi = { + enable = true; + value = "on"; + }; + + # Ensure userspace SPI char device and permissions. + boot.kernelModules = [ "spidev" ]; users.groups.spi = {}; users.groups.gpio = {}; - - # Add your user to the groups. users.users.anicolao.extraGroups = [ "spi" "gpio" ]; - - # Device permissions for non-root SPI/GPIO access. services.udev.extraRules = '' KERNEL=="spidev*", GROUP="spi", MODE="0660" KERNEL=="gpiochip*", GROUP="gpio", MODE="0660" ''; - - # Load spidev module. - boot.kernelModules = [ "spidev" ]; - - # Raspberry Pi firmware/device-tree SPI enablement. - boot.loader.raspberryPi = { - enable = true; - version = 4; # adjust for your board generation - firmwareConfig = '' - dtparam=spi=on - ''; - }; } ```