From 9308a1c1deb0a8d67588055f3ab4318855f1105e Mon Sep 17 00:00:00 2001 From: Steve Dee Date: Sat, 4 Jan 2025 16:26:19 +0000 Subject: [PATCH] nchat: enable whatsapp module (requires building go module 'whatsmeow') --- pkgs/by-name/nc/nchat/package.nix | 44 ++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/pkgs/by-name/nc/nchat/package.nix b/pkgs/by-name/nc/nchat/package.nix index 444a4cc91cb0..4ab6257c3f7a 100644 --- a/pkgs/by-name/nc/nchat/package.nix +++ b/pkgs/by-name/nc/nchat/package.nix @@ -1,5 +1,6 @@ { lib, + buildGoModule, fetchFromGitHub, file, # for libmagic ncurses, @@ -13,8 +14,7 @@ darwin, }: -stdenv.mkDerivation rec { - pname = "nchat"; +let version = "5.4.2"; src = fetchFromGitHub { @@ -24,16 +24,55 @@ stdenv.mkDerivation rec { hash = "sha256-NrAU47GA7ZASJ7vCo1S8nyGBpfsZn4EBBqx2c4HKx7k="; }; + libcgowm = buildGoModule { + pname = "nchat-wmchat-libcgowm"; + inherit version src; + + sourceRoot = "${src.name}/lib/wmchat/go"; + vendorHash = "sha256-EdbOO5cCDT1CcPlCBgMoPDg65FcoOYvBwZa4bz0hfGE="; + + buildPhase = '' + mkdir -p $out/ + go build -o $out/ -buildmode=c-archive + mv $out/go.a $out/libcgowm.a + ln -s $out/libcgowm.a $out/libref-cgowm.a + mv $out/go.h $out/libcgowm.h + ''; + }; +in +stdenv.mkDerivation rec { + pname = "nchat"; + inherit version src; + + nl = "\n"; postPatch = '' substituteInPlace lib/tgchat/ext/td/CMakeLists.txt \ --replace "get_git_head_revision" "#get_git_head_revision" substituteInPlace lib/tgchat/CMakeLists.txt \ --replace-fail "list(APPEND OPENSSL_ROOT_DIR" "#list(APPEND OPENSSL_ROOT_DIR" + + # specific mangling to handle whatsapp go module: + + substituteInPlace CMakeLists.txt \ + --replace "if(HAS_WHATSAPP AND (NOT GO_VERSION VERSION_GREATER_EQUAL GO_VERSION_MIN))" \ + "if(FALSE AND (NOT GO_VERSION VERSION_GREATER_EQUAL GO_VERSION_MIN))" + + substituteInPlace lib/wmchat/CMakeLists.txt \ + --replace-fail "add_subdirectory(go)" \ + "set(GO_LIBRARIES ${libcgowm}/libcgowm.a)${nl}target_include_directories(wmchat PRIVATE ${libcgowm})" + + substituteInPlace lib/wmchat/CMakeLists.txt \ + --replace-fail "target_link_libraries(wmchat PUBLIC ref-cgowm ncutil \''${GO_LIBRARIES})" \ + "target_link_libraries(wmchat PUBLIC ${libcgowm}/libcgowm.a ncutil \''${GO_LIBRARIES})" + + substituteInPlace lib/wmchat/CMakeLists.txt \ + --replace-fail "add_dependencies(wmchat ref-cgowm)" "#add_dependencies(wmchat ref-cgowm)" ''; nativeBuildInputs = [ cmake gperf + libcgowm ]; buildInputs = @@ -56,7 +95,6 @@ stdenv.mkDerivation rec { cmakeFlags = [ "-DCMAKE_INSTALL_LIBDIR=lib" - "-DHAS_WHATSAPP=OFF" # go module build required ]; meta = {