`libQt5Widgets.so.5` failed to link to the excutable

I’d like to build linuxdeepin/unilang with nix, but it crashed at runtime:

unilang: error while loading shared libraries: libQt5Widgets.so.5: cannot open shared object file: No such file or directory

During the build process, /nix/store/<hash>-qtbase-5.15.12 was reported as unreferenced input.

The following workrounds did not work:

  • shell: nix shell nixpkgs#libsForQt5.qt5.qtbase nixpkgs#libsForQt5.qt5.qtdeclarative .

  • flake.nix: qtWrapperArgs = [ ''--prefix LD_LIBRARY_PATH : ${pkgs.libsForQt5.qt5.qtbase}/lib'' ];

  • flake.nix: dontWrapQtApps = true; preFixup = ''wrapQtApp "$out/bin/unilang" --prefix LD_LIBRARY_PATH : ${pkgs.libsForQt5.qt5.qtbase}/lib'';

  • flake.nix: change buildInputs to propagatedBuildInputs

  • shell: export LD_LIBRARY_PATH='/nix/store/<hash>-qtbase-5.15.12/lib'

flake.nix:

{
  description = "Unilang, a general purpose programming language";
  inputs = {
    nixpkgs.url = "nixpkgs";
  };
  outputs = flakeInputs @ { ... }: let
    flakeOutputs = flakeInputs.self.outputs;
    system = "x86_64-linux";
    inherit (flakeInputs.nixpkgs) lib;
    pkgs = flakeInputs.nixpkgs.legacyPackages.${system};
  in {
    packages.${system} = {
      default = flakeOutputs.packages.${system}.unilang;
      unilang = pkgs.stdenv.mkDerivation {
        pname = "unilang";
        version = "0.13";

        src = pkgs.fetchFromGitHub {
          owner = "linuxdeepin";
          repo = "unilang";
          rev = "V0.13";
          hash = "sha256-GWY9FtbX3+FrxRSKWPcJKXm43tWF6AHggjaLr3YtN/8=";
          fetchSubmodules = true;
        };
        nativeBuildInputs = with pkgs; [
          git
          pkg-config
          parallel
          lld
          libsForQt5.qt5.wrapQtAppsHook
        ];
        buildInputs = with pkgs; [
          libffi
          libsForQt5.qt5.qtbase
          libsForQt5.qt5.qtdeclarative
        ];
        buildPhase =  ''
          runHook preInstall

          export Unilang_Output="''${out}/bin/unilang"
          export Unilang_BuildDir='.'
          export UNILANG_NO_LLVM='1'
          export LDFLAGS='-fuse-ld=lld'
          export Verbose='1'
          source 'build.sh'

          runHook postInstall
        '';

        meta = with lib; {
          description = "Unilang, a general purpose programming language";
          longDescription = ''
            Unilang is a general purpose programming language project proposed to adapt to more effective and flexible development of desktop environment applications.
          '';
          license = licenses.bsd2Patent;
        };
      };
    };
  };
}