{ config, lib, pkgs, namespace, ... }: let cfg = config.${namespace}.hardware.raspberry-pi; in { options.${namespace}.hardware.raspberry-pi = { enable = lib.mkEnableOption "Raspberry Pi common configuration"; variant = lib.mkOption { type = lib.types.enum [ "4" "5" ]; description = "Raspberry Pi variant (4 or 5)"; }; }; config = lib.mkIf cfg.enable { # Common Raspberry Pi packages environment.systemPackages = with pkgs; [ i2c-tools libraspberrypi raspberrypi-eeprom raspberrypifw raspberrypiWirelessFirmware raspberrypi-armstubs erofs-utils fex squashfuse squashfsTools ]; # Common Bluetooth configuration systemd.services.btattach = { before = [ "bluetooth.service" ]; after = [ "dev-ttyAMA0.device" ]; wantedBy = [ "multi-user.target" ]; serviceConfig = { ExecStart = "${pkgs.bluez}/bin/btattach -B /dev/ttyAMA0 -P bcm -S 3000000"; }; }; # Common hardware settings hardware.i2c.enable = lib.mkDefault true; # Pi specific settings hardware.graphics.enable32Bit = lib.mkForce false; # Pi specific system tags system.nixos.tags = ( let bootCfg = config.boot.loader.raspberry-pi; in [ "raspberry-pi-${bootCfg.variant}" bootCfg.bootloader config.boot.kernelPackages.kernel.version ] ); # Common programs programs.kdeconnect.enable = lib.mkDefault false; # Root user shell configuration users.users.root.shell = pkgs.zsh; }; }