summary refs log tree commit diff
path: root/pkgs/tools/typesetting/tex/texlive/generate-fixed-hashes.nix
blob: dedb877448a6f94986d483fb3656bbf461d40408 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
with import ../../../../.. { };

with lib; let
  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 = 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);

  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));

  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
{
  # fixedHashesNix uses 'import from derivation' which does not parallelize well
  # you should build newHashes first, before evaluating (and building) fixedHashesNix
  newHashes = map computeHash (filter (fod: ! fod ? outputHash) fods);

  fixedHashesNix = writeText "fixed-hashes.nix"
    ''
      {
      ${lib.concatMapStrings hashLine sorted}}
    '';
}