OpenBangla / OpenBangla-Keyboard

An OpenSource, Unicode compliant Bengali Input Method
http://openbangla.github.io/
GNU General Public License v3.0
457 stars 73 forks source link

Add build instructions for nixos #306

Open sifat06 opened 2 years ago

sifat06 commented 2 years ago

I was trying to install openbangla-keyboard in nixos 22.05. As there is no official package for nixos, I was trying to build it myself. I made a script that looks like this:


$ cat openbangla-keyboard.nix
{ stdenv, fetchFromGitHub, cmake, rustc, cargo, qtbase, wrapQtAppsHook, ibus, pkg-config, zstd }:

stdenv.mkDerivation rec {
  pname = "openbangla-keyboard";
  version = "6.0.0-rc1";

  src = fetchFromGitHub {
    owner = "openbangla";
    repo = "openbangla-keyboard";
    rev = "adab38f09d47b8b6c88f57256e89983152b8384c";
    hash = "sha256-z63bsrxhUudb8O29genHmcOy4pzCO+KzadUc7Hs0ULY=";
    fetchSubmodules = true;
  };

  buildInputs = [ ibus cargo rustc qtbase zstd ];

  nativeBuildInputs = [
    wrapQtAppsHook
    cmake
    pkg-config
  ];
} 

However, it wasn't successfully built.


$ nix-build -K -E 'with import <nixpkgs> {}; libsForQt5.callPackage ./openbangla-keyboard.nix {}'
this derivation will be built:
  /nix/store/hgkhmqzhxw7wxr7v9snf4nw3dlcbzn7j-openbangla-keyboard-6.0.0-rc1.drv
