Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at netboot-syslinux-multiplatform 102 lines 3.1 kB view raw
1{ dhall, dhall-docs, haskell, lib, lndir, runCommand, writeText }: 2 3{ name 4 5 # Expressions to add to the cache before interpreting the code 6, dependencies ? [] 7 8 # A Dhall expression 9 # 10 # Carefully note that the following expression must be devoid of uncached HTTP 11 # imports. This is because the expression will be evaluated using an 12 # interpreter with HTTP support disabled, so all HTTP imports have to be 13 # protected by an integrity check that can be satisfied via cached 14 # dependencies. 15 # 16 # You can add a dependency to the cache using the preceding `dependencies` 17 # option 18, code 19 20 # `buildDhallPackage` can include both a "source distribution" in 21 # `source.dhall` and a "binary distribution" in `binary.dhall`: 22 # 23 # * `source.dhall` is a dependency-free αβ-normalized Dhall expression 24 # 25 # * `binary.dhall` is an expression of the form: `missing sha256:${HASH}` 26 # 27 # This expression requires you to install the cache product located at 28 # `.cache/dhall/1220${HASH}` to successfully resolve 29 # 30 # By default, `buildDhallPackage` only includes "binary.dhall" to conserve 31 # space within the Nix store, but if you set the following `source` option to 32 # `true` then the package will also include `source.dhall`. 33, source ? false 34 35 # Directory to generate documentation for (i.e. as the `--input` option to the 36 # `dhall-docs` command.) 37 # 38 # If `null`, then no documentation is generated. 39, documentationRoot ? null 40 41 # Base URL prepended to paths copied to the clipboard 42 # 43 # This is used in conjunction with `documentationRoot`, and is unused if 44 # `documentationRoot` is `null`. 45, baseImportUrl ? null 46}: 47 48let 49 # HTTP support is disabled in order to force that HTTP dependencies are built 50 # using Nix instead of using Dhall's support for HTTP imports. 51 dhallNoHTTP = haskell.lib.compose.appendConfigureFlag "-f-with-http" dhall; 52 53 file = writeText "${name}.dhall" code; 54 55 cache = ".cache"; 56 57 data = ".local/share"; 58 59 cacheDhall = "${cache}/dhall"; 60 61 dataDhall = "${data}/dhall"; 62 63 sourceFile = "source.dhall"; 64 65in 66 runCommand name { inherit dependencies; } '' 67 set -eu 68 69 mkdir -p ${cacheDhall} 70 71 for dependency in $dependencies; do 72 ${lndir}/bin/lndir -silent $dependency/${cacheDhall} ${cacheDhall} 73 done 74 75 export XDG_CACHE_HOME=$PWD/${cache} 76 77 mkdir -p $out/${cacheDhall} 78 79 ${dhallNoHTTP}/bin/dhall --alpha --file '${file}' > $out/${sourceFile} 80 81 SHA_HASH=$(${dhallNoHTTP}/bin/dhall hash <<< $out/${sourceFile}) 82 83 HASH_FILE="''${SHA_HASH/sha256:/1220}" 84 85 ${dhallNoHTTP}/bin/dhall encode --file $out/${sourceFile} > $out/${cacheDhall}/$HASH_FILE 86 87 echo "missing $SHA_HASH" > $out/binary.dhall 88 89 ${lib.optionalString (!source) "rm $out/${sourceFile}"} 90 91 ${lib.optionalString (documentationRoot != null) '' 92 mkdir -p $out/${dataDhall} 93 94 XDG_DATA_HOME=$out/${data} ${dhall-docs}/bin/dhall-docs --output-link $out/docs ${lib.cli.toGNUCommandLineShell { } { 95 base-import-url = baseImportUrl; 96 97 input = documentationRoot; 98 99 package-name = name; 100 }} 101 ''} 102 ''