core/pkgs/by-name/te/texlive/generate-fixed-hashes.nix

47 lines
1.6 KiB
Nix
Raw Normal View History

2024-05-02 00:46:19 +00:00
{ pkgs ? (import ../../../../.. { }) }:
let
inherit (pkgs) runCommand writeText texlive nix;
inherit (pkgs.lib)
2024-05-13 21:24:10 +00:00
attrValues concatMap concatMapStrings isDerivation filter optional
optionalString sort strings;
getFods = drv:
optional (isDerivation drv.tex) (drv.tex // { tlType = "run"; })
2024-05-02 00:46:19 +00:00
++ optional (drv ? texdoc) (drv.texdoc // { tlType = "doc"; })
++ optional (drv ? texsource) (drv.texsource // { tlType = "source"; })
++ optional (drv ? tlpkg) (drv.tlpkg // { tlType = "tlpkg"; });
sorted = sort (a: b: a.pname < b.pname) (attrValues texlive.pkgs);
fods = concatMap getFods sorted;
2024-05-13 21:24:10 +00:00
computeHash = fod:
runCommand "${fod.pname}-${fod.tlType}-fixed-hash" {
buildInputs = [ nix ];
inherit fod;
} ''echo -n "$(nix-hash --base32 --type sha256 "$fod")" >"$out"'';
2024-05-02 00:46:19 +00:00
hash = fod: fod.outputHash or (builtins.readFile (computeHash fod));
hashes = fods:
concatMapStrings ({ tlType, ... }@p: ''${tlType}="${hash p}";'') fods;
hashLine = { pname, revision, extraRevision ? "", ... }@drv:
let
fods = getFods drv;
# NOTE: the fixed naming scheme must match default.nix
fixedName = "${pname}-${toString revision}${extraRevision}";
2024-05-13 21:24:10 +00:00
in optionalString (fods != [ ]) ''
2024-05-02 00:46:19 +00:00
${strings.escapeNixIdentifier fixedName}={${hashes fods}};
'';
2024-05-13 21:24:10 +00:00
in {
2024-05-02 00:46:19 +00:00
# fixedHashesNix uses 'import from derivation' which does not parallelize well
# you should build newHashes first, before evaluating (and building) fixedHashesNix
2024-05-13 21:24:10 +00:00
newHashes = map computeHash (filter (fod: !fod ? outputHash) fods);
2024-05-02 00:46:19 +00:00
2024-05-13 21:24:10 +00:00
fixedHashesNix = writeText "fixed-hashes.nix" ''
{
${concatMapStrings hashLine sorted}}
'';
2024-05-02 00:46:19 +00:00
}