building '/nix/store/hgkhmqzhxw7wxr7v9snf4nw3dlcbzn7j-openbangla-keyboard-6.0.0-rc1.drv'...
qtPreHook
unpacking sources
unpacking source archive /nix/store/6ir44rbl1azby0n943sv26ln06iixgnf-source
source root is source
patching sources
configuring
fixing cmake files...
cmake flags: -DCMAKE_FIND_USE_SYSTEM_PACKAGE_REGISTRY=OFF -DCMAKE_FIND_USE_PACKAGE_REGISTRY=OFF -DCMAKE_EXPORT_NO_PACKAGE_REGISTRY=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_SKIP_BUILD_RPATH=ON -DBUILD_TESTING=OFF -DCMAKE_INSTALL_LOCALEDIR=/nix/store/xlnsm0yz8y9w9bxa51wahpkhgr2rw9bj-openbangla-keyboard-6.0.0-rc1/share/locale -DCMAKE_INSTALL_LIBEXECDIR=/nix/store/xlnsm0yz8y9w9bxa51wahpkhgr2rw9bj-openbangla-keyboard-6.0.0-rc1/libexec -DCMAKE_INSTALL_LIBDIR=/nix/store/xlnsm0yz8y9w9bxa51wahpkhgr2rw9bj-openbangla-keyboard-6.0.0-rc1/lib -DCMAKE_INSTALL_DOCDIR=/nix/store/xlnsm0yz8y9w9bxa51wahpkhgr2rw9bj-openbangla-keyboard-6.0.0-rc1/share/doc/OpenBangla-Keyboard -DCMAKE_INSTALL_INFODIR=/nix/store/xlnsm0yz8y9w9bxa51wahpkhgr2rw9bj-openbangla-keyboard-6.0.0-rc1/share/info -DCMAKE_INSTALL_MANDIR=/nix/store/xlnsm0yz8y9w9bxa51wahpkhgr2rw9bj-openbangla-keyboard-6.0.0-rc1/share/man -DCMAKE_INSTALL_OLDINCLUDEDIR=/nix/store/xlnsm0yz8y9w9bxa51wahpkhgr2rw9bj-openbangla-keyboard-6.0.0-rc1/include -DCMAKE_INSTALL_INCLUDEDIR=/nix/store/xlnsm0yz8y9w9bxa51wahpkhgr2rw9bj-openbangla-keyboard-6.0.0-rc1/include -DCMAKE_INSTALL_SBINDIR=/nix/store/xlnsm0yz8y9w9bxa51wahpkhgr2rw9bj-openbangla-keyboard-6.0.0-rc1/sbin -DCMAKE_INSTALL_BINDIR=/nix/store/xlnsm0yz8y9w9bxa51wahpkhgr2rw9bj-openbangla-keyboard-6.0.0-rc1/bin -DCMAKE_INSTALL_NAME_DIR=/nix/store/xlnsm0yz8y9w9bxa51wahpkhgr2rw9bj-openbangla-keyboard-6.0.0-rc1/lib -DCMAKE_POLICY_DEFAULT_CMP0025=NEW -DCMAKE_OSX_SYSROOT= -DCMAKE_FIND_FRAMEWORK=LAST -DCMAKE_STRIP=/nix/store/ag2bpk0lzjvj409znklrz5krkpc5imzs-gcc-wrapper-11.3.0/bin/strip -DCMAKE_RANLIB=/nix/store/rq6bh3qfrqnyqwik0w3q6w180zg3w2pa-binutils-2.38/bin/ranlib -DCMAKE_AR=/nix/store/rq6bh3qfrqnyqwik0w3q6w180zg3w2pa-binutils-2.38/bin/ar -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_INSTALL_PREFIX=/nix/store/xlnsm0yz8y9w9bxa51wahpkhgr2rw9bj-openbangla-keyboard-6.0.0-rc1  
-- The C compiler identification is GNU 11.3.0
-- The CXX compiler identification is GNU 11.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /nix/store/ag2bpk0lzjvj409znklrz5krkpc5imzs-gcc-wrapper-11.3.0/bin/gcc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /nix/store/ag2bpk0lzjvj409znklrz5krkpc5imzs-gcc-wrapper-11.3.0/bin/g++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Cargo Home: /build
-- Rust Compiler Version: rustc 1.60.0
-- Found PkgConfig: /nix/store/szc9mx70l0lk32rbyixpq5mska4fzj61-pkg-config-wrapper-0.29.2/bin/pkg-config (found version "0.29.2") 
-- Checking for module 'ibus-1.0'
--   Found ibus-1.0, version 1.5.26
Package libpcre was not found in the pkg-config search path.
Perhaps you should add the directory containing `libpcre.pc'
to the PKG_CONFIG_PATH environment variable
Package 'libpcre', required by 'glib-2.0', not found
Package libpcre was not found in the pkg-config search path.
Perhaps you should add the directory containing `libpcre.pc'
to the PKG_CONFIG_PATH environment variable
Package 'libpcre', required by 'glib-2.0', not found
Package libpcre was not found in the pkg-config search path.
Perhaps you should add the directory containing `libpcre.pc'
to the PKG_CONFIG_PATH environment variable
Package 'libpcre', required by 'glib-2.0', not found
Package libpcre was not found in the pkg-config search path.
Perhaps you should add the directory containing `libpcre.pc'
to the PKG_CONFIG_PATH environment variable
Package 'libpcre', required by 'glib-2.0', not found
-- Checking for module 'libzstd'
--   Found libzstd, version 1.5.2
-- Rust Compiler Target: x86_64-unknown-linux-gnu
-- Configuring done
-- Generating done
CMake Warning:
  Manually-specified variables were not used by the project:

    BUILD_TESTING
    CMAKE_EXPORT_NO_PACKAGE_REGISTRY
    CMAKE_INSTALL_BINDIR
    CMAKE_INSTALL_DOCDIR
    CMAKE_INSTALL_INCLUDEDIR
    CMAKE_INSTALL_INFODIR
    CMAKE_INSTALL_LIBDIR
    CMAKE_INSTALL_LIBEXECDIR
    CMAKE_INSTALL_LOCALEDIR
    CMAKE_INSTALL_MANDIR
    CMAKE_INSTALL_OLDINCLUDEDIR
    CMAKE_INSTALL_SBINDIR
    CMAKE_POLICY_DEFAULT_CMP0025

