From 32946c35d97dc724d9fcf895a207375e68ba1e40 Mon Sep 17 00:00:00 2001 From: Colin Date: Thu, 24 Jul 2025 07:03:40 +0000 Subject: [PATCH] newelle: ship on moby, hack in cross compilation --- hosts/common/programs/assorted.nix | 2 +- hosts/common/programs/newelle.nix | 37 +++++++++++++++++++++- overlays/cross.nix | 19 +++++++++++ pkgs/by-name/nixpkgs-bootstrap/patches.nix | 7 ++++ 4 files changed, 63 insertions(+), 2 deletions(-) diff --git a/hosts/common/programs/assorted.nix b/hosts/common/programs/assorted.nix index 326e619b8..5646312fd 100644 --- a/hosts/common/programs/assorted.nix +++ b/hosts/common/programs/assorted.nix @@ -350,6 +350,7 @@ in "mpv" "networkmanagerapplet" # "ntfy-sh" # notification service + "newelle" # ollama/LLM client "newsflash" # RSS viewer "papers" # PDF viewer "pavucontrol" @@ -433,7 +434,6 @@ in # "makemkv" # x86-only # "monero-gui" # x86-only "mumble" - "newelle" # ollama/LLM client # "nheko" # Matrix chat client "nicotine-plus" # soulseek client # "obsidian" diff --git a/hosts/common/programs/newelle.nix b/hosts/common/programs/newelle.nix index 4be9bc11d..cc5132507 100644 --- a/hosts/common/programs/newelle.nix +++ b/hosts/common/programs/newelle.nix @@ -3,10 +3,45 @@ # to decrease pathologies # - intelligent formatting of model output (e.g. latex, markdown) # +# shortcomings (as of 2025-07-23): +# - poorly adapts to very narrow screens. +# - usable, but e.g. the "post" button (and the window close button) is cut off +# - closing the UI does not fully exit the process +# - presumably it's sitting in the background, waiting to be dbus-activated +# # TODO: configure ollama connection details statically -{ ... }: +{ pkgs, ... }: { sane.programs.newelle = { + packageUnwrapped = (pkgs.newelle.override { + python3Packages = pkgs.python3Packages // { + # XXX(2025-07-23): these don't cross compile; disable them + # pydub drags in opencv, but only used for text-to-speech (and only for Newelle <= 0.9.8) + pydub = null; + # speechrecognition has a build error due to python3Packages.standard-aifc > python3Packages.audioop + speechrecognition = null; + # both of these are blocked on `python3Packages.spacy` + # llama-index-* is imported, lazily, from handlers/rag/llamaindex_handler.py + llama-index-core = null; + llama-index-readers-file = null; + }; + }).overridePythonAttrs (upstream: { + postPatch = (upstream.postPatch or "") + '' + # patch out the toplevel speech_recognition imports so that the app + # is launchable without it. + # actually trying to use speech recognition will (likely) manifest as a runtime error, instead. + find . -exec sed -i 's/import speech_recognition/# import speech_recognition/g' '{}' ';' + + # turn pydub (text-to-speech) into a runtime error. + # N.B.: remove once Newelle is upgraded past 0.9.8: + # future versions do not use pydub for tts (but ffplay instead) + substituteInPlace src/handlers/tts/tts.py \ + --replace-fail 'from pydub' '# from pydub' + ''; + }); + + buildCost = 2; #< liable to break cross during updates; not important enough to block deploy over + sandbox.net = "all"; # maybe only needs wireguard, actually sandbox.whitelistWayland = true; sandbox.mesaCacheDir = ".cache/Newelle/mesa"; diff --git a/overlays/cross.nix b/overlays/cross.nix index 1938b7ba4..75d2ed2dc 100644 --- a/overlays/cross.nix +++ b/overlays/cross.nix @@ -588,6 +588,25 @@ in with final; { cargo = crossCargo; }; + # pythonPackagesExtensions = prev.pythonPackagesExtensions ++ [ + # (pyself: pysuper: { + # # 2025/07/23: upstreaming is unblocked, but solution is untested. + # # the references here are a result of the cython build process. + # # cython is using the #include files from the build python, and leaving those paths in code comments. + # # better solution is to get cython to use the HOST python?? + # # + # # python3Packages.srsly is required by `newelle` program. + # srsly = pysuper.srsly.overridePythonAttrs (upstream: { + # nativeBuildInputs = (upstream.nativeBuildInputs or []) ++ [ + # removeReferencesTo + # ]; + # postFixup = (upstream.postFixup or "") + '' + # remove-references-to -t ${pyself.python.pythonOnBuildForHost} $out/${pyself.python.sitePackages}/srsly/msgpack/*.cpp + # ''; + # }); + # }) + # ]; + # qt6 = prev.qt6.overrideScope (self: super: { # # qtbase = super.qtbase.overrideAttrs (upstream: { # # # cmakeFlags = upstream.cmakeFlags ++ lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [ diff --git a/pkgs/by-name/nixpkgs-bootstrap/patches.nix b/pkgs/by-name/nixpkgs-bootstrap/patches.nix index 0d99d8962..2a7aab443 100644 --- a/pkgs/by-name/nixpkgs-bootstrap/patches.nix +++ b/pkgs/by-name/nixpkgs-bootstrap/patches.nix @@ -64,6 +64,13 @@ in hash = "sha256-609snDT1Ru69ZTWfzu4PnhY0pj3xghPr8w880j7JZ5k="; }) + # (fetchpatch' { + # # opencv used by alpaca, newelle + # name = "opencv: fix cross compliation by patching protobuf"; + # prUrl = "https://github.com/NixOS/nixpkgs/pull/415591"; + # hash = "sha256-ZTTIw10Nh179JrAudSuC8FDTSW2CspYrRchMi+ODwww="; + # }) + # (fetchpatch' { # # XXX(2025-01-06): patch does not produce valid binaries for cross # name = "lua-language-server: fix cross compiling";