Commit b5188683 authored by Vincenzo Mantova's avatar Vincenzo Mantova
Browse files

texlive: group fixed hashes into one attribute set per package

parent 260d7d11
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -380,7 +380,7 @@ let
      npp-for-context.license = [  "gpl3Only" ];

      texdoc = {
        extraRevision = ".tlpdb${toString tlpdbVersion.revision}";
        extraRevision = "-tlpdb${toString tlpdbVersion.revision}";
        extraVersion = "-tlpdb-${toString tlpdbVersion.revision}";

        # build Data.tlpdb.lua (part of the 'tlType == "run"' package)
@@ -446,6 +446,7 @@ let
            # the fake derivations are used for filtering of hyphenation patterns and formats
          else ({
            inherit pname version;
            inherit (attrs) revision;
            tlType = "run";
            hasHyphens = attrs.hasHyphens or false;
            tlDeps = map (n: tl.${n}) (attrs.deps or []);
@@ -506,11 +507,11 @@ let
  # map: name -> fixed-output hash
  fixedHashes = lib.optionalAttrs useFixedHashes (import ./fixed-hashes.nix);

  # NOTE: the fixed naming scheme must match generated-fixed-hashes.nix
  # name for the URL
  mkURLName = { pname, tlType, ... }: pname + lib.optionalString (tlType != "run" && tlType != "tlpkg") ".${tlType}";
  # NOTE: the fixed naming scheme must match generated-fixed-hashes.nix
  # name + revision for the fixed output hashes
  mkFixedName = { tlType, revision, extraRevision ? "", ... }@attrs: mkURLName attrs + (lib.optionalString (tlType == "tlpkg") ".tlpkg") + ".r${toString revision}${extraRevision}";
  mkFixedName = { pname, tlType, revision, extraRevision ? "", ... }: "${pname}-${toString revision}${extraRevision}";
  # name + version for the derivation
  mkTLName = { tlType, version, extraVersion ? "", ... }@attrs: mkURLName attrs + (lib.optionalString (tlType == "tlpkg") ".tlpkg") + "-${version}${extraVersion}";

@@ -558,7 +559,8 @@ let
      # the basename used by upstream (without ".tar.xz" suffix)
      urlName = mkURLName args;
      tlName = mkTLName args;
      fixedHash = fixedHashes.${mkFixedName args} or null; # be graceful about missing hashes
      fixedName = mkFixedName args;
      fixedHash = if fixedHashes ? ${fixedName} then fixedHashes.${fixedName}.${tlType} or null else null; # be graceful about missing hashes

      urls = args.urls or (if args ? url then [ args.url ] else
        map (up: "${up}/archive/${urlName}.r${toString revision}.tar.xz") (args.urlPrefixes or urlPrefixes));
+4243 −9896

File changed.

Preview size limit exceeded, changes collapsed.

+24 −23
Original line number Diff line number Diff line
with import ../../../../.. { };

with lib; let
  # NOTE: the fixed naming scheme must match default.nix
  # name for the URL
  mkURLName = { pname, tlType, ... }: pname + lib.optionalString (tlType != "run" && tlType != "tlpkg") ".${tlType}";
  # name + revision for the fixed output hashes
  mkFixedName = { tlType, revision, extraRevision ? "", ... }@attrs: mkURLName attrs + (lib.optionalString (tlType == "tlpkg") ".tlpkg") + ".r${toString revision}${extraRevision}";

  uniqueByName = fods: catAttrs "fod" (genericClosure {
    startSet = map (fod: { key = fod.name; inherit fod; }) fods;
    operator = _: [ ];
  });
  isFod = p: p.tlType != "bin" && isDerivation p;

  # ugly hack to extract combine from collection-latexextra, since it is masked by texlive.combine
  combine = lib.findFirst (p: (lib.head p.pkgs).pname == "combine") { pkgs = [ ]; } (lib.head texlive.collection-latexextra.pkgs).tlDeps;
  all = concatLists (map (p: p.pkgs or []) (attrValues (removeAttrs texlive [ "bin" "combine" "combined" "tlpdb" ]))) ++ combine.pkgs;
  all = filter (p: p ? pkgs) (attrValues (removeAttrs texlive [ "bin" "combine" "combined" "tlpdb" ])) ++ [ combine ];
  sorted = sort (a: b: (head a.pkgs).pname < (head b.pkgs).pname) all;
  fods = filter isFod (concatMap (p: p.pkgs or [ ]) all);

  # fixed hashes only for run, doc, source, tlpkg types
  fods = sort (a: b: a.name < b.name) (uniqueByName (filter (p: isDerivation p && p.tlType != "bin") all));

  computeHash = fod: runCommand "${fod.name}-fixed-hash"
  computeHash = fod: runCommand "${fod.pname}-${fod.tlType}-fixed-hash"
    { buildInputs = [ nix ]; inherit fod; }
    ''echo -n "$(nix-hash --base32 --type sha256 "$fod")" >"$out"'';

  hash = fod: fod.outputHash or (builtins.readFile (computeHash fod));
  hashLine = fod: ''
    "${mkFixedName fod}"="${hash fod}";

  hashes = { pkgs }:
    concatMapStrings ({ tlType, ... }@p: lib.optionalString (isFod p) (''${tlType}="${hash p}";'')) pkgs;

  hashLine = { pkgs }@pkg:
    let
      fods = lib.filter isFod pkgs;
      first = lib.head fods;
      # NOTE: the fixed naming scheme must match default.nix
      fixedName = with first; "${pname}-${toString revision}${first.extraRevision or ""}";
    in
    lib.optionalString (fods != [ ]) ''
      ${strings.escapeNixIdentifier fixedName}={${hashes pkg}};
    '';
in
{
@@ -36,6 +37,6 @@ in
  fixedHashesNix = writeText "fixed-hashes.nix"
    ''
      {
    ${lib.concatMapStrings hashLine fods}}
      ${lib.concatMapStrings hashLine sorted}}
    '';
}