-- Build files have been written to: /build/source/build
cmake: enabled parallel building
building
build flags: -j4 -l4 SHELL=/nix/store/iffl6dlplhv22i2xy7n1w51a5r631kmi-bash-5.1-p16/bin/bash
[  7%] Building CXX object src/shared/CMakeFiles/libShared.dir/Settings.cpp.o
[  7%] Building CXX object src/shared/CMakeFiles/libShared.dir/FileSystem.cpp.o
[ 10%] running cargo
[ 14%] Automatic MOC and UIC for target 3rdParty
    Updating crates.io index
warning: spurious network error (2 tries remaining): [6] Couldn't resolve host name (Could not resolve host: github.com); class=Net (12)
warning: spurious network error (1 tries remaining): [6] Couldn't resolve host name (Could not resolve host: github.com); class=Net (12)
error: failed to get `edit-distance` as a dependency of package `riti v0.1.0 (/build/source/src/engine/riti)`

Caused by:
  failed to load source for dependency `edit-distance`

Caused by:
  Unable to update registry `crates-io`

Caused by:
  failed to fetch `https://github.com/rust-lang/crates.io-index`

Caused by:
  network failure seems to have happened
  if a proxy or similar is necessary `net.git-fetch-with-cli` may help here
  https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli

Caused by:
  [6] Couldn't resolve host name (Could not resolve host: github.com); class=Net (12)
make[2]: *** [src/engine/riti/CMakeFiles/riti_target.dir/build.make:92: src/engine/riti/x86_64-unknown-linux-gnu/release/libriti.a] Error 101
make[1]: *** [CMakeFiles/Makefile2:240: src/engine/riti/CMakeFiles/riti_target.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 14%] Built target 3rdParty_autogen
[ 17%] Linking CXX static library liblibShared.a
[ 17%] Built target libShared
make: *** [Makefile:156: all] Error 2
note: keeping build directory '/tmp/nix-build-openbangla-keyboard-6.0.0-rc1.drv-9'
error: builder for '/nix/store/hgkhmqzhxw7wxr7v9snf4nw3dlcbzn7j-openbangla-keyboard-6.0.0-rc1.drv' failed with exit code 2;
       last 10 log lines:
       >
       > Caused by:
       >   [6] Couldn't resolve host name (Could not resolve host: github.com); class=Net (12)
       > make[2]: *** [src/engine/riti/CMakeFiles/riti_target.dir/build.make:92: src/engine/riti/x86_64-unknown-linux-gnu/release/libriti.a] Error 101
       > make[1]: *** [CMakeFiles/Makefile2:240: src/engine/riti/CMakeFiles/riti_target.dir/all] Error 2
       > make[1]: *** Waiting for unfinished jobs....
       > [ 14%] Built target 3rdParty_autogen
       > [ 17%] Linking CXX static library liblibShared.a
       > [ 17%] Built target libShared
       > make: *** [Makefile:156: all] Error 2
       For full logs, run 'nix log /nix/store/hgkhmqzhxw7wxr7v9snf4nw3dlcbzn7j-openbangla-keyboard-6.0.0-rc1.drv'.

It would be great if there were official build instructions for nixos.

mominul commented 2 years ago

I haven't used nixOS yet, so I don't know the details about the system much. At first glance it seems nixOS is restricting network access which is needed to download required dependencies. Are there any options to permit network access to the build process?

sifat06 commented 2 years ago

I don't think internet can be accessed in the buildphase. But I have found some resources about using rust dependencies for building nix packages https://nixos.org/manual/nixpkgs/stable/#compiling-rust-applications-with-cargo. Although, I have no idea how rust and cargo work.

shadowrylander commented 2 years ago

