Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] upstream nix requirements to nixpkgs #8588

Open
thedavidmeister opened this issue Jan 11, 2024 · 19 comments · May be fixed by tauri-apps/tauri-docs#2413
Open

[feat] upstream nix requirements to nixpkgs #8588

thedavidmeister opened this issue Jan 11, 2024 · 19 comments · May be fixed by tauri-apps/tauri-docs#2413
Labels
help wanted Help is requested to fix this issue platform: Nix/NixOS Issues specific to NixOS or Nix tooling type: feature request

Comments

@thedavidmeister
Copy link

Describe the problem

Not sure if this is a bug or a feature, it's borderline imo.

Basically what I expect is that when i use the cargo-tauri derivation from nixpkgs that i don't also have to copy and paste a bunch of additional prerequisites from the tauri docs in order to get things half working.

I say half working because I'm still running into bugs with cargo-tauri, especially on mac, one of which i already pushed a fix for NixOS/nixpkgs#279771 (comment)

I also see that one of the dependencies, webkitgtk is marked as broken in nixpkgs on mac, but listed as a dependency on the tauri docs. I understand the nix docs say nixos rather than nix but it's pretty common use case for people working on linux/mac to be using nix rather than committing to a full nixos setup.

Additionally, I noticed that the prerequisites in the docs only work for a nix develop style shell, they don't work for nix run, say if I wanted to lift some standard tauri tasks into a package, the instructions don't cover that. This is because the additional steps of setting up the library etc. are limited to a shellHook.

Further, the prerequisites are missing required steps in the shellHook. We found that when tauri is built via nix there is a need to disable webkit compositing mode like export WEBKIT_DISABLE_COMPOSITING_MODE=1 in the shellHook. This seems to be some known tribal knowledge, as it appears in snippets from other people such as #8535 but it's not listed in the prerequisites in the docs.

There are other issues like #8535 that I expect are probably not issues with tauri itself, but some additional work that needs to be done on the nix side. At the moment it isn't clear where to put or discuss such a fix, would it just result in more documented boilerplate? or is there a way to codify it?

Stepping back a bit, I feel like the meta issue is that fixes to issues are being pushed into the tauri docs (or not) rather than some derivation that is directly maintainable and reusable downstream.

Describe the solution you'd like

Tauri maintains the derivation in nixpkgs with the same dependencies that it outlines in the documentation, so then there are no manual steps for consumers.

Alternatives considered

Another alternative would be that tauri maintains their own nix code separate to nixpkgs, such as an overlay or flake.

This would be fine too, the main problem to solve is to lift dependencies and other issues from docs and into nix-compatible code somewhere.

Additional context

No response

@FabianLars
Copy link
Member

I think the main blocker here is that nobody in the tauri wg uses nix or nixos and i personally am not interested in getting into it either.

The docs were contributed (and are semi-maintained) by the community. And together with my prior statement we currently rely on them to also fix issues with it / keep it updated.
Same for cargo-tauri, i'm not sure we even knew it exists (and i for one don't even understand it 😅).

I also see that one of the dependencies, webkitgtk is marked as broken in nixpkgs on mac, but listed as a dependency on the tauri docs. I understand the nix docs say nixos rather than nix but it's pretty common use case for people working on linux/mac to be using nix rather than committing to a full nixos setup.

Is it possible then to mark webkitgtk as platform specific? Because it is a hard dependency on Linux but indeed not used at all on macOS. But you're right, we should probably differntiate between nix and nixos (probably by adding a new nix section to macos. Or wherever we could fit it into the new docs.)


Anyway, i believe that for the time being this is something we have to rely on the community to maintain if they want to use it.
Alternatively, if our docs are indeed that wrong we should consider to remove it / not migrate it to the new site (beta.tauri.app) until there's an actually working version.
I know this is likely not the type of response you were looking for but there's only so much we can do with our current resources...

@FabianLars FabianLars closed this as not planned Won't fix, can't repro, duplicate, stale Jan 15, 2024
@FabianLars FabianLars added the platform: Nix/NixOS Issues specific to NixOS or Nix tooling label Jan 15, 2024
@FabianLars
Copy link
Member

FabianLars commented Jan 15, 2024

Actually, let me reopen this with the Help Needed tag for better visibility :)

@FabianLars FabianLars reopened this Jan 15, 2024
@FabianLars FabianLars added the help wanted Help is requested to fix this issue label Jan 15, 2024
@thedavidmeister
Copy link
Author

