summary refs log tree commit diff
diff options
context:
space:
mode:
authorTim Cuthbertson <tim@gfxmonk.net>2023-02-28 21:28:41 +1100
committerArtturin <Artturin@artturin.com>2023-09-03 20:18:10 +0300
commit0bffcc3f3cef71004f130a62432cf8615eb7731b (patch)
tree6e2cc6255e114f35dd54727df42a7a603b8216de
parent074dea1e11c459588b4da209cc487d57e1257539 (diff)
downloadnixpkgs-0bffcc3f3cef71004f130a62432cf8615eb7731b.tar
nixpkgs-0bffcc3f3cef71004f130a62432cf8615eb7731b.tar.gz
nixpkgs-0bffcc3f3cef71004f130a62432cf8615eb7731b.tar.bz2
nixpkgs-0bffcc3f3cef71004f130a62432cf8615eb7731b.tar.lz
nixpkgs-0bffcc3f3cef71004f130a62432cf8615eb7731b.tar.xz
nixpkgs-0bffcc3f3cef71004f130a62432cf8615eb7731b.tar.zst
nixpkgs-0bffcc3f3cef71004f130a62432cf8615eb7731b.zip
setup-hooks/strip: add stripExclude
-rw-r--r--doc/stdenv/stdenv.chapter.md22
-rw-r--r--pkgs/build-support/setup-hooks/strip.sh10
2 files changed, 31 insertions, 1 deletions
diff --git a/doc/stdenv/stdenv.chapter.md b/doc/stdenv/stdenv.chapter.md
index 56843467fa4..c466e375b1a 100644
--- a/doc/stdenv/stdenv.chapter.md
+++ b/doc/stdenv/stdenv.chapter.md
@@ -937,6 +937,28 @@ Like `stripDebugList`, but only applies to packages’ target platform. By defau
 
 Flags passed to the `strip` command applied to the files in the directories listed in `stripDebugList`. Defaults to `-S` (i.e. `--strip-debug`).
 
+##### `stripExclude` {#var-stdenv-stripExclude}
+
+A list of filenames or path patterns to avoid stripping. A file is excluded if its name _or_ path (from the derivation root) matches.
+
+This example prevents all `*.rlib` files from being stripped:
+
+```nix
+stdenv.mkDerivation {
+  # ...
+  stripExclude = [ "*.rlib" ]
+}
+```
+
+This example prevents files within certain paths from being stripped:
+
+```nix
+stdenv.mkDerivation {
+  # ...
+  stripExclude = [ "lib/modules/*/build/* ]
+}
+```
+
 ##### `dontPatchELF` {#var-stdenv-dontPatchELF}
 
 If set, the `patchelf` command is not used to remove unnecessary `RPATH` entries. Only applies to Linux.
diff --git a/pkgs/build-support/setup-hooks/strip.sh b/pkgs/build-support/setup-hooks/strip.sh
index d2422bb8423..ce41e6ea056 100644
--- a/pkgs/build-support/setup-hooks/strip.sh
+++ b/pkgs/build-support/setup-hooks/strip.sh
@@ -49,11 +49,19 @@ stripDirs() {
     local ranlibCmd="$2"
     local paths="$3"
     local stripFlags="$4"
+    local excludeFlags=()
     local pathsNew=
 
     [ -z "$cmd" ] && echo "stripDirs: Strip command is empty" 1>&2 && exit 1
     [ -z "$ranlibCmd" ] && echo "stripDirs: Ranlib command is empty" 1>&2 && exit 1
 
+    local pattern
+    if [ -n "${stripExclude:-}" ]; then
+        for pattern in "${stripExclude[@]}"; do
+            excludeFlags+=(-a '!' '(' -name "$pattern" -o -wholename "$prefix/$pattern" ')' )
+        done
+    fi
+
     local p
     for p in ${paths}; do
         if [ -e "$prefix/$p" ]; then
@@ -67,7 +75,7 @@ stripDirs() {
         local striperr
         striperr="$(mktemp --tmpdir="$TMPDIR" 'striperr.XXXXXX')"
         # Do not strip lib/debug. This is a directory used by setup-hooks/separate-debug-info.sh.
-        find $paths -type f -a '!' -path "$prefix/lib/debug/*" -print0 |
+        find $paths -type f "${excludeFlags[@]}" -a '!' -path "$prefix/lib/debug/*" -print0 |
             # Make sure we process files under symlinks only once. Otherwise
             # 'strip` can corrupt files when writes to them in parallel:
             #   https://github.com/NixOS/nixpkgs/issues/246147#issuecomment-1657072039