tauri-apps / tauri

Build smaller, faster, and more secure desktop applications with a web frontend.
https://tauri.app
Apache License 2.0
79.46k stars 2.36k forks source link

[bug] AppImage build fail with Nix Flake #8535

Open francis2tm opened 6 months ago

francis2tm commented 6 months ago

Describe the bug

Hello, I'm on Ubuntu 22.04 but using Nix package manager. After following your prerequisites for NixOS and attempting to build a tauri project with the below flake.nix, I got the following error:

-- Running input plugin: gtk --
[gtk/stderr] chmod: cannot access 'edgen-chat.AppDir/usr/lib64': No such file or directory
[gtk/stdout] Installing AppRun hook
[gtk/stderr] cp: cannot stat '/nix/store/2if9iy5cy0bicwafllpa2aiq30v26app-glib-2.78.1/share/glib-2.0/schemas': No such file or directory
[gtk/stdout] Installing GLib schemas
ERROR: Failed to run plugin: gtk (exit code: 1)
       Error [tauri_cli_node] failed to bundle project: error running appimage.sh
error Command failed with exit code 1.

Thanks in advance

Reproduction

flake.nix:

{
    inputs = {
        nixpkgs.url = "nixpkgs";
        rust-overlay.url = "github:oxalica/rust-overlay";
        flake-utils.url = "github:numtide/flake-utils";
    };

    outputs = { self, nixpkgs, rust-overlay, flake-utils }:
        flake-utils.lib.eachDefaultSystem (system:
        let
            overlays = [ (import rust-overlay) ];
            pkgs = import nixpkgs {
                inherit system overlays;
            };

            rust-toolchain = pkgs.rust-bin.selectLatestNightlyWith (toolchain: toolchain.default.override {
                extensions = [ "rust-src" ];
                #targets = [ "wasm32-unknown-unknown" ];
            });

            nativeBuildInputs = with pkgs; [
                pkg-config
                rust-toolchain
            ];

            libraries = with pkgs;[
                webkitgtk
                gtk3
                cairo
                gdk-pixbuf
                glib
                dbus
                openssl_3
                librsvg
            ];

            packages = with pkgs; [
                curl
                wget
                dbus
                openssl_3
                glib
                gtk3
                gdk-pixbuf
                libsoup
                pango
                harfbuzz
                at-spi2-atk
                cairo
                webkitgtk
                librsvg
                yarn
                nodejs_18
            ];

            buildInputs = packages;
        in
        rec {
            # `nix develop`
            devShell = pkgs.mkShell {
                inherit buildInputs nativeBuildInputs;
                shellHook = ''
                # For rust-analyzer 'hover' tooltips to work.
                export RUST_SRC_PATH=${rust-toolchain}

                # add ~/.cargo/bin to PATH for crates installed with `cargo install`
                export PATH=$PATH:$HOME/.cargo/bin

                export RUST_BACKTRACE=1

                # tauri
                export WEBKIT_DISABLE_COMPOSITING_MODE=1
                export LD_LIBRARY_PATH=${pkgs.lib.makeLibraryPath libraries}:$LD_LIBRARY_PATH
                export XDG_DATA_DIRS=${pkgs.gsettings-desktop-schemas}/share/gsettings-schemas/${pkgs.gsettings-desktop-schemas.name}:${pkgs.gtk3}/share/gsettings-schemas/${pkgs.gtk3.name}:$XDG_DATA_DIRS
                '';
            };
        });
}

Expected behavior

Successful build with no issues.

Full tauri info output

[⚠] Environment
    - OS: Ubuntu 22.04 X64
    ✔ webkit2gtk-4.0: 2.42.3
    ✔ rsvg2: 2.57.0
    ✔ rustc: 1.77.0-nightly (3d0e6bed6 2023-12-21)
    ✔ cargo: 1.77.0-nightly (1a2666ddd 2023-12-17)
    ⚠ rustup: not installed!
      If you have rust installed some other way, we recommend uninstalling it
      then use rustup instead. Visit https://rustup.rs/
    ⚠ Rust toolchain: couldn't be detected!
      Maybe you don't have rustup installed? if so, Visit https://rustup.rs/
    - node: 18.19.0
    - yarn: 1.22.19
    - npm: 10.2.3

[-] Packages
    - tauri [RUST]: 1.5.4
    - tauri-build [RUST]: 1.5.1
    - wry [RUST]: 0.24.7
    - tao [RUST]: 0.16.5
    - tauri-cli [RUST]: 1.5.9
    - @tauri-apps/api : not installed!
    - @tauri-apps/cli [NPM]: 1.5.9

