14 # Expressions to add to the cache before interpreting the code
19 # Carefully note that the following expression must be devoid of uncached HTTP
20 # imports. This is because the expression will be evaluated using an
21 # interpreter with HTTP support disabled, so all HTTP imports have to be
22 # protected by an integrity check that can be satisfied via cached
25 # You can add a dependency to the cache using the preceding `dependencies`
29 # `buildDhallPackage` can include both a "source distribution" in
30 # `source.dhall` and a "binary distribution" in `binary.dhall`:
32 # * `source.dhall` is a dependency-free αβ-normalized Dhall expression
34 # * `binary.dhall` is an expression of the form: `missing sha256:${HASH}`
36 # This expression requires you to install the cache product located at
37 # `.cache/dhall/1220${HASH}` to successfully resolve
39 # By default, `buildDhallPackage` only includes "binary.dhall" to conserve
40 # space within the Nix store, but if you set the following `source` option to
41 # `true` then the package will also include `source.dhall`.
44 # Directory to generate documentation for (i.e. as the `--input` option to the
45 # `dhall-docs` command.)
47 # If `null`, then no documentation is generated.
48 documentationRoot ? null,
50 # Base URL prepended to paths copied to the clipboard
52 # This is used in conjunction with `documentationRoot`, and is unused if
53 # `documentationRoot` is `null`.
58 # HTTP support is disabled in order to force that HTTP dependencies are built
59 # using Nix instead of using Dhall's support for HTTP imports.
60 dhallNoHTTP = haskell.lib.compose.appendConfigureFlag "-f-with-http" dhall;
62 file = writeText "${name}.dhall" code;
66 data = ".local/share";
68 cacheDhall = "${cache}/dhall";
70 dataDhall = "${data}/dhall";
72 sourceFile = "source.dhall";
75 runCommand name { inherit dependencies; } ''
78 mkdir -p ${cacheDhall}
80 for dependency in $dependencies; do
81 ${lndir}/bin/lndir -silent $dependency/${cacheDhall} ${cacheDhall}
84 export XDG_CACHE_HOME=$PWD/${cache}
86 mkdir -p $out/${cacheDhall}
88 ${dhallNoHTTP}/bin/dhall --alpha --file '${file}' > $out/${sourceFile}
90 SHA_HASH=$(${dhallNoHTTP}/bin/dhall hash <<< $out/${sourceFile})
92 HASH_FILE="''${SHA_HASH/sha256:/1220}"
94 ${dhallNoHTTP}/bin/dhall encode --file $out/${sourceFile} > $out/${cacheDhall}/$HASH_FILE
96 echo "missing $SHA_HASH" > $out/binary.dhall
98 ${lib.optionalString (!source) "rm $out/${sourceFile}"}
100 ${lib.optionalString (documentationRoot != null) ''
101 mkdir -p $out/${dataDhall}
103 XDG_DATA_HOME=$out/${data} ${dhall-docs}/bin/dhall-docs --output-link $out/docs ${
104 lib.cli.toGNUCommandLineShell { } {
105 base-import-url = baseImportUrl;
107 input = documentationRoot;