summary refs log tree commit diff
path: root/pkgs/build-support/trivial-builders.nix
diff options
context:
space:
mode:
authorVladimír Čunát <v@cunat.cz>2019-09-04 11:00:56 +0200
committerVladimír Čunát <v@cunat.cz>2019-09-04 11:00:56 +0200
commit4aad2947f8d680f18e5b01e115cf8cff22186998 (patch)
treea7a3d020efc6ec7be822bc06e08eca3ac311c9e2 /pkgs/build-support/trivial-builders.nix
parent2c5835b09a1d4966756212902d36b1b8ab242da6 (diff)
parent1d8a3973f46a2d1360f855eaa0f3a19859771793 (diff)
downloadnixpkgs-4aad2947f8d680f18e5b01e115cf8cff22186998.tar
nixpkgs-4aad2947f8d680f18e5b01e115cf8cff22186998.tar.gz
nixpkgs-4aad2947f8d680f18e5b01e115cf8cff22186998.tar.bz2
nixpkgs-4aad2947f8d680f18e5b01e115cf8cff22186998.tar.lz
nixpkgs-4aad2947f8d680f18e5b01e115cf8cff22186998.tar.xz
nixpkgs-4aad2947f8d680f18e5b01e115cf8cff22186998.tar.zst
nixpkgs-4aad2947f8d680f18e5b01e115cf8cff22186998.zip
Merge branch 'master' into staging-next
Diffstat (limited to 'pkgs/build-support/trivial-builders.nix')
-rw-r--r--pkgs/build-support/trivial-builders.nix33
1 files changed, 33 insertions, 0 deletions
diff --git a/pkgs/build-support/trivial-builders.nix b/pkgs/build-support/trivial-builders.nix
index 0bfe14a8539..55df09121b4 100644
--- a/pkgs/build-support/trivial-builders.nix
+++ b/pkgs/build-support/trivial-builders.nix
@@ -381,4 +381,37 @@ rec {
   # Copy a list of paths to the Nix store.
   copyPathsToStore = builtins.map copyPathToStore;
 
+  /* Applies a list of patches to a source directory.
+   *
+   * Examples:
+   *
+   * # Patching nixpkgs:
+   * applyPatches {
+   *   src = pkgs.path;
+   *   patches = [
+   *     (pkgs.fetchpatch {
+   *       url = "https://github.com/NixOS/nixpkgs/commit/1f770d20550a413e508e081ddc08464e9d08ba3d.patch";
+   *       sha256 = "1nlzx171y3r3jbk0qhvnl711kmdk57jlq4na8f8bs8wz2pbffymr";
+   *     })
+   *   ];
+   * }
+   */
+  applyPatches =
+    { src
+    , name ? (if builtins.typeOf src == "path"
+              then builtins.baseNameOf src
+              else
+                if builtins.isAttrs src && builtins.hasAttr "name" src
+                then src.name
+                else throw "applyPatches: please supply a `name` argument because a default name can only be computed when the `src` is a path or is an attribute set with a `name` attribute."
+             ) + "-patched"
+    , patches   ? []
+    , postPatch ? ""
+    }: stdenvNoCC.mkDerivation {
+      inherit name src patches postPatch;
+      preferLocalBuild = true;
+      allowSubstitutes = false;
+      phases = "unpackPhase patchPhase installPhase";
+      installPhase = "cp -R ./ $out";
+    };
 }