anchor.diff:        )
         ( ''
             mkdir "$out"
  -        '' + lib.concatMapStrings (pkg: pkg.unpackCmd) pkgs
  +        '' + unpackCmd "'${src}'"
         );
   
     # combine a set of TL packages into a single TL meta-package
  
positive.code:           sha512 = attrs.sha512.${tlType};
            inherit pname tlType version;
          };
          in mkPkgs {
            inherit (pkg) pname tlType version;
            pkgList = [ pkg ];
          };
      in {
        # TL pkg contains lists of packages: runtime files, docs, sources, binaries
        pkgs =
  
negative.code:         ++ combinePkgs (attrs.deps or {});
      };
  
    # create a derivation that contains an unpacked upstream TL package
    mkPkg = { pname, tlType, version, sha512, postUnpack ? "", stripPrefix ? 1, ... }@args:
      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
  
        url = args.url or "${urlPrefix}/${urlName}.tar.xz";
        urlPrefix = args.urlPrefix or
          http://lipa.ms.mff.cuni.cz/~cunav5am/nix/texlive-2016;
        # XXX XXX XXX FIXME: mirror the snapshot XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX XXX
        #  ("${mirror}/pub/tex/historic/systems/texlive/${bin.texliveYear}/tlnet-final/archive");
        #mirror = "http://ftp.math.utah.edu";
        src = fetchurl { inherit url sha512; };
  
        passthru = {
          inherit pname tlType version;
        } // lib.optionalAttrs (sha512 != "") { inherit src; };
        unpackCmd = file: ''
          tar -xf ${file} \
            '--strip-components=${toString stripPrefix}' \
            -C "$out" --anchored --exclude=tlpkg --keep-old-files
        '' + postUnpack;
  
      in if sha512 == "" then
        # hash stripped from pkgs.nix to save space -> fetch&unpack in a single step
        fetchurl {
          inherit url;
          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";
  