Rust packaging problems, no such file cargo.lock

Hi!

I’m trying to build a tauri package. It works if I build it with cargoLock but doesn’t when I use cargoHash etc. It says:

       last 25 log lines:
       > unpacking source archive /nix/store/paxbzjfhqx0dr2q22zx81p123h9zq2fk-source
       > source root is source
       > Running phase: patchPhase
       > applying patch /nix/store/47n7z79rrbsrsachx63vqqacq46a7qmd-0001-Cargo.patch
       > patching file src-tauri/Cargo.lock
       > patching file src-tauri/Cargo.toml
       > Running phase: updateAutotoolsGnuConfigScriptsPhase
       > Running phase: configurePhase
       > no configure script, doing nothing
       > Running phase: buildPhase
       > Traceback (most recent call last):
       >   File "/nix/store/hpg5ar98kl2acrm4bjci6879mhqbaqll-fetch-cargo-vendor-util/bin/fetch-cargo-vendor-util", line 314, in <module>
       >     main()
       >   File "/nix/store/hpg5ar98kl2acrm4bjci6879mhqbaqll-fetch-cargo-vendor-util/bin/fetch-cargo-vendor-util", line 310, in main
       >     subcommand_func()
       >   File "/nix/store/hpg5ar98kl2acrm4bjci6879mhqbaqll-fetch-cargo-vendor-util/bin/fetch-cargo-vendor-util", line 301, in <lambda>
       >     "create-vendor-staging": lambda: create_vendor_staging(lockfile_path=Path(sys.argv[2]), out_dir=Path(sys.argv[3])),
       >                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       >   File "/nix/store/hpg5ar98kl2acrm4bjci6879mhqbaqll-fetch-cargo-vendor-util/bin/fetch-cargo-vendor-util", line 123, in create_vendor_staging
       >     cargo_lock_toml = load_toml(lockfile_path)
       >                       ^^^^^^^^^^^^^^^^^^^^^^^^
       >   File "/nix/store/hpg5ar98kl2acrm4bjci6879mhqbaqll-fetch-cargo-vendor-util/bin/fetch-cargo-vendor-util", line 22, in load_toml
       >     with open(path, "rb") as f:
       >          ^^^^^^^^^^^^^^^^
       > FileNotFoundError: [Errno 2] No such file or directory: 'Cargo.lock'

Link to the code: GitHub - Uncorrupt3318/nixpkgs-blink at remove-cargolock

Sorry for the brief post, I’m a bit in a rush. I will answer any questions you might have later :slight_smile:

I’m still new to nix, so if you could explain it from ground up that would be cool, but not necessary, I can use Google haha (though I couldn’t find an answer to this one) Thanks!

I don’t really see how you got it building as-is, the expression you posted doesn’t build on my system.

diff --git a/blink.nix b/blink.nix
index d09d7d6..c609e7b 100644
--- a/blink.nix
+++ b/blink.nix
@@ -36,13 +36,6 @@ rustPlatform.buildRustPackage rec {
     ./0001-Cargo.patch
   ];
 
-  cargoLock = {
-    lockFileContents = builtins.readFile ./Cargo.lock;
-    outputHashes = {
-      "tauri-plugin-localhost-2.0.1" = "sha256-75lRQHotyRGeorPifVUV71swbkPsd5o/UmJDBvDnDJE=";
-    };
-  };
-
   nativeBuildInputs = [
     cargo-tauri.hook
     nodejs
@@ -65,18 +58,14 @@ rustPlatform.buildRustPackage rec {
     glib-networking
   ];
 
-  buildPhase = ''
-    pnpm install --offline
-    pnpm run tauri build --no-bundle
-  '';
-
+  useFetchCargoVendor = true;
+  cargoHash = "sha256-HERcmfc+C3kJnlEKcbY0vc8GqEYN+1fvOs2u0MMIrHI=";
   cargoRoot = "src-tauri";
   buildAndTestSubdir = cargoRoot;
 
   installPhase = ''
     runHook preInstall
-    mkdir -p $out/bin
-    cp src-tauri/target/release/blink $out/bin/
+    install -Dm755 src-tauri/target/release/blink -t $out/bin
     runHook postInstall
   '';
 }

Applying the following diff gets closer, but still appears to fail on the glib crate for some reason :thinking: adding rustPlatform.bindgenHook didn’t appear to help either.

Also you will want to build this against master or at least nixos-unstable, since master is where PRs will go to first regardless (and nixos-unstable trails it by a couple of days).

