2020-11-26 06:02:26 +00:00
|
|
|
{ dhall, dhall-docs, haskell, lib, lndir, runCommand, writeText }:
|
2020-02-12 06:02:53 +00:00
|
|
|
|
|
|
|
{ name
|
|
|
|
|
|
|
|
# Expressions to add to the cache before interpreting the code
|
|
|
|
, dependencies ? []
|
|
|
|
|
|
|
|
# A Dhall expression
|
|
|
|
#
|
|
|
|
# Carefully note that the following expression must be devoid of uncached HTTP
|
|
|
|
# imports. This is because the expression will be evaluated using an
|
|
|
|
# interpreter with HTTP support disabled, so all HTTP imports have to be
|
|
|
|
# protected by an integrity check that can be satisfied via cached
|
|
|
|
# dependencies.
|
|
|
|
#
|
|
|
|
# You can add a dependency to the cache using the preceding `dependencies`
|
|
|
|
# option
|
|
|
|
, code
|
|
|
|
|
|
|
|
# `buildDhallPackage` can include both a "source distribution" in
|
|
|
|
# `source.dhall` and a "binary distribution" in `binary.dhall`:
|
|
|
|
#
|
|
|
|
# * `source.dhall` is a dependency-free αβ-normalized Dhall expression
|
|
|
|
#
|
|
|
|
# * `binary.dhall` is an expression of the form: `missing sha256:${HASH}`
|
|
|
|
#
|
|
|
|
# This expression requires you to install the cache product located at
|
|
|
|
# `.cache/dhall/1220${HASH}` to successfully resolve
|
|
|
|
#
|
|
|
|
# By default, `buildDhallPackage` only includes "binary.dhall" to conserve
|
|
|
|
# space within the Nix store, but if you set the following `source` option to
|
|
|
|
# `true` then the package will also include `source.dhall`.
|
|
|
|
, source ? false
|
2020-11-26 06:02:26 +00:00
|
|
|
|
|
|
|
# Directory to generate documentation for (i.e. as the `--input` option to the
|
|
|
|
# `dhall-docs` command.)
|
|
|
|
#
|
|
|
|
# If `null`, then no documentation is generated.
|
|
|
|
, documentationRoot ? null
|
2021-06-30 03:09:29 +01:00
|
|
|
|
|
|
|
# Base URL prepended to paths copied to the clipboard
|
|
|
|
#
|
|
|
|
# This is used in conjunction with `documentationRoot`, and is unused if
|
|
|
|
# `documentationRoot` is `null`.
|
|
|
|
, baseImportUrl ? null
|
2020-02-12 06:02:53 +00:00
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
|
|
|
# HTTP support is disabled in order to force that HTTP dependencies are built
|
|
|
|
# using Nix instead of using Dhall's support for HTTP imports.
|
2021-10-26 11:20:34 +01:00
|
|
|
dhallNoHTTP = haskell.lib.compose.appendConfigureFlag "-f-with-http" dhall;
|
2020-02-12 06:02:53 +00:00
|
|
|
|
|
|
|
file = writeText "${name}.dhall" code;
|
|
|
|
|
|
|
|
cache = ".cache";
|
|
|
|
|
2020-11-26 06:02:26 +00:00
|
|
|
data = ".local/share";
|
|
|
|
|
2020-02-12 06:02:53 +00:00
|
|
|
cacheDhall = "${cache}/dhall";
|
|
|
|
|
2020-11-26 06:02:26 +00:00
|
|
|
dataDhall = "${data}/dhall";
|
|
|
|
|
2020-02-12 06:02:53 +00:00
|
|
|
sourceFile = "source.dhall";
|
|
|
|
|
|
|
|
in
|
|
|
|
runCommand name { inherit dependencies; } ''
|
|
|
|
set -eu
|
|
|
|
|
|
|
|
mkdir -p ${cacheDhall}
|
|
|
|
|
|
|
|
for dependency in $dependencies; do
|
|
|
|
${lndir}/bin/lndir -silent $dependency/${cacheDhall} ${cacheDhall}
|
|
|
|
done
|
|
|
|
|
|
|
|
export XDG_CACHE_HOME=$PWD/${cache}
|
|
|
|
|
|
|
|
mkdir -p $out/${cacheDhall}
|
|
|
|
|
2020-04-11 17:07:58 +01:00
|
|
|
${dhallNoHTTP}/bin/dhall --alpha --file '${file}' > $out/${sourceFile}
|
2020-02-12 06:02:53 +00:00
|
|
|
|
2020-04-11 17:07:58 +01:00
|
|
|
SHA_HASH=$(${dhallNoHTTP}/bin/dhall hash <<< $out/${sourceFile})
|
2020-02-12 06:02:53 +00:00
|
|
|
|
|
|
|
HASH_FILE="''${SHA_HASH/sha256:/1220}"
|
|
|
|
|
2020-04-11 17:07:58 +01:00
|
|
|
${dhallNoHTTP}/bin/dhall encode --file $out/${sourceFile} > $out/${cacheDhall}/$HASH_FILE
|
2020-02-12 06:02:53 +00:00
|
|
|
|
|
|
|
echo "missing $SHA_HASH" > $out/binary.dhall
|
|
|
|
|
|
|
|
${lib.optionalString (!source) "rm $out/${sourceFile}"}
|
2020-11-26 06:02:26 +00:00
|
|
|
|
|
|
|
${lib.optionalString (documentationRoot != null) ''
|
|
|
|
mkdir -p $out/${dataDhall}
|
|
|
|
|
2021-06-30 03:09:29 +01:00
|
|
|
XDG_DATA_HOME=$out/${data} ${dhall-docs}/bin/dhall-docs --output-link $out/docs ${lib.cli.toGNUCommandLineShell { } {
|
|
|
|
base-import-url = baseImportUrl;
|
|
|
|
|
|
|
|
input = documentationRoot;
|
|
|
|
|
|
|
|
package-name = name;
|
|
|
|
}}
|
2020-11-26 06:02:26 +00:00
|
|
|
''}
|
2020-02-12 06:02:53 +00:00
|
|
|
''
|