[-] App
    - build-type: bundle
    - CSP: unset
    - distDir: ../out
    - devPath: http://localhost:3000/
    - framework: React (Next.js)
    - bundler: Webpack
thedavidmeister commented 5 months ago

seeing same here https://github.com/rainlanguage/rain.orderbook/actions/runs/7479976179/job/20358351394?pr=57

note though that this is just ubuntu with nix not nixos

yeus commented 3 months ago

I have the same problem on NixOS:

{
  description = "Nix Development Flake for Taskyon";
  inputs = {
    flake-utils.url = "github:numtide/flake-utils";
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
  };

  outputs = { self, nixpkgs, flake-utils }:

    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = import nixpkgs { inherit system; };

        # this is all tauri-related stuff
        libraries = with pkgs; [

          # tauri deps
          webkitgtk
          gtk3
          cairo
          gdk-pixbuf
          glib
          dbus
          openssl_3
          librsvg
          libsoup

          # this is needed for appimage by build_appimage.sh ...
          libgpg-error 
          xorg.libX11
          xorg.libSM
          xorg.libICE
          xorg.libxcb
          fribidi
          fontconfig
          libthai
          harfbuzz
          freetype
          libglvnd
          mesa
          libdrm
        ];
        packages = with pkgs; [
          rustfmt
          rustc
          cargo

          # for tauri
          curl
          wget
          pkg-config

          # node
          yarn
          nodejs_21
        ];
      in {
        devShells.default = pkgs.mkShell rec {
          name = "xyntopia_gui";
          buildInputs = libraries ++ packages;
          shellHook = ''

            if [ -f ./.env ]; then
              set -a  # automatically export all variables
              source ./.env
              set +a
            fi

            export PATH="$(pwd)/node_modules/.bin:$PATH"

            export LD_LIBRARY_PATH=${
              pkgs.lib.makeLibraryPath libraries
            }:$LD_LIBRARY_PATH
            export XDG_DATA_DIRS=${pkgs.gsettings-desktop-schemas}/share/gsettings-schemas/${pkgs.gsettings-desktop-schemas.name}:${pkgs.gtk3}/share/gsettings-schemas/${pkgs.gtk3.name}:$XDG_DATA_DIRS
          '';
        };
      });
}

tauri-info:

[⚠] Environment
    - OS: NixOS 23.11.0 X64
    ✔ webkit2gtk-4.0: 2.42.5
    ✔ rsvg2: 2.57.0
    ✔ rustc: 1.73.0 (cc66ad468 2023-10-03) (built from a source tarball)
    ✔ cargo: 1.73.0
    ⚠ rustup: not installed!
      If you have rust installed some other way, we recommend uninstalling it
      then use rustup instead. Visit https://rustup.rs/
    ⚠ Rust toolchain: couldn't be detected!
      Maybe you don't have rustup installed? if so, Visit https://rustup.rs/
    - node: 21.6.2
    - yarn: 1.22.19
    - npm: 10.2.4

[-] Packages
    - tauri [RUST]: 1.1.0
    - tauri-build [RUST]: 1.1.0
    - wry [RUST]: 0.21.1
    - tao [RUST]: 0.14.0
    - @tauri-apps/api [NPM]: 1.5.3
    - @tauri-apps/cli [NPM]: 1.5.10

[-] App
    - build-type: bundle
    - CSP: unset
    - distDir: ../dist/spa
    - devPath: http://localhost:8080/
    - framework: Vue.js (Quasar)
    - bundler: Webpack

When running tauri build -v I get:

-- Running input plugin: gtk --
[gtk/stdout] Installing AppRun hook
[gtk/stderr] chmod: cannot access 'taskyon.AppDir/usr/lib64': No such file or directory
[gtk/stdout] Installing GLib schemas
[gtk/stderr] cp: cannot stat '/nix/store/3j4bisnb0bk9vzpfxbcmv4v51pkha8lx-glib-2.78.4/share/glib-2.0/schemas': No such file or directory
ERROR: Failed to run plugin: gtk (exit code: 1)
       Error [tauri_cli_node] failed to bundle project: error running appimage.sh
yeus commented 3 months ago

And the same thing happens, when I use this, basically replacing all rust dependencies with the tauri packages from nixpcks:

