at 25.11-pre 2.2 kB view raw
1# This expression returns a list of all fetchurl calls used by ‘expr’. 2 3{ 4 expr, 5 lib ? import ../../lib, 6}: 7 8let 9 inherit (lib) 10 addErrorContext 11 attrNames 12 concatLists 13 const 14 filter 15 genericClosure 16 isAttrs 17 isDerivation 18 isList 19 mapAttrsToList 20 optional 21 optionals 22 ; 23 24 root = expr; 25 26 uniqueFiles = map (x: x.file) (genericClosure { 27 startSet = map (file: { 28 key = with file; (if type == null then "" else type + "+") + hash; 29 inherit file; 30 }) files; 31 operator = const [ ]; 32 }); 33 34 files = map (drv: { 35 urls = drv.urls or [ drv.url ]; 36 hash = drv.outputHash; 37 isPatch = (drv ? postFetch && drv.postFetch != ""); 38 type = drv.outputHashAlgo; 39 name = drv.name; 40 }) fetchurlDependencies; 41 42 fetchurlDependencies = filter ( 43 drv: 44 drv.outputHash or "" != "" && drv.outputHashMode or "flat" == "flat" && (drv ? url || drv ? urls) 45 ) dependencies; 46 47 dependencies = map (x: x.value) (genericClosure { 48 startSet = map keyDrv (derivationsIn' root); 49 operator = { key, value }: map keyDrv (immediateDependenciesOf value); 50 }); 51 52 derivationsIn' = 53 x: 54 if !canEval x then 55 [ ] 56 else if isDerivation x then 57 optional (canEval x.drvPath) x 58 else if isList x then 59 concatLists (map derivationsIn' x) 60 else if isAttrs x then 61 concatLists ( 62 mapAttrsToList (n: v: addErrorContext "while finding tarballs in '${n}':" (derivationsIn' v)) x 63 ) 64 else 65 [ ]; 66 67 keyDrv = 68 drv: 69 if canEval drv.drvPath then 70 { 71 key = drv.drvPath; 72 value = drv; 73 } 74 else 75 { }; 76 77 immediateDependenciesOf = 78 drv: 79 concatLists ( 80 mapAttrsToList (n: v: derivationsIn v) ( 81 removeAttrs drv ( 82 [ 83 "meta" 84 "passthru" 85 ] 86 ++ optionals (drv ? passthru) (attrNames drv.passthru) 87 ) 88 ) 89 ); 90 91 derivationsIn = 92 x: 93 if !canEval x then 94 [ ] 95 else if isDerivation x then 96 optional (canEval x.drvPath) x 97 else if isList x then 98 concatLists (map derivationsIn x) 99 else 100 [ ]; 101 102 canEval = val: (builtins.tryEval val).success; 103 104in 105uniqueFiles