nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at haskell-updates 52 lines 1.5 kB view raw
1{ 2 jq, 3 lib, 4 python3, 5 runCommand, 6 writeText, 7}: 8 9{ 10 closureRoots, 11 excludePaths ? [ ], 12 maxLayers ? 100, 13 fromImage ? null, 14 debug ? false, 15}: 16 17runCommand "layers.json" 18 { 19 __structuredAttrs = true; 20 exportReferencesGraph.graph = closureRoots; 21 inherit fromImage maxLayers; 22 nativeBuildInputs = [ 23 jq 24 python3 25 ]; 26 excludePathsFile = writeText "excludePaths" (lib.concatMapStrings (x: x + "\n") excludePaths); 27 } 28 '' 29 # Compute the number of layers that are already used by a potential 30 # 'fromImage' as well as the customization layer. Ensure that there is 31 # still at least one layer available to store the image contents. 32 # one layer will be taken up by the customisation layer 33 usedLayers=1 34 35 if [ -n "$fromImage" ]; then 36 # subtract number of base image layers 37 baseImageLayersCount=$(tar -xOf "$fromImage" manifest.json | jq '.[0].Layers | length') 38 (( usedLayers += baseImageLayersCount )) 39 fi 40 41 if ! (( $usedLayers < $maxLayers )); then 42 echo >&2 "Error: usedLayers $usedLayers layers to store 'fromImage' and" \ 43 "'extraCommands', but only maxLayers=$maxLayers were" \ 44 "allowed. At least 1 layer is required to store contents." 45 exit 1 46 fi 47 availableLayers=$(( maxLayers - usedLayers )) 48 49 jq .graph "$NIX_ATTRS_JSON_FILE" > referencesGraph 50 ${lib.optionalString debug "export DEBUG=1"} 51 python3 ${./auto-layer.py} referencesGraph $excludePathsFile $availableLayers > $out 52 ''