{
  description = "Nix Development Flake for Taskyon";

  inputs = {
    flake-utils.url = "github:numtide/flake-utils";
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
  };

  outputs = { self, nixpkgs, flake-utils }:

    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = import nixpkgs { inherit system; };

        # this is all tauri-related stuff
        libraries = with pkgs; [
          cargo-tauri
        ];
        packages = with pkgs; [
          # rust
          rustfmt
          #clippy
          rustc
          cargo

          # for tauri
          curl
          wget
          pkg-config

          # node
          yarn
          nodejs_21
        ];
      in {
        devShells.default = pkgs.mkShell rec {
          name = "xyntopia_gui";
          # TODO: what is this for? nativeBuildInputs = [ pkgs.bashInteractive ];
          buildInputs = libraries ++ packages;
          shellHook = ''
            if [ -f ./.env ]; then
              set -a  # automatically export all variables
              source ./.env
              set +a
            fi

            export PATH="$(pwd)/node_modules/.bin:$PATH"

            export LD_LIBRARY_PATH=${
              pkgs.lib.makeLibraryPath libraries
            }:$LD_LIBRARY_PATH
            export XDG_DATA_DIRS=${pkgs.gsettings-desktop-schemas}/share/gsettings-schemas/${pkgs.gsettings-desktop-schemas.name}:${pkgs.gtk3}/share/gsettings-schemas/${pkgs.gtk3.name}:$XDG_DATA_DIRS
          '';
        };
      });
}
yeus commented 3 weeks ago

ok, I did a little more investigation on this.

so..

this file here:

[gtk/stderr] cp: cannot stat '/nix/store/3j4bisnb0bk9vzpfxbcmv4v51pkha8lx-glib-2.78.4/share/glib-2.0/schemas': No such file or directory

it is part of the "glib.dev" package.. I have added "glib.dev" to my flake.nix but it doesn't not seem to make any difference...

from nix-locate --top-level /share/glib-2.0/schemas: glib.dev 1 d /nix/store/8gkrqg6bx8q4rnhvs7zg6hpqzw870mp7-glib-2.78.4-dev/share/glib-2.0/schemas

this one has a different hash, so probably is there on my system for some other reason :) --> I am not sure, what to do about this from here.

Eveeifyeve commented 3 weeks ago

try this package

{
  lib,
  buildNpmPackage,
  openssl,
  stdenv,
  pkg-config,
  glibc,
  libsoup_3,
  gtk3,
  cairo,
  webkitgtk_4_1,
  nodejs-slim,
  cargo-tauri,
  cargo,
  rustPlatform,
  rustc,
  bun,
  darwin,
  llvmPackages,
  rustup,
  libiconv,
}:

let
  inherit (darwin.apple_sdk.frameworks)
    Security
    SystemConfiguration
    AppKit
    WebKit
    CoreFoundation
    ;
in
buildNpmPackage rec {
  pname = "Example Name";
  version = "0.0.1-dev";
  dontNpmBuild = true; # Don't want to npm build since it will produce the application from tauri

  src = ./..;

  npmDepsHash = "sha256-eNAOAjBZQ/L9MMHRFOZi6+wIsj0axF6y7bbdswOuPww=";

  cargoDeps = rustPlatform.importCargoLock {
    lockFile = "${src}/src-tauri/Cargo.lock";
    outputHashes = {
      "tauri-plugin-clipboard-manager-2.1.0-beta.1" = "sha256-2F+OkX92B2/aJva86orotHc7mYUZuaYAmKx50dDp2Sc=";
    };
  };

  configurePhase = ''
    export HOME=$(mktemp -d)
  '';

  preBuild = if stdenv.isLinux then "cargo tauri build -b deb" else "cargo tauri build -b app";
  cargoRoot = "src-tauri/";

  preInstall =
    if stdenv.isLinux then
      "mv src-tauri/target/release/bundle/deb/*/data/usr/ \"$out\""
    else
      "mv src-tauri/target/release/bundle/macos/* \"$out/\"";

  nativeBuildInputs =
    [
      pkg-config
      rustPlatform.cargoSetupHook
      cargo
      rustc
      cargo-tauri
      nodejs-slim
      openssl
      bun
    ]
    ++ lib.optionals stdenv.isDarwin [
      llvmPackages.libcxxStdenv
      llvmPackages.libcxxClang
      llvmPackages.libcxx
      darwin.libobjc
      darwin.libiconv
      libiconv
      Security
      SystemConfiguration
      AppKit
      WebKit
      CoreFoundation
    ];

  buildInputs =
    [ openssl ]
    ++ lib.optionals stdenv.isLinux [
      glibc
      libsoup_3
      cairo
      gtk3
      webkitgtk_4_1
    ]
    ++ lib.optionals stdenv.isDarwin [
      Security
      darwin.libiconv
      SystemConfiguration
      AppKit
      WebKit
      rustup
    ];

  meta = with lib; {
    description = "Example description";
    homepage = "https://example.com";
    license = with licenses; [ epl20 ];
    mainProgram = "program";
    maintainers = with maintainers; [ ];
  };
}
purepani commented 2 weeks ago