Would it not be possible to package riti itself, then maybe patch the makefile? Or even just create a custom build phase?

McSinyx commented 2 years ago

I suggest trying to package this in nixpkgs and some maintainer will guide you through the PR.

hqurve commented 2 years ago

@sifat06 see PR https://github.com/NixOS/nixpkgs/pull/181871.

Also, if you are open to it, would it be possible to add the Cargo.lock to riti and bump the submodule?

mominul commented 2 years ago

I can upload a vendored tar archive containing every dependencies included, so no network access will be required. I will do so in the coming weekend.

hqurve commented 2 years ago

Thanks. But I think that might be a bit excessive since just having the Cargo.lock file would tell cargo the exact version (and hash) of each dependency to use while building. Plus it is more easily tracked by version control. In either case it is okay. Thanks again

sifat06 commented 2 years ago

@hqurve Thanks for your help! With your instructions, it built successfully, but I can't seem to find any way to add it to system configuration. Can you also help with that?

hqurve commented 2 years ago

No problem. You should just have to add the Cargo.lock file and the default.nix file to some directory and reference it in your config file. For example, you can have the following directory structure

/etc/nixos
|- configuration.nix
 .....
|- pkgs
   |- open-bangla
     |- default.nix
     |- Cargo.lock

then just add it to systemPackages as such

environment.systemPackages = [
   ....
   ( pkgs.callPackage ./pkgs/open-bangla {}) # the parenthesis are important 
]
sifat06 commented 2 years ago

Thanks. That's installs it as as an application. But I can't seem to find it as a input method either in gnome-settings or in output of ibus list-engine. But if I run /nix/store/wvq1ba86mw6inw5dkzij7sk670jhy561-openbangla-keyboard-2.0.0/share/openbangla-keyboard/ibus-openbangla it works, until I again change the input method. Probably what I think is ibus is not looking for xml files in the /nix/store/wvq1ba86mw6inw5dkzij7sk670jhy561-openbangla-keyboard-2.0.0/share/ibus/component/ directory. Do you have any solutions for this? What I tried is setting IBUS_COMPONENT_DIR to /nix/store/wvq1ba86mw6inw5dkzij7sk670jhy561-openbangla-keyboard-2.0.0/share/ibus/component/, but it didn't worked.

hqurve commented 2 years ago

Sorry, I just added the package and launched the executable without fully knowing how it should be integrated. But the nixos wiki has a good article on using ibus. In the end, I added the following entries to my config and rebooted.

i18n.inputMethod = {
  enabled = "ibus";
  ibus.engines = [ (pkgs.libsForQt5.callpackage ./pkgs/openbangla) ]; # sorry, I forgot that it depended on qt stuff
  ibus.panel = "${pkgs.plasma5Packages.plasma-desktop}/lib/libexec/kimpanel-ibus-panel"; # I tested it on kde
};

Also, please add isIbusEngine=true to the meta section of the openbangla-package.

... I'll make a pr to fix it

sifat06 commented 2 years ago

Thanks! Now it works perfectly! But I forgot to mention that clicking on "OpenBangla Keyboard" icon does nothing. Instead, I had to type openbangla-gui in the terminal to open it as an application. Sorry for that.

mominul commented 2 years ago

Thanks. But I think that might be a bit excessive since just having the Cargo.lock file would tell cargo the exact version (and hash) of each dependency to use while building. Plus it is more easily tracked by version control. In either case it is okay. Thanks again

@hqurve Okay, I'll make sure Cargo.lock file is included in the git repository in the following versions then! Currently, development happens in thedevelop branch, I'll make a PR to unignore Cargo.lock file.

asifakonjee commented 9 months ago

@hqurve... fcitx5-openbangla-keyboard does not work in the new stable release of NixOS. However, ibus-engines.openbangla-keyboard works fine.

asifakonjee commented 8 months ago

