Platform-dependent patches

I’m trying to write a derivation for SimSET, whose installation procedure requires some of the distributed files to be patched (edited by hand, according to the guide), depending on the architecture on which the software is to be compiled.

What would be a good way of expressing these architecture-dependent patches?

You can inspect stdenv.hostPlatform to figure out which flags to add (e.g. stdenv.hostPlatform.isLinux, stdenv.hostPlatform.is64Bit, stdenv.hostPlatform.system etc.).

Then you can set derivation attributes based on this information:

makeFlags =
     lib.optionals stdenv.hostPlatform.isLinux ["PLATFORM=Linux"]
  ++ lib.optionals stdenv.hostPlatform.is64Bit ["IS64=1"];

(i’m making these flags up, this is just to illustrate the point).

For maximum flexibility you can run arbitrary shell commands in hooks like postPatch.

Godspeed.

2 Likes