@FabianLars this issue is about an approach, the nix community is large and there is a cargo-tauri pkg that i managed to update without much friction when i put a PR up

have you tried filing issues for these dependencies and other concerns upstream?

perhaps someone from the nix community would be willing to help

@khionu
Copy link

khionu commented Mar 5, 2024

The ideal solution for Nix/NixOS users would be for Tauri to have a flake. Said flake could provide a basic devshell that user flakes could inherit, and that would import the essential packages. It could also export tauri-cli.

Normally, I'd say the flake should be in this repo, but it might be good for it to be in its own repo because of the sheer size of this one. Would make it easier to delegate stewardship as well.

@ahkohd
Copy link
Member

ahkohd commented Mar 5, 2024

I recently started using NixOS (x86_64-unknown-linux-gnu). I have a custom flake that I use for Tauri projects. How can I be of help?

flake.nix

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

  };

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

        toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;

        packages = with pkgs; [
          cargo

          cargo-tauri

          toolchain

          rust-analyzer-unwrapped

          nodejs_18

          nodePackages.pnpm
        ];

        nativeBuildPackages = with pkgs; [
          pkg-config

          dbus

          openssl

          glib

          gtk3

          libsoup

          webkitgtk

          librsvg
        ];

        libraries = with pkgs; [
          webkitgtk

          gtk3

          cairo

          gdk-pixbuf

          glib

          dbus

          openssl

          librsvg
        ];

      in {

        devShells.default = pkgs.mkShell {
          buildInputs = packages;

          nativeBuildInputs = nativeBuildPackages;

          shellHook = with pkgs; ''
            export LD_LIBRARY_PATH="${
              lib.makeLibraryPath libraries
            }:$LD_LIBRARY_PATH"

            export OPENSSL_INCLUDE_DIR="${openssl.dev}/include/openssl"

            export OPENSSL_LIB_DIR="${openssl.out}/lib"

            export OPENSSL_ROOT_DIR="${openssl.out}"

            export RUST_SRC_PATH="${toolchain}/lib/rustlib/src/rust/library"
          '';
        };
      });
}

rust-toolchain.toml

[toolchain]
# You can use a stable channel. Tauri recommends using a Rust version of at least 1.64
channel = "nightly-2023-08-08"
components = ["rustfmt", "clippy", "rust-src"]
targets = ["x86_64-unknown-linux-gnu"]

@ahkohd
Copy link
Member

ahkohd commented Mar 5, 2024

Do we create tauri-apps/nix-flakeor a community maintained repo? Where can we maintain the flake I shared above and add support for darwin?

@khionu
Copy link

khionu commented Mar 5, 2024

I asked on the Discord, and the TL;DR is that it should probably be made and owned by a member of the community first. I'd be happy to own it.

@simonhyll
Copy link
Contributor

Yea the best path forward is to first make a repo community owned so that we see there's a real interest and that it's not just yet another feature request putting the burden of developing it on the WG.

The question of whether it then becomes part of the official tauri-apps organisation is really the question of who will maintain the project and whether the community is ok with relinquishing control of the project over to the WG. Once something becomes official it falls under the control of Tauri with all the checks and balances that comes with it, such as demands for proper reviewing of PR's, CI/CD, supporting the project, ensuring it's safe and stable, the works. The closer the project adheres to Tauri's demands the easier it'll be to transition into being an official project.

Note ofc that it's not impossible by any means to join the WG, if you own it @khionu and donate it to tauri-apps later, it could be seen as your contribution towards Tauri and qualify you for joining the WG if you so choose. Getting at least 2-3 WG members onboard with maintaining the project is a good idea. Getting the clear-to-go from the relevant domain lead is the final checkbox to tic I'd say (the development domain in this case, @lucasfernog, since the domain lead is the one that either creates or assigns a team to work on the project).

@ahkohd
Copy link
Member

ahkohd commented Mar 6, 2024

I have created a repo https://github.com/ahkohd/tauri-flake where we can all contribute to the flake.

I'm looking for a Darwin contributor and other reviewers. I can contribute to this, but I'll need to set up Nix first on my MBP; it will be faster if somebody already has this setup.

@ahkohd
Copy link
Member

ahkohd commented Mar 6, 2024

I asked on the Discord, and the TL;DR is that it should probably be made and owned by a member of the community first. I'd be happy to own it.

Oh I missed this, oops.

@Eveeifyeve
Copy link

