Skip to content

Commit

Permalink
importCargoLock: add support for patches
Browse files Browse the repository at this point in the history
Motivation https://www.github.com/nix-community/nixpkgs-wayland/issues/461#issuecomment-2294113236

This fixes the lockfile mismatch which happens when `cargoPatches` is used with
`cargoLock` because those patches are added to `patches`.
  • Loading branch information
Artturin committed Aug 26, 2024
1 parent a8e2b00 commit 6ad1c89
Showing 1 changed file with 30 additions and 5 deletions.
35 changes: 30 additions & 5 deletions pkgs/build-support/rust/import-cargo-lock.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ fetchgit, fetchurl, lib, writers, python3Packages, runCommand, cargo, jq }:
{ fetchgit, fetchurl, lib, writers, python3Packages, runCommand, applyPatches, writeTextFile, cargo, jq }:

{
# Cargo lock file
Expand All @@ -7,6 +7,9 @@
# Cargo lock file contents as string
, lockFileContents ? null

# Applying patches requires IFD thus cannot be used in nixpkgs.
, patches ? null

# Allow `builtins.fetchGit` to be used to not require hashes for git dependencies
, allowBuiltinFetchGit ? false

Expand Down Expand Up @@ -41,12 +44,34 @@ let
sha = builtins.elemAt parts 4;
} // lib.optionalAttrs (type != null) { inherit type value; };

# shadows args.lockFileContents
lockFileContents =
if lockFile != null
then builtins.readFile lockFile
lockFileContents' =
if args.lockFile != null
then builtins.readFile args.lockFile
else args.lockFileContents;

lockFile' = (
applyPatches {
name = "cargo-lockFileContents-patched";
inherit patches;
unpackPhase = "cp $src ./Cargo.lock && chmod +w Cargo.lock";
installPhase = "cp ./Cargo.lock $out";
src =
if args.lockFile != null then
args.lockFile
else
writeTextFile {
name = "cargo-lockFileContents";
text = lockFileContents';
};
}
);

# shadows args.lockFile
lockFile = if patches != null then lockFile' else args.lockFile;
# shadows args.lockFileContents
# If `patches` is specified then `readFIle lockFile` will use IFD
lockFileContents = if patches != null then builtins.readFile lockFile else lockFileContents';

parsedLockFile = builtins.fromTOML lockFileContents;

packages = parsedLockFile.package;
Expand Down

0 comments on commit 6ad1c89

Please sign in to comment.