Skip to content

Commit

Permalink
texlive: make packages fixed-output derivations
Browse files Browse the repository at this point in the history
This reverts a part of the changes made in #40826.
Fixed-output derivations save time and space on rebuilds.

(cherry picked from commit 738bae4)
  • Loading branch information
xeji committed Sep 4, 2018
1 parent d2c300b commit 292413f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
35 changes: 30 additions & 5 deletions pkgs/tools/typesetting/tex/texlive/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
{ stdenv, lib, fetchurl, runCommand, writeText, buildEnv
, callPackage, ghostscriptX, harfbuzz, poppler_min
, makeWrapper, python, ruby, perl
, useFixedHashes ? true
, recurseIntoAttrs
}:
let
Expand All @@ -41,6 +42,10 @@ let
};
};

# map: name -> fixed-output hash
# sha1 in base32 was chosen as a compromise between security and length
fixedHashes = lib.optionalAttrs useFixedHashes (import ./fixedHashes.nix);

# function for creating a working environment from a set of TL packages
combine = import ./combine.nix {
inherit bin combinePkgs buildEnv fastUnique lib makeWrapper writeText
Expand Down Expand Up @@ -116,6 +121,7 @@ let
# the basename used by upstream (without ".tar.xz" suffix)
urlName = pname + lib.optionalString (tlType != "run") ".${tlType}";
tlName = urlName + "-${version}";
fixedHash = fixedHashes.${tlName} or null; # be graceful about missing hashes

urls = args.urls or (if args ? url then [ args.url ] else
map (up: "${up}/${urlName}.tar.xz") urlPrefixes
Expand Down Expand Up @@ -155,11 +161,30 @@ let
-C "$out" --anchored --exclude=tlpkg --keep-old-files
'' + postUnpack;

in runCommand "texlive-${tlName}" {
# lots of derivations, not meant to be cached
preferLocalBuild = true; allowSubstitutes = false;
inherit passthru;
}
in if sha512 == "" then
# hash stripped from pkgs.nix to save space -> fetch&unpack in a single step
fetchurl {
inherit urls;
sha1 = if fixedHash == null then throw "TeX Live package ${tlName} is missing hash!"
else fixedHash;
name = tlName;
recursiveHash = true;
downloadToTemp = true;
postFetch = ''mkdir "$out";'' + unpackCmd "$downloadedFile";
# TODO: perhaps override preferHashedMirrors and allowSubstitutes
}
// passthru

else runCommand "texlive-${tlName}"
( { # lots of derivations, not meant to be cached
preferLocalBuild = true; allowSubstitutes = false;
inherit passthru;
} // lib.optionalAttrs (fixedHash != null) {
outputHash = fixedHash;
outputHashAlgo = "sha1";
outputHashMode = "recursive";
}
)
( ''
mkdir "$out"
'' + unpackCmd "'${src}'"
Expand Down
10 changes: 10 additions & 0 deletions pkgs/tools/typesetting/tex/texlive/fixHashes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh

echo "{"
grep -v -F '.bin-' | while read path; do
hash=`nix-hash --type sha1 --base32 "$path"`
echo -n "$path" | sed -E 's/[^-]*-texlive-(.*)/"\1"/'
echo "=\"$hash\";"
done
echo "}"

0 comments on commit 292413f

Please sign in to comment.