Files
nixpkgs/pkgs/build-support/setup-hooks/compress-man-pages.sh
Arnout Engelen 4108382f36 compress-man-pages: don't leak build timestamp into archive
without `-n`, gzip leaks the file timestamp into the compressed file,
which is likely to leak the build timestamp into the output.

This fixes #434930, a regression introduced in c5252e1 / #406922
2025-08-20 17:03:51 +02:00

28 lines
920 B
Bash

fixupOutputHooks+=('if [ -z "${dontGzipMan-}" ]; then compressManPages "$prefix"; fi')
compressManPages() {
local dir="$1"
if [ -L "$dir"/share ] || [ -L "$dir"/share/man ] || [ ! -d "$dir/share/man" ]
then return
fi
echo "gzipping man pages under $dir/share/man/"
# Compress all uncompressed manpages. Don't follow symlinks, etc.
# gzip -f is needed to not error out on hard links.
find "$dir"/share/man/ -type f -a '!' -regex '.*\.\(bz2\|gz\|xz\)$' -print0 \
| xargs -0 -n1 -P "$NIX_BUILD_CORES" gzip -n -f
# Point symlinks to compressed manpages.
find "$dir"/share/man/ -type l -a '!' -regex '.*\.\(bz2\|gz\|xz\)$' -print0 \
| sort -z \
| while IFS= read -r -d $'\0' f
do
local target
target="$(readlink -f "$f")"
if [ -f "$target".gz ]; then
ln -sf "$target".gz "$f".gz && rm "$f"
fi
done
}