···937938Flags passed to the `strip` command applied to the files in the directories listed in `stripDebugList`. Defaults to `-S` (i.e. `--strip-debug`).
9390000000000000000000000940##### `dontPatchELF` {#var-stdenv-dontPatchELF}
941942If set, the `patchelf` command is not used to remove unnecessary `RPATH` entries. Only applies to Linux.
···937938Flags passed to the `strip` command applied to the files in the directories listed in `stripDebugList`. Defaults to `-S` (i.e. `--strip-debug`).
939940+##### `stripExclude` {#var-stdenv-stripExclude}
941+942+A list of filenames or path patterns to avoid stripping. A file is excluded if its name _or_ path (from the derivation root) matches.
943+944+This example prevents all `*.rlib` files from being stripped:
945+946+```nix
947+stdenv.mkDerivation {
948+ # ...
949+ stripExclude = [ "*.rlib" ]
950+}
951+```
952+953+This example prevents files within certain paths from being stripped:
954+955+```nix
956+stdenv.mkDerivation {
957+ # ...
958+ stripExclude = [ "lib/modules/*/build/* ]
959+}
960+```
961+962##### `dontPatchELF` {#var-stdenv-dontPatchELF}
963964If set, the `patchelf` command is not used to remove unnecessary `RPATH` entries. Only applies to Linux.
+9-1
pkgs/build-support/setup-hooks/strip.sh
···49 local ranlibCmd="$2"
50 local paths="$3"
51 local stripFlags="$4"
052 local pathsNew=
5354 [ -z "$cmd" ] && echo "stripDirs: Strip command is empty" 1>&2 && exit 1
55 [ -z "$ranlibCmd" ] && echo "stripDirs: Ranlib command is empty" 1>&2 && exit 1
00000005657 local p
58 for p in ${paths}; do
···67 local striperr
68 striperr="$(mktemp --tmpdir="$TMPDIR" 'striperr.XXXXXX')"
69 # Do not strip lib/debug. This is a directory used by setup-hooks/separate-debug-info.sh.
70- find $paths -type f -a '!' -path "$prefix/lib/debug/*" -print0 |
71 # Make sure we process files under symlinks only once. Otherwise
72 # 'strip` can corrupt files when writes to them in parallel:
73 # https://github.com/NixOS/nixpkgs/issues/246147#issuecomment-1657072039
···49 local ranlibCmd="$2"
50 local paths="$3"
51 local stripFlags="$4"
52+ local excludeFlags=()
53 local pathsNew=
5455 [ -z "$cmd" ] && echo "stripDirs: Strip command is empty" 1>&2 && exit 1
56 [ -z "$ranlibCmd" ] && echo "stripDirs: Ranlib command is empty" 1>&2 && exit 1
57+58+ local pattern
59+ if [ -n "${stripExclude:-}" ]; then
60+ for pattern in "${stripExclude[@]}"; do
61+ excludeFlags+=(-a '!' '(' -name "$pattern" -o -wholename "$prefix/$pattern" ')' )
62+ done
63+ fi
6465 local p
66 for p in ${paths}; do
···75 local striperr
76 striperr="$(mktemp --tmpdir="$TMPDIR" 'striperr.XXXXXX')"
77 # Do not strip lib/debug. This is a directory used by setup-hooks/separate-debug-info.sh.
78+ find $paths -type f "${excludeFlags[@]}" -a '!' -path "$prefix/lib/debug/*" -print0 |
79 # Make sure we process files under symlinks only once. Otherwise
80 # 'strip` can corrupt files when writes to them in parallel:
81 # https://github.com/NixOS/nixpkgs/issues/246147#issuecomment-1657072039