Skip to content

Commit

Permalink
stdenv: Allow changing the patch command
Browse files Browse the repository at this point in the history
The `patch` utility is not fully compatible with the diffs generated by
`git`, one missing feature is the renaming of files. As GitHub exports diffs
of a PR with renames, it means that those patches are not guaranteed to work
with `patch`.
  • Loading branch information
Tom-Hubrecht committed Aug 26, 2023
1 parent a16ae0e commit 802dff2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
6 changes: 5 additions & 1 deletion doc/stdenv/stdenv.chapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -667,13 +667,17 @@ The patch phase applies the list of patches defined in the `patches` variable.

Set to true to skip the patch phase.

##### `patchCommand` {#var-stdenv-patchCommand}

The patch command to use. If not set, the `patch` utility is used.

##### `patches` {#var-stdenv-patches}

The list of patches. They must be in the format accepted by the `patch` command, and may optionally be compressed using `gzip` (`.gz`), `bzip2` (`.bz2`) or `xz` (`.xz`).

##### `patchFlags` {#var-stdenv-patchFlags}

Flags to be passed to `patch`. If not set, the argument `-p1` is used, which causes the leading directory component to be stripped from the file names in each patch.
Flags to be passed to `$patchCommand`. If not set, the argument `-p1` is used, which causes the leading directory component to be stripped from the file names in each patch.

##### `prePatch` {#var-stdenv-prePatch}

Expand Down
5 changes: 3 additions & 2 deletions pkgs/build-support/trivial-builders/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -905,17 +905,18 @@ rec {
) + "-patched"
, patches ? []
, postPatch ? ""
, patchCommand ? "patch"
, ...
}@args: stdenvNoCC.mkDerivation {
inherit name src patches postPatch;
inherit name src patches patchCommand postPatch;
preferLocalBuild = true;
allowSubstitutes = false;
phases = "unpackPhase patchPhase installPhase";
installPhase = "cp -R ./ $out";
}
# Carry `meta` information from the underlying `src` if present.
// (optionalAttrs (src?meta) { inherit (src) meta; })
// (removeAttrs args [ "src" "name" "patches" "postPatch" ]);
// (removeAttrs args [ "src" "name" "patches" "patchCommand" "postPatch" ]);

/* An immutable file in the store with a length of 0 bytes. */
emptyFile = runCommand "empty-file" {
Expand Down
2 changes: 1 addition & 1 deletion pkgs/stdenv/generic/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1198,7 +1198,7 @@ patchPhase() {
fi
# "2>&1" is a hack to make patch fail if the decompressor fails (nonexistent patch, etc.)
# shellcheck disable=SC2086
$uncompress < "$i" 2>&1 | patch "${flagsArray[@]}"
$uncompress < "$i" 2>&1 | ${patchCommand:-patch} "${flagsArray[@]}"
done

runHook postPatch
Expand Down

0 comments on commit 802dff2

Please sign in to comment.