diff --git a/pkgs/build-support/java/canonicalize-jar.nix b/pkgs/build-support/java/canonicalize-jar.nix deleted file mode 100644 index 1edd9a6e0d20..000000000000 --- a/pkgs/build-support/java/canonicalize-jar.nix +++ /dev/null @@ -1,9 +0,0 @@ -{ substituteAll, unzip, zip }: - -substituteAll { - name = "canonicalize-jar"; - src = ./canonicalize-jar.sh; - - unzip = "${unzip}/bin/unzip"; - zip = "${zip}/bin/zip"; -} diff --git a/pkgs/build-support/java/canonicalize-jar.sh b/pkgs/build-support/java/canonicalize-jar.sh deleted file mode 100644 index af010bcd2b26..000000000000 --- a/pkgs/build-support/java/canonicalize-jar.sh +++ /dev/null @@ -1,29 +0,0 @@ -# Canonicalize the manifest & repack with deterministic timestamps. -canonicalizeJar() { - local input='' outer='' - input="$(realpath -sm -- "$1")" - outer="$(pwd)" - # -qq: even quieter - @unzip@ -qq "$input" -d "$input-tmp" - canonicalizeJarManifest "$input-tmp/META-INF/MANIFEST.MF" - # Sets all timestamps to Jan 1 1980, the earliest mtime zips support. - find -- "$input-tmp" -exec touch -t 198001010000.00 {} + - rm "$input" - pushd "$input-tmp" 2>/dev/null - # -q|--quiet, -r|--recurse-paths - # -o|--latest-time: canonicalizes overall archive mtime - # -X|--no-extra: don't store platform-specific extra file attribute fields - @zip@ -qroX "$outer/tmp-out.jar" . 2> /dev/null - popd 2>/dev/null - rm -rf "$input-tmp" - mv "$outer/tmp-out.jar" "$input" -} - -# See also the Java specification's JAR requirements: -# https://docs.oracle.com/javase/8/docs/technotes/guides/jar/jar.html#Notes_on_Manifest_and_Signature_Files -canonicalizeJarManifest() { - local input='' - input="$(realpath -sm -- "$1")" - (head -n 1 "$input" && tail -n +2 "$input" | sort | grep -v '^\s*$') > "$input-tmp" - mv "$input-tmp" "$input" -} diff --git a/pkgs/build-support/setup-hooks/canonicalize-jars.sh b/pkgs/build-support/setup-hooks/canonicalize-jars.sh deleted file mode 100644 index 5137bfc94b01..000000000000 --- a/pkgs/build-support/setup-hooks/canonicalize-jars.sh +++ /dev/null @@ -1,16 +0,0 @@ -# This setup hook causes the fixup phase to repack all JAR files in a -# canonical & deterministic fashion, e.g. resetting mtimes (like with normal -# store files) and avoiding impure metadata. - -fixupOutputHooks+=('if [ -z "$dontCanonicalizeJars" -a -e "$prefix" ]; then canonicalizeJarsIn "$prefix"; fi') - -canonicalizeJarsIn() { - local dir="$1" - echo "canonicalizing jars in $dir" - dir="$(realpath -sm -- "$dir")" - while IFS= read -rd '' f; do - canonicalizeJar "$f" - done < <(find -- "$dir" -type f -name '*.jar' -print0) -} - -source @canonicalize_jar@ diff --git a/pkgs/build-support/setup-hooks/strip-java-archives.sh b/pkgs/build-support/setup-hooks/strip-java-archives.sh new file mode 100644 index 000000000000..22322468f76d --- /dev/null +++ b/pkgs/build-support/setup-hooks/strip-java-archives.sh @@ -0,0 +1,16 @@ +# This setup hook makes the fixup phase to repack all java archives in a +# deterministic fashion. The most important change being done is the resetting +# of the modification times of the archive entries + +fixupOutputHooks+=('stripJavaArchivesIn $prefix') + +stripJavaArchivesIn() { + local dir="$1" + echo "stripping java archives in $dir" + find $dir -type f -regextype posix-egrep -regex ".*\.(jar|war|hpi|apk)$" -print0 | + while IFS= read -rd '' f; do + echo "stripping java archive $f" + strip-nondeterminism --type jar "$f" + done +} + diff --git a/pkgs/top-level/aliases.nix b/pkgs/top-level/aliases.nix index 28ee46900ded..8b1d1802c2c7 100644 --- a/pkgs/top-level/aliases.nix +++ b/pkgs/top-level/aliases.nix @@ -146,6 +146,7 @@ mapAliases ({ callPackage_i686 = pkgsi686Linux.callPackage; cadence = throw "cadence has been removed from nixpkgs, as it was archived upstream"; # Added 2023-10-28 cask = emacs.pkgs.cask; # Added 2022-11-12 + canonicalize-jars-hook = stripJavaArchivesHook; # Added 2024-03-17 cargo-embed = throw "cargo-embed is now part of the probe-rs package"; # Added 2023-07-03 cargo-espflash = espflash; cargo-flash = throw "cargo-flash is now part of the probe-rs package"; # Added 2023-07-03 diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 5e03fbae6b72..2b4a8529c43c 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -212,11 +212,10 @@ with pkgs; inherit (darwin.apple_sdk.frameworks) Security; }; - canonicalize-jar = callPackage ../build-support/java/canonicalize-jar.nix { }; - canonicalize-jars-hook = makeSetupHook { - name = "canonicalize-jars-hook"; - substitutions = { canonicalize_jar = canonicalize-jar; }; - } ../build-support/setup-hooks/canonicalize-jars.sh; + stripJavaArchivesHook = makeSetupHook { + name = "strip-java-archives-hook"; + propagatedBuildInputs = [ strip-nondeterminism ]; + } ../build-support/setup-hooks/strip-java-archives.sh; ensureNewerSourcesHook = { year }: makeSetupHook { name = "ensure-newer-sources-hook";