I built openbangla from the develop branch using overlay in nixos. It does not work also. fcitx5 crashes the x11 session and in wayland d-bus stops working. Even fcitx5 is forcefully run, it says openbangla keyboard not available.

@mominul @hqurve

asifakonjee commented 8 months ago

My nix pkg overlay to built develop version of openbangla keyboard:

{ config, pkgs, ... }:
let 
  openbangla-keyboard-overlay = final: prev: {
     openbangla-keyboard = prev.fcitx5-openbangla-keyboard.overrideAttrs
     (old: {
         version = "develop-2023-11-05";
         src = final.fetchFromGitHub {
         owner = "openbangla";
         repo = "openbangla-keyboard";
         rev = "7586ea9fef16a5eb69ddb06343de76bae445c729"; # Tip of `develop` as of 2023-11-28
         hash = "sha256-hPywabhWho7Gi3Y01bK7mvi08edKsmb9EbHu7dc69mo=";
         fetchSubmodules = true;
     };
     });
  };

 in 

{
   nixpkgs.overlays = [ openbangla-keyboard-overlay ];
     i18n.inputMethod = {
     enabled = "fcitx5";
     fcitx5.addons = with pkgs; [ 
     fcitx5-m17n
     openbangla-keyboard 
     ];
    };
} 
asifakonjee commented 8 months ago

fcitx5 crash log:

=========================
Fcitx 5.1.5 -- Get Signal No.: 11
Date: try "date -d @1702802244" if you are using GNU date ***
ProcessID: 1816
fcitx5[0x411d1d]
/nix/store/qn3ggz5sf3hkjs2c797xf7nan3amdxmp-glibc-2.38-27/lib/libc.so.6(+0x3da70)[0x7f058c775a70]
/nix/store/fp3gj9rvxypnxm6s69mldialxfbdkdq5-fcitx5-5.1.5/lib/libFcitx5Core.so.7(_ZN5fcitx19InputContextManager18unregisterPropertyERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+0x11c)[0x7f058cee9d6c]
/nix/store/fp3gj9rvxypnxm6s69mldialxfbdkdq5-fcitx5-5.1.5/lib/libFcitx5Core.so.7(_ZN5fcitx27InputContextPropertyFactoryD1Ev+0x1c)[0x7f058ceed29c]
/nix/store/jjayw7x8fx3n5pizrhclpa6zmiz7wrfq-fcitx5-with-addons-5.1.5/lib/fcitx5/openbangla.so(+0x10aa92)[0x7f058850aa92]
/nix/store/jjayw7x8fx3n5pizrhclpa6zmiz7wrfq-fcitx5-with-addons-5.1.5/lib/fcitx5/openbangla.so(+0x11eb39)[0x7f058851eb39]
/nix/store/fp3gj9rvxypnxm6s69mldialxfbdkdq5-fcitx5-5.1.5/lib/libFcitx5Core.so.7(+0x97ccb)[0x7f058cf05ccb]
/nix/store/fp3gj9rvxypnxm6s69mldialxfbdkdq5-fcitx5-5.1.5/lib/libFcitx5Core.so.7(+0x9b120)[0x7f058cf09120]
/nix/store/fp3gj9rvxypnxm6s69mldialxfbdkdq5-fcitx5-5.1.5/lib/libFcitx5Core.so.7(+0x9c21d)[0x7f058cf0a21d]
/nix/store/fp3gj9rvxypnxm6s69mldialxfbdkdq5-fcitx5-5.1.5/lib/libFcitx5Core.so.7(_ZN5fcitx12AddonManager5addonERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEb+0x8f)[0x7f058cf07c6f]
/nix/store/fp3gj9rvxypnxm6s69mldialxfbdkdq5-fcitx5-5.1.5/lib/libFcitx5Core.so.7(+0x4a62f)[0x7f058ceb862f]
/nix/store/fp3gj9rvxypnxm6s69mldialxfbdkdq5-fcitx5-5.1.5/lib/libFcitx5Utils.so.2(+0x4cad2)[0x7f058cdcbad2]
/nix/store/i0sdqs34r68if9s4sfmpixnnj36npiwj-systemd-254.6/lib/libsystemd.so.0(+0x8d374)[0x7f058c6b8374]
/nix/store/i0sdqs34r68if9s4sfmpixnnj36npiwj-systemd-254.6/lib/libsystemd.so.0(sd_event_dispatch+0xc8)[0x7f058c6b87c8]
/nix/store/i0sdqs34r68if9s4sfmpixnnj36npiwj-systemd-254.6/lib/libsystemd.so.0(sd_event_run+0xc0)[0x7f058c6b92d0]
/nix/store/i0sdqs34r68if9s4sfmpixnnj36npiwj-systemd-254.6/lib/libsystemd.so.0(sd_event_loop+0x7f)[0x7f058c6b953f]
/nix/store/fp3gj9rvxypnxm6s69mldialxfbdkdq5-fcitx5-5.1.5/lib/libFcitx5Utils.so.2(_ZN5fcitx9EventLoop4execEv+0x11)[0x7f058cdcbc71]
/nix/store/fp3gj9rvxypnxm6s69mldialxfbdkdq5-fcitx5-5.1.5/lib/libFcitx5Core.so.7(_ZN5fcitx8Instance4execEv+0x54)[0x7f058cece434]
fcitx5[0x410547]
/nix/store/qn3ggz5sf3hkjs2c797xf7nan3amdxmp-glibc-2.38-27/lib/libc.so.6(+0x27fce)[0x7f058c75ffce]
/nix/store/qn3ggz5sf3hkjs2c797xf7nan3amdxmp-glibc-2.38-27/lib/libc.so.6(__libc_start_main+0x89)[0x7f058c760089]
fcitx5[0x410cc5]
mominul commented 8 months ago

