Applying a patch in a git submodule

I am trying to write a derivation, which fetches a repository from GitHub, with submodules, and which has git patches to apply in some of its git submodules.

I tried the following so far:

postUnpack = ''
  cd $sourceRoot/foo_submodule && git apply foo.patch
'';

and

  prePatch = ''
    cd $sourceRoot/foo_submodule
  '';
  patches = ["foo.patch"];

Is there a recommended approach to do this?

As I am developing using nix-shell I had to change references to $src to $sourceRoot in order to avoid permission denied errors as files under the nix/store appear to be read-only or protected from writes.

A related concern I have, is that the unpackPhase removes the .git directory and I wonder how this affects the action of applying a git patch, with git apply ....

1 Like

Sorry to revive a dead thread, but I haven’t seen anything else that answers this question. Did you ever figure out if this would be the best way to apply patches to submodules or is this the preferred approach?