Hi, I believe I have located something that might be causing this. I was trying to build https://github.com/Martichou/rquickshare, and was running into this error. If you run pnpm build --verbose, you get the following error:

     Running [tauri_bundler::bundle::common] Command `/home/purewater/projects/rquickshare/frontend/src-tauri/target/release/bundle/appimage/build_appimage.sh `
+ export ARCH=x86_64
+ ARCH=x86_64
+ APPIMAGE_BUNDLE_XDG_OPEN=0
+ APPIMAGE_BUNDLE_GSTREAMER=0
+ TRAY_LIBRARY_PATH='/nix/store/nm9608b5y801fq2p73nl7k80z8kcbmh2-glib-2.80.2/lib -L/nix/store/6ivp7s6qwf02d3siggfjrh3ayf2y056v-gtk+3-3.24.42/lib -L/nix/store/yy2r81w57f927gzgj5spkzihcqlyip3i-at-spi2-core-2.52.0/lib -L/nix/store/09788nmfm9gz27skmsr1cla96gsh938c-cairo-1.18.0/lib -L/nix/store/3jbl3zgj68ff6cngbzbkk82y1ckd5552-gdk-pixbuf-2.42.12/lib -L/nix/store/461d831ri7sd2bc2dplgigqas3f09qa9-pango-1.52.2/lib -L/nix/store/3kgm5ynckkxq46h5ycn6c73ndny6sdn7-harfbuzz-8.4.0/lib -L/nix/store/vw10czhhgqyh0ygwb9kwkqajyqnynqwq-libayatana-appindicator-0.5.92/lib -L/nix/store/dywnqj9gmyy79kdvflc8ywkfwvryvc0k-ayatana-ido-0.10.2/lib -L/nix/store/5ivs7x7ngmlqgc1wk0hhdj7d3q7s60z5-libdbusmenu-gtk3-16.04.0/lib/libayatana-appindicator3.so.1'
+ '[' x86_64 == i686 ']'
+ linuxdeploy_arch=x86_64
+ mkdir -p r-quick-share.AppDir
+ cp -r ../appimage_deb/data/usr r-quick-share.AppDir
+ cd r-quick-share.AppDir
+ mkdir -p usr/bin
+ mkdir -p usr/lib
+ [[ 0 != \0 ]]
+ [[ /nix/store/nm9608b5y801fq2p73nl7k80z8kcbmh2-glib-2.80.2/lib -L/nix/store/6ivp7s6qwf02d3siggfjrh3ayf2y056v-gtk+3-3.24.42/lib -L/nix/store/yy2r81w57f927gzgj5spkzihcqlyip3i-at-spi2-core-2.52.0/lib -L/nix/store/09788nmfm9gz27skmsr1cla96gsh938c-cairo-1.18.0/lib -L/nix/store/3jbl3zgj68ff6cngbzbkk82y1ckd5552-gdk-pixbuf-2.42.12/lib -L/nix/store/461d831ri7sd2bc2dplgigqas3f09qa9-pango-1.52.2/lib -L/nix/store/3kgm5ynckkxq46h5ycn6c73ndny6sdn7-harfbuzz-8.4.0/lib -L/nix/store/vw10czhhgqyh0ygwb9kwkqajyqnynqwq-libayatana-appindicator-0.5.92/lib -L/nix/store/dywnqj9gmyy79kdvflc8ywkfwvryvc0k-ayatana-ido-0.10.2/lib -L/nix/store/5ivs7x7ngmlqgc1wk0hhdj7d3q7s60z5-libdbusmenu-gtk3-16.04.0/lib/libayatana-appindicator3.so.1 != \0 ]]
+ echo 'Copying appindicator library /nix/store/nm9608b5y801fq2p73nl7k80z8kcbmh2-glib-2.80.2/lib -L/nix/store/6ivp7s6qwf02d3siggfjrh3ayf2y056v-gtk+3-3.24.42/lib -L/nix/store/yy2r81w57f927gzgj5spkzihcqlyip3i-at-spi2-core-2.52.0/lib -L/nix/store/09788nmfm9gz27skmsr1cla96gsh938c-cairo-1.18.0/lib -L/nix/store/3jbl3zgj68ff6cngbzbkk82y1ckd5552-gdk-pixbuf-2.42.12/lib -L/nix/store/461d831ri7sd2bc2dplgigqas3f09qa9-pango-1.52.2/lib -L/nix/store/3kgm5ynckkxq46h5ycn6c73ndny6sdn7-harfbuzz-8.4.0/lib -L/nix/store/vw10czhhgqyh0ygwb9kwkqajyqnynqwq-libayatana-appindicator-0.5.92/lib -L/nix/store/dywnqj9gmyy79kdvflc8ywkfwvryvc0k-ayatana-ido-0.10.2/lib -L/nix/store/5ivs7x7ngmlqgc1wk0hhdj7d3q7s60z5-libdbusmenu-gtk3-16.04.0/lib/libayatana-appindicator3.so.1'
Copying appindicator library /nix/store/nm9608b5y801fq2p73nl7k80z8kcbmh2-glib-2.80.2/lib -L/nix/store/6ivp7s6qwf02d3siggfjrh3ayf2y056v-gtk+3-3.24.42/lib -L/nix/store/yy2r81w57f927gzgj5spkzihcqlyip3i-at-spi2-core-2.52.0/lib -L/nix/store/09788nmfm9gz27skmsr1cla96gsh938c-cairo-1.18.0/lib -L/nix/store/3jbl3zgj68ff6cngbzbkk82y1ckd5552-gdk-pixbuf-2.42.12/lib -L/nix/store/461d831ri7sd2bc2dplgigqas3f09qa9-pango-1.52.2/lib -L/nix/store/3kgm5ynckkxq46h5ycn6c73ndny6sdn7-harfbuzz-8.4.0/lib -L/nix/store/vw10czhhgqyh0ygwb9kwkqajyqnynqwq-libayatana-appindicator-0.5.92/lib -L/nix/store/dywnqj9gmyy79kdvflc8ywkfwvryvc0k-ayatana-ido-0.10.2/lib -L/nix/store/5ivs7x7ngmlqgc1wk0hhdj7d3q7s60z5-libdbusmenu-gtk3-16.04.0/lib/libayatana-appindicator3.so.1
+ cp /nix/store/nm9608b5y801fq2p73nl7k80z8kcbmh2-glib-2.80.2/lib -L/nix/store/6ivp7s6qwf02d3siggfjrh3ayf2y056v-gtk+3-3.24.42/lib -L/nix/store/yy2r81w57f927gzgj5spkzihcqlyip3i-at-spi2-core-2.52.0/lib -L/nix/store/09788nmfm9gz27skmsr1cla96gsh938c-cairo-1.18.0/lib -L/nix/store/3jbl3zgj68ff6cngbzbkk82y1ckd5552-gdk-pixbuf-2.42.12/lib -L/nix/store/461d831ri7sd2bc2dplgigqas3f09qa9-pango-1.52.2/lib -L/nix/store/3kgm5ynckkxq46h5ycn6c73ndny6sdn7-harfbuzz-8.4.0/lib -L/nix/store/vw10czhhgqyh0ygwb9kwkqajyqnynqwq-libayatana-appindicator-0.5.92/lib -L/nix/store/dywnqj9gmyy79kdvflc8ywkfwvryvc0k-ayatana-ido-0.10.2/lib -L/nix/store/5ivs7x7ngmlqgc1wk0hhdj7d3q7s60z5-libdbusmenu-gtk3-16.04.0/lib/libayatana-appindicator3.so.1 usr/lib
cp: invalid option -- '/'
Try 'cp --help' for more information.
       Error [tauri_cli_node] failed to bundle project: error running appimage.sh
 ELIFECYCLE  Command failed with exit code 1.

This looks a lot like the output of pkg-config ayatana-appindicator3-0.1 --libs-only-L, but without the leading -L flag in the first input, leading me to think that there was an assumption that pkg-config would only ever output one value for the path of a library. Following the breadcrumbs in the code:

This is copy command causing the bug. This reads from an environment variable TAURI_TRAY_LIBRARY_PATH. This is set here. The code that sets path(which the env var is set to) always leads to calling [this function]((https://github.com/tauri-apps/tauri/blob/16641723b001b1172d1962e9fa80f5fafbc570f0/tooling/cli/src/interface/rust.rs#L1442), which, as written in the comment, and as evident in the line

let word = output.stdout[2..].to_vec();

does in fact make that assumption that pkg-config only outputs one library, which it does not do on nixos.

I'm not sure how this might need to be fixed, but given that this can happen on any system where there are multiple versions of a package, this should probably be fixed here as opposed to being simply patched in nixpkgs.