Well so much for reproducibility lol. The main branch did build for me a day ago, while the remove-cargolock branch (which is basically the diff you sent me) gives me the above error.

I feel like I’m missing something fundamental, something in my environment? You’re using nix-build -A blink right? I’m going to question everything haha

Can’t really claim reproducibility if your inputs aren’t pinned. That’s why lockfiles exist. npins, nvfetcher, and flakes all allow for pinning the exact revision more ergonomically, or you could specify the exact revision in your default.nix.

BTW I also removed the buildPhase since it’s redundant and is missing the pre/post-phase hooks.

You’re right. That was a stupid thing to say.

With all that you said, I went back to basics and played around. Instead, I cloned the nixpkgs repo (solves the reproducibility problem) and wrote the nix file from the beginning. With this setup, there was no need for patches and other problem are also gone.

{
  cargo-tauri,
  fetchFromGitHub,
  glib,
  gst_all_1,
  gtk3,
  lib,
  libsoup_3,
  nodejs,
  pkg-config,
  pnpm_9,
  rustPlatform,
  webkitgtk_4_1,
  wrapGAppsHook4
}:

rustPlatform.buildRustPackage rec {
  pname = "blink";
  version = "v1.0.0-alpha03";

  src = fetchFromGitHub {
    owner = "prayag17";
    repo = pname;
    rev = version;
    sha256 = "0m5ckvs7mscallr6fdh0bikklavzibn5f4ir46j1nr50s53qqshb";
  };

  pnpmDeps = pnpm_9.fetchDeps {
    inherit pname version src;
    hash = "sha256-PM0e/Ju/7/gdqe94Dsi324sADaxNHuzkcfFi0u/fY9I=";
  };

  useFetchCargoVendor = true;
  cargoHash = "sha256-bDhTsAaO/v8HiQBXuala5ZSjMIdrVr0rAE++/x4pM7Y=";

  nativeBuildInputs = [
    cargo-tauri.hook
    nodejs
    pkg-config
    pnpm_9.configHook
    wrapGAppsHook4
  ];

  buildInputs = [
    glib
    gst_all_1.gstreamer
    gst_all_1.gst-plugins-base
    gst_all_1.gst-plugins-good
    gst_all_1.gst-plugins-bad
    gst_all_1.gst-plugins-ugly
    gtk3
    libsoup_3
    webkitgtk_4_1
  ];

  tauriBuildFlags = [ "--no-bundle" ];

  cargoRoot = "src-tauri";
  buildAndTestSubdir = cargoRoot;

  installPhase = ''
    runHook preInstall
    mkdir -p $out/bin
    install -Dm755 target/x86_64-unknown-linux-gnu/release/blink $out/bin/
    runHook postInstall
  '';
}
  • The installPhase probably needs a variable for the system type.
  • tauriBuildFlags is there because it failed with Error failed to bundle project: - Unable to find a bundled project for the updater otherwise. About that, are binaries enough or does it require a bundle (like deb) for nixpkgs?

It still has some issues (no HE-AAC codec support, I’m guessing)(mesa mismatch between my system and the unstable branch), but those are mine to figure out

1 Like

You’re looking for stdenv.hostPlatform.rust.cargoShortTarget here.

(You can also drop the mkdir call since install -D takes care of it, but ensure to keep the trailing slash after $out/bin/ or use the -t flag as in -t $out/bin.)

Also, if you did manage to get bundling working, you could even drop the installPhase entirely, since tauriInstallHook expects the app to be bundled.

Also it looks like other tauri packages have run into this issue before, and this is how they solved it:

It would be nice to have a centralised hook for this use case, though this should suffice for now.

All makes sense. Thanks!

General questions:

  • How do you know what hooks expect or do? Experience or just browsing the source code?
  • I’m guessing you just copy pasted the error message into GitHub to find the issue? Would the way of searching Nixpkgs GitHub → Nix Discourse → Google be right? As in if I can’t find it in the repo, I search here and then Google?

Manual and reading the code. In this case the manual covers it.

Yes and yes.

By the way, if you’re interested, cargo-tauri.hook: disable bundle updater; remove redundant patches by eclairevoyant · Pull Request #389107 · NixOS/nixpkgs · GitHub contains a fix to disable the updater by default; if you’ve got a chance, feel free to review it and provide feedback or approve. (Anyone with a gh account is free to review/approve.)