Can't build rust package with cargo.lock version 4

I was trying to package tiny-irc, a rust project, with buildRustPackage, however the compiler’s version is 1.77, and cargo.lock version 4 was added on 1.78 (march 2024).

I’ve tried to add a patch to downgrade the version but this error came:

error: the lock file /build/source/Cargo.lock needs to be updated but --frozen was passed to prevent this
If you want to try to generate the lock file without accessing the network, remove the --frozen flag and use --offline instead.
error: builder for ‘/nix/store/ywlhiryzngcjmamh919zj5vj54ph8kmy-tinyirc-0.13.0.drv’ failed with exit code 101

I’ve tried to change buildPhase to this:

  buildPhase = ''
    runHook preBuild
    cargo build
    runHook postBuild
  '';

but then this error occurs:

Executing cargoInstallPostBuildHook
cp: missing destination file operand after ‘target/x86_64-unknown-linux-gnu/release-tmp/’
Try ‘cp --help’ for more information.
error: builder for ‘/nix/store/0f3354dr7xq4835n9apsm0gxc5ma8xgc-tinyirc-0.13.0.drv’ failed with exit code 1

the derivation program:

{
  lib,
  rustPlatform,
  fetchFromGitHub,
}:
rustPlatform.buildRustPackage rec {
  pname = "tinyirc";
  version = "0.13.0";
  owner = "osa1";
  repo = "tiny";

  src = fetchFromGitHub {
    inherit owner repo;
    rev = "v${version}";
    #sha256 = "lbG07IlBhvY1vFP0aU6mInbiVC60Y9RRAj15tCPlUVM=";
    sha256 = "phjEae2SS3zkSpuhhE4iscUM8ij8DT47YLIMATMG/+Q=";
  };

  cargoPatches = [
    ./downgrade-Cargo.lock-version.patch # Cargo.lock version 4 -> 3
  ];

  #cargoHash = "sha256-YDDkYBsg/ORFLgvYf6A/xzgFPAaL5PfzCutLop8v+R8=";
  cargoHash = "sha256-AVS1vFMi0rmsT/QeYmGLT6tNb+RMq+Fa7B6o7t4RlzE=";

  meta = with lib; {
    description = "A terminal IRC client built in rust";
    homepage = "https://github.com/${owner}/${repo}";
    license = with licenses; [ mit ];
    maintainers = with maintainers; [ ];
  };
}

nix build log
nix build + vendoring log

Last and least important: if I don’t try to run nix-build with sudo, this error occurs.

I’m just saying this here in case it’s important to the cargo problem, that issue should probably be solved there

Thanks in advance : )

My NixOS version 24.11.717484.26245db0cb55 (Vicuna)

You should run cargo update --offline (or something similar), and then use the updated lockfile, instead of only downgrading the version.

There is no need to override the build phase.

1 Like

I’ve realised my mistake. I was using and old version of nixpkgs with the outdated compiler for the derivation. I’ve updated to 24.11 and it now works.

However, on which hook should I execute the command you suggested?
I’ve tried prePath and postPatch, but they only apply if there’s a patch. And I don’t think preBuild ran aswell.

They’re saying to run it manually and vendor the lockfile or use that diff, I believe. Not during the build (since builds are network-sandboxed unless they’re a FOD).

2 Likes

That makes sense, thank you very much :slight_smile: