From eb3fe42542c742b611b1baa742dddc40296623b3 Mon Sep 17 00:00:00 2001 From: Thierry Pouplier Date: Sun, 14 Jun 2026 20:56:17 -0400 Subject: [PATCH] refactor: extract shared uconsole modules to eliminate toplevel/image duplication --- flake.nix | 155 ++++++++++++++++++++++++------------------------------ 1 file changed, 70 insertions(+), 85 deletions(-) diff --git a/flake.nix b/flake.nix index 15b5b9f..89776dd 100644 --- a/flake.nix +++ b/flake.nix @@ -46,6 +46,74 @@ devShell = import ./shells/nix_dev.nix { inherit pkgs system agenix; }; + + # Cross-compile overlay fixes for Hyprland and deps on aarch64 + uconsoleCrossOverlay = final: prev: { + libcamera = prev.libcamera.overrideAttrs (_: { meta.platforms = []; }); + libcamera-rpi = prev.libcamera-rpi.overrideAttrs (_: { meta.platforms = []; }); + libpisp = prev.libpisp.overrideAttrs (_: { meta.platforms = []; }); + pipewire = prev.pipewire.overrideAttrs (old: { + buildInputs = builtins.filter + (x: !(x?pname && x.pname == "libcamera")) + (old.buildInputs or []); + mesonFlags = builtins.filter + (flag: !(builtins.isString flag && builtins.match ".*libcamera.*" flag != null)) + (old.mesonFlags or []) ++ [ "-Dlibcamera=disabled" ]; + }); + gjs = prev.gjs.overrideAttrs (old: { + mesonFlags = (old.mesonFlags or []) ++ [ "-Dskip_gtk_tests=true" ]; + }); + hyprland = prev.hyprland.override { wrapRuntimeDeps = false; }; + xdg-desktop-portal-hyprland = prev.xdg-desktop-portal-hyprland.overrideAttrs (old: { + preConfigure = (old.preConfigure or "") + '' + cmakeFlags="$cmakeFlags -Dhyprwayland-scanner_DIR=${prev.buildPackages.hyprwayland-scanner}/lib/cmake/hyprwayland-scanner" 2>/dev/null || true + export PKG_CONFIG_PATH="${prev.buildPackages.hyprwayland-scanner}/lib/pkgconfig:$PKG_CONFIG_PATH" + ''; + }); + }; + + # RPI-specific pipewire libcamera fix (separate nixpkgs instance) + uconsoleRpiPipewireOverlay = final: prev: { + pipewire = prev.pipewire.overrideAttrs (old: { + buildInputs = builtins.filter + (x: !(x?pname && x.pname == "libcamera")) + (old.buildInputs or []); + mesonFlags = builtins.filter + (flag: !(builtins.isString flag && builtins.match ".*libcamera.*" flag != null)) + (old.mesonFlags or []) ++ [ "-Dlibcamera=disabled" ]; + }); + }; + + # Shared uConsole CM5 module set — used by both toplevel and SD image + uconsoleBaseModules = [ + { + nixpkgs.buildPlatform = "x86_64-linux"; + nixpkgs.hostPlatform = "aarch64-linux"; + nixpkgs.config.allowUnfree = true; + boot.loader.raspberry-pi.bootloader = "kernel"; + nixpkgs.overlays = [ uconsoleCrossOverlay ]; + } + nixos-raspberrypi.nixosModules.nixpkgs-rpi + ({ config, lib, pkgs, ... }: { + nixpkgs.overlays = [ uconsoleRpiPipewireOverlay ]; + }) + nixos-raspberrypi.nixosModules.raspberry-pi-5.base + nixos-raspberrypi.lib.inject-overlays + nixos-raspberrypi.lib.inject-overlays-global + nixos-uconsole.nixosModules.uconsole-cm5 + # Cross-compiled Lix for uConsole + ({ config, lib, pkgs, inputs, ... }: let + lixCross = import inputs.nixpkgs-uconsole { + localSystem = { system = "x86_64-linux"; }; + crossSystem = { system = "aarch64-linux"; }; + overlays = [ inputs.lix.overlays.default ]; + }; + in { nix.package = lixCross.lix; }) + agenix.nixosModules.default + ./hosts/uconsole-cm5/configuration.nix + ./hosts/uconsole-cm5/hardware-configuration.nix + ]; + in { nixosConfigurations = { lazyworkhorse = nixpkgs.lib.nixosSystem { @@ -93,80 +161,7 @@ nixos-raspberrypi = nixos-raspberrypi; isCM4 = false; }; - modules = [ - { - nixpkgs.buildPlatform = "x86_64-linux"; - nixpkgs.hostPlatform = "aarch64-linux"; - nixpkgs.config.allowUnfree = true; - boot.loader.raspberry-pi.bootloader = "kernel"; - # Kill camera packages — not needed on uConsole, break cross-compile - nixpkgs.overlays = [ - # Make camera packages "unavailable" so no pkgs depend on them - (final: prev: { - libcamera = prev.libcamera.overrideAttrs (_: { meta.platforms = []; }); - libcamera-rpi = prev.libcamera-rpi.overrideAttrs (_: { meta.platforms = []; }); - libpisp = prev.libpisp.overrideAttrs (_: { meta.platforms = []; }); - # Pipewire in nixos-25.11 has libcamera unconditionally in buildInputs; - # meta.platforms trick doesn't help — must actually remove it - pipewire = prev.pipewire.overrideAttrs (old: { - buildInputs = builtins.filter - (x: !(x?pname && x.pname == "libcamera")) - (old.buildInputs or []); - mesonFlags = builtins.filter - (flag: !(builtins.isString flag && builtins.match ".*libcamera.*" flag != null)) - (old.mesonFlags or []) ++ [ "-Dlibcamera=disabled" ]; - }); - # gjs cross-compile fails without GTK; skip intro tests - gjs = prev.gjs.overrideAttrs (old: { - mesonFlags = (old.mesonFlags or []) ++ [ "-Dskip_gtk_tests=true" ]; - }); - # Qt6Quick missing from aarch64 qtdeclarative cross-compile; - # skip qtutils runtime deps — Hyprland only needs it for QML UI - hyprland = prev.hyprland.override { wrapRuntimeDeps = false; }; - # hyprwayland-scanner not found by cross pkg-config wrapper - xdg-desktop-portal-hyprland = prev.xdg-desktop-portal-hyprland.overrideAttrs (old: { - preConfigure = (old.preConfigure or "") + '' - # Point cmake to the correct hyprwayland-scanner pkgconfig - cmakeFlags="$cmakeFlags -Dhyprwayland-scanner_DIR=${prev.buildPackages.hyprwayland-scanner}/lib/cmake/hyprwayland-scanner" 2>/dev/null || true - export PKG_CONFIG_PATH="${prev.buildPackages.hyprwayland-scanner}/lib/pkgconfig:$PKG_CONFIG_PATH" - ''; - }); - }) - ]; - } - nixos-raspberrypi.nixosModules.nixpkgs-rpi - # Disable libcamera in rpi pipewire too (separate nixpkgs instance) - ({ config, lib, pkgs, ... }: { - nixpkgs.overlays = [ - (final: prev: { - pipewire = prev.pipewire.overrideAttrs (old: { - buildInputs = builtins.filter - (x: !(x?pname && x.pname == "libcamera")) - (old.buildInputs or []); - mesonFlags = builtins.filter - (flag: !(builtins.isString flag && builtins.match ".*libcamera.*" flag != null)) - (old.mesonFlags or []) ++ [ "-Dlibcamera=disabled" ]; - }); - }) - ]; - }) - -# Patches are now in gortium/nixos-uconsole fork (pr/dcs-panel-detection branch) - nixos-raspberrypi.nixosModules.raspberry-pi-5.base - nixos-raspberrypi.lib.inject-overlays - nixos-raspberrypi.lib.inject-overlays-global - nixos-uconsole.nixosModules.uconsole-cm5 - ({ config, lib, pkgs, inputs, ... }: let - lix-cross = import inputs.nixpkgs-uconsole { - localSystem = { system = "x86_64-linux"; }; - crossSystem = { system = "aarch64-linux"; }; - overlays = [ inputs.lix.overlays.default ]; - }; - in { nix.package = lix-cross.lix; }) - agenix.nixosModules.default - ./hosts/uconsole-cm5/configuration.nix - ./hosts/uconsole-cm5/hardware-configuration.nix - ]; + modules = uconsoleBaseModules; }; }; @@ -180,18 +175,8 @@ nixos-raspberrypi = nixos-raspberrypi; isCM4 = false; }; - modules = [ - { - nixpkgs.buildPlatform = system; - nixpkgs.hostPlatform = "aarch64-linux"; - } - nixos-raspberrypi.nixosModules.nixpkgs-rpi - nixos-raspberrypi.nixosModules.raspberry-pi-5.base - nixos-raspberrypi.lib.inject-overlays-global + modules = uconsoleBaseModules ++ [ nixos-raspberrypi.nixosModules.sd-image - nixos-uconsole.nixosModules.uconsole-cm5 - agenix.nixosModules.default - ./hosts/uconsole-cm5/configuration.nix ]; }).config.system.build.sdImage; };