tauri: [bug] AppImage build fail with Nix Flake

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

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 6
  • Comments: 28 (1 by maintainers)

Commits related to this issue

Most upvoted comments

Hey so me and @getchoo have been working a hook that might fix this.

The above PR has been merged. Tauri packages can now be built in nixpkgs via cargo-tauri.hook, which is documented here – many real world examples can also be searched through here

Hey so me and @getchoo have been working a hook that might fix this.

Mention PR: https://github.com/NixOS/nixpkgs/pull/335751

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

@getchoo I’m using Tauri v2 and struggling to build the package. The cargo-tauri.hook looks be only compatible with the Tauri v1.

Is there some progress to updating the hook?

I tried to update it myself, without any luck yet. I would be willing to help, but I’m not sure where.

There is a pr that’s in progress of updating tauri here: https://github.com/NixOS/nixpkgs/pull/346277

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.