Look I could take a look at making a flake for tauri templates my only problem I use devenv wather then the normal shell stuff. Maybe we could make a nix folder somewhere and copy and paste template like nix flake init --template github:tauri-apps/tauri#devenv or nix flake init --template github:tauri-apps/tauri for deafult template without devenv.

@Eveeifyeve
Copy link

Eveeifyeve commented Apr 12, 2024

But the problem is I can only test only on MacOS, So is anyone willing when my PR Comes out test it on NixOS?

@Eveeifyeve
Copy link

Eveeifyeve commented Apr 12, 2024

But the problem I've ran into is in issue #9433 where it requires Clang expression at start so I don't know how it will go but if someone like @FabianLars Tell me all the decencies required by Tauri on Both MacOS and Linux I can try to get some sort of flake template started

@Eveeifyeve
Copy link

I am going to get started on a repo called nix-tauri which includes stuff for tauri for Nix/NixOS

@Eveeifyeve
Copy link

@Eveeifyeve
Copy link

I will build more of it tmr and get a prototype working maybe a include a build thing in nix??? where it build a tauri application

@Eveeifyeve
Copy link

MacOS version of the flake is fully working #9433 based on https://github.com/eveeifyeve/nix-tauri using nix flake init github:eveeifyeve/nix-tauri

@Eveeifyeve
Copy link

Hey Good News I am working on a PR that will fix this issue.

@getchoo
Copy link

getchoo commented Oct 2, 2024

Basically what I expect is that when i use the cargo-tauri derivation from nixpkgs that i don't also have to copy and paste a bunch of additional prerequisites from the tauri docs in order to get things half working.

Right off the bat this is not possible. cargo-tauri simply packages the CLI. We have no good (and safe) way of what is basically injecting random libraries into rustc's linking stages

I also see that one of the dependencies, webkitgtk is marked as broken in nixpkgs on mac, but listed as a dependency on the tauri docs.

webkitgtk is not used on Mac, the system webview is. This is provided in nixpkgs by darwin.apple_sdk.frameworks.WebKit

say if I wanted to lift some standard tauri tasks into a package, the instructions don't cover that.

I'm not entirely sure what you mean here by "Tauri tasks"? If you're implying building Tauri through Nix, then this makes sense as that isn't the job of a development shell, but a proper package

We found that when tauri is built via nix there is a need to disable webkit compositing mode like export WEBKIT_DISABLE_COMPOSITING_MODE=1 in the shellHook

This is not a Nix issue, but one with newer versions of webkitgtk on NVIDIA GPUs. It should not be set in a shellHook or development shell universally, only on systems where you actually have these issues

At the moment it isn't clear where to put or discuss such a fix, would it just result in more documented boilerplate?

Yes

Tauri maintains the derivation in nixpkgs with the same dependencies that it outlines in the documentation, so then there are no manual steps for consumers.

As said above, this isn't really possible. Further, I believe it's very unreasonable to expect this from upstream -- especially as they have stated before no one in the WG uses it

I believe the current best solution would be to document a basic dev shell similar to other distributions in the official documentation (see possibly tauri-apps/tauri-docs#2413) and further applications of Nix + Tauri should be documented on wiki.nixos.org for example

To quickly solve some issues here though, cargo-tauri.hook has landed in the unstable branch of nixpkgs, making it much easier to package and run Tauri applications on NixOS. It is documented here and already used in many real world examples you can search through here

A basic dev shell for a Tauri project may also look something like this

pkgs.mkShell {
  packages = with pkgs; [
    nodejs
    # This will automatically use whatever package manager is declared by package.json if using corepack (which you totally should, it's great)
    # You can also replace this with any package manager of your choice, like `pnpm` or `bun`
    corepack
  ];
  
  nativeBuildInputs = 
    with pkgs; 
    [
      # Rust toolchain
      rustc
      cargo
      pkg-config
    ]
    # Brings in most of our GTK stuff for Linux
    ++ lib.optionals stdenv.hostPlatform.isLinux [ wrapGAppsHook4 ];
  
  buildInputs =
    with pkgs;
    [ openssl ]
    ++ lib.optionals stdenv.hostPlatform.isLinux [
      # Required for most applications
      glib-networking
      
      webkitgtk_4_1
    ]
    ++ lib.optionals stdenv.hostPlatform.isDarwin [
      darwin.apple_sdk.frameworks.WebKit
    ];
}

You may also have other tools required for your project like turbo. You can put those in packages alongside nodejs and your package manager of choice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Help is requested to fix this issue platform: Nix/NixOS Issues specific to NixOS or Nix tooling type: feature request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants