Home Explore Blog Models CI



nixpkgs

doc/hooks/tauri.section.md
ee0a28213980f9294c5cbf3921f0a103c8a50e1c8ce76c0f00000003000008aa
# cargo-tauri.hook {#tauri-hook}

[Tauri](https://tauri.app/) is a framework for building smaller, faster, and
more secure desktop applications with a web frontend.

In Nixpkgs, `cargo-tauri.hook` overrides the default build and install phases.

## Example code snippet {#tauri-hook-example-code-snippet}

```nix
{
  lib,
  stdenv,
  rustPlatform,
  fetchNpmDeps,
  cargo-tauri,
  glib-networking,
  nodejs,
  npmHooks,
  openssl,
  pkg-config,
  webkitgtk_4_1,
  wrapGAppsHook4,
}:

rustPlatform.buildRustPackage (finalAttrs: {
  # ...

  cargoHash = "...";

  # Assuming our app's frontend uses `npm` as a package manager
  npmDeps = fetchNpmDeps {
    name = "${finalAttrs.pname}-${finalAttrs.version}-npm-deps";
    inherit (finalAttrs) src;
    hash = "...";
  };

  nativeBuildInputs = [
    # Pull in our main hook
    cargo-tauri.hook

    # Setup npm
    nodejs
    npmHooks.npmConfigHook

    # Make sure we can find our libraries
    pkg-config
  ]
  ++ lib.optionals stdenv.hostPlatform.isLinux [ wrapGAppsHook4 ];

  buildInputs = lib.optionals stdenv.hostPlatform.isLinux [
    glib-networking # Most Tauri apps need networking
    openssl
    webkitgtk_4_1
  ];

  # Set our Tauri source directory
  cargoRoot = "src-tauri";
  # And make sure we build there too
  buildAndTestSubdir = finalAttrs.cargoRoot;

  # ...
})
```

## Variables controlling cargo-tauri {#tauri-hook-variables-controlling}

### Tauri Exclusive Variables {#tauri-hook-exclusive-variables}

#### `tauriBuildFlags` {#tauri-build-flags}

Controls the flags passed to `cargo tauri build`.

#### `tauriBundleType` {#tauri-bundle-type}

The [bundle type](https://tauri.app/v1/guides/building/) to build.

#### `dontTauriBuild` {#dont-tauri-build}

Disables using `tauriBuildHook`.

#### `dontTauriInstall` {#dont-tauri-install}

Disables using `tauriInstallPostBuildHook` and `tauriInstallHook`.

### Honored Variables {#tauri-hook-honored-variables}

Along with those found in [](#compiling-rust-applications-with-cargo), the
following variables used by `cargoBuildHook` and `cargoInstallHook` are honored
by the cargo-tauri setup hook.

- `buildAndTestSubdir`
- `cargoBuildType`
- `cargoBuildNoDefaultFeatures`
- `cargoBuildFeatures`

Chunks
40116178 (1st chunk of `doc/hooks/tauri.section.md`)
Title: `cargo-tauri.hook` in Nixpkgs
Summary
This chunk describes `cargo-tauri.hook` within Nixpkgs, which is used to build Tauri applications—a framework for desktop apps with web frontends. The hook overrides standard build and install phases. An example Nix snippet illustrates its use, detailing how to set up `npm` dependencies, include necessary `nativeBuildInputs` (like `cargo-tauri.hook`, `nodejs`, `npmConfigHook`, `pkg-config`), `buildInputs` (e.g., `glib-networking`, `openssl`, `webkitgtk_4_1`), and define `cargoRoot` and `buildAndTestSubdir`. It also lists specific Tauri-exclusive variables such as `tauriBuildFlags`, `tauriBundleType`, `dontTauriBuild`, and `dontTauriInstall`, alongside other general `cargo` variables it honors.