at 22.05-pre 1.7 kB view raw
1# This expression returns a list of all fetchurl calls used by ‘expr’. 2 3with import ../.. { }; 4with lib; 5 6{ expr }: 7 8let 9 10 root = expr; 11 12 uniqueUrls = map (x: x.file) (genericClosure { 13 startSet = map (file: { key = file.url; inherit file; }) urls; 14 operator = const [ ]; 15 }); 16 17 urls = map (drv: { url = head (drv.urls or [ drv.url ]); hash = drv.outputHash; type = drv.outputHashAlgo; name = drv.name; }) fetchurlDependencies; 18 19 fetchurlDependencies = 20 filter 21 (drv: drv.outputHash or "" != "" && drv.outputHashMode or "flat" == "flat" 22 && drv.postFetch or "" == "" && (drv ? url || drv ? urls)) 23 dependencies; 24 25 dependencies = map (x: x.value) (genericClosure { 26 startSet = map keyDrv (derivationsIn' root); 27 operator = { key, value }: map keyDrv (immediateDependenciesOf value); 28 }); 29 30 derivationsIn' = x: 31 if !canEval x then [] 32 else if isDerivation x then optional (canEval x.drvPath) x 33 else if isList x then concatLists (map derivationsIn' x) 34 else if isAttrs x then concatLists (mapAttrsToList (n: v: addErrorContext "while finding tarballs in '${n}':" (derivationsIn' v)) x) 35 else [ ]; 36 37 keyDrv = drv: if canEval drv.drvPath then { key = drv.drvPath; value = drv; } else { }; 38 39 immediateDependenciesOf = drv: 40 concatLists (mapAttrsToList (n: v: derivationsIn v) (removeAttrs drv (["meta" "passthru"] ++ optionals (drv?passthru) (attrNames drv.passthru)))); 41 42 derivationsIn = x: 43 if !canEval x then [] 44 else if isDerivation x then optional (canEval x.drvPath) x 45 else if isList x then concatLists (map derivationsIn x) 46 else [ ]; 47 48 canEval = val: (builtins.tryEval val).success; 49 50in uniqueUrls