diff --git a/RaspberryPi_JetsonNano/c/NIX_CONFIG.md b/RaspberryPi_JetsonNano/c/NIX_CONFIG.md new file mode 100644 index 00000000..0799cd02 --- /dev/null +++ b/RaspberryPi_JetsonNano/c/NIX_CONFIG.md @@ -0,0 +1,100 @@ +# 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) + +`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 +{ + 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 = {}; + users.users.anicolao.extraGroups = [ "spi" "gpio" ]; + services.udev.extraRules = '' + KERNEL=="spidev*", GROUP="spi", MODE="0660" + KERNEL=="gpiochip*", GROUP="gpio", MODE="0660" + ''; +} +``` + +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" + ''; + }; + }); +}