I am not familiar with Nix environment, so I can't be helpful that much. @hqurve would be the most knowledgeable here.

About the fcitx crash, can you report it to the fcitx's bug tracker?

asifakonjee commented 8 months ago

@mominul ... I will report the crash. But When I install fcitx5-m17n only without openbangla keyboard, it works just fine. I can add m17n languages like Probhat, National and even Bijoy Keyboard layouts.

I encountered the same problem in Arch Linux with fcitx5 once. I was trying to install openbangla keyboard from AUR with openbangla-keyboard-git to work with fcitx5 and it crashed the system. But when I installed fcitx5-openbangla-git from AUR, it worked fine again.

Screenshot 20231218 1414

P.S. - In my practical experience, manually building openbangla keyboard from develop branch works completely fine in almost all other distros ( Debian, Fedora, Arch, Void etc).

mominul commented 8 months ago

@hqurve @eclairevoyant as #364 has landed, can you update the Nix installation script?

asifakonjee commented 8 months ago

@mominul .... This error shows up now in Nix if built from develop version.

[ 14%] running cargo
error: failed to select a version for the requirement `ahash = "^0.8"`
candidate versions found which didn't match: 0.7.6
location searched: directory source `/build/cargo-deps-vendor.tar.gz` (which is replacing registry `crates-io`)
required by package `riti v0.1.0 (/build/source/src/engine/riti)`
perhaps a crate was updated and forgotten to be re-vendored?
mominul commented 8 months ago

There are new crate updates in the riti library, so the libraries(crate) needs to be re-vendored. You can request the nix pkg maintainers to revendor the crates on their issues page.

asifakonjee commented 8 months ago

@mominul ... I forked the develop branch and changed the files as advised from fcitx5 issue. Now i have built from my forked repo and atlast it is working!!! আমার আফসোস মিটলো শেষ পর্যন্ত!

বি.দ্র. - আমি একটা কাস্টম লোগো ব্যবহার করেছি এবং এজন্যে আন্তরিকভাবে ক্ষমাপ্রার্থী।

Screenshot 20231226 1929

mominul commented 8 months ago

That's great :tada: