From 738bae4ec2a73c16fa8d4f76b0a41474937a366c Mon Sep 17 00:00:00 2001 From: Uli Baum Date: Mon, 27 Aug 2018 14:04:43 +0200 Subject: [PATCH] texlive: make packages fixed-output derivations This reverts a part of the changes made in #40826. Fixed-output derivations save time and space on rebuilds. --- .../tools/typesetting/tex/texlive/default.nix | 35 ++++++++++++++++--- .../typesetting/tex/texlive/fixHashes.sh | 10 ++++++ 2 files changed, 40 insertions(+), 5 deletions(-) create mode 100755 pkgs/tools/typesetting/tex/texlive/fixHashes.sh diff --git a/pkgs/tools/typesetting/tex/texlive/default.nix b/pkgs/tools/typesetting/tex/texlive/default.nix index e4799e39c43..c10b9c99296 100644 --- a/pkgs/tools/typesetting/tex/texlive/default.nix +++ b/pkgs/tools/typesetting/tex/texlive/default.nix @@ -29,6 +29,7 @@ { stdenv, lib, fetchurl, runCommand, writeText, buildEnv , callPackage, ghostscriptX, harfbuzz, poppler_min , makeWrapper, python, ruby, perl +, useFixedHashes ? true , recurseIntoAttrs }: let @@ -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 @@ -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 @@ -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}'" diff --git a/pkgs/tools/typesetting/tex/texlive/fixHashes.sh b/pkgs/tools/typesetting/tex/texlive/fixHashes.sh new file mode 100755 index 00000000000..439660682e2 --- /dev/null +++ b/pkgs/tools/typesetting/tex/texlive/fixHashes.sh @@ -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 "}" +