1 { cacert, dhall, dhall-docs, haskell, lib, runCommand }:
3 # `buildDhallUrl` is similar to `buildDhallDirectoryPackage` or
4 # `buildDhallGitHubPackage`, but instead builds a Nixpkgs Dhall package
5 # based on a hashed URL. This will generally be a URL that has an integrity
6 # check in a Dhall file.
8 # Similar to `buildDhallDirectoryPackage` and `buildDhallGitHubPackage`, the output
9 # of this function is a derivation that has a `binary.dhall` file, along with
10 # a `.cache/` directory with the actual contents of the Dhall file from the
13 # This function is primarily used by `dhall-to-nixpkgs directory --fixed-output-derivations`.
15 { # URL of the input Dhall file.
16 # example: "https://raw.githubusercontent.com/cdepillabout/example-dhall-repo/c1b0d0327146648dcf8de997b2aa32758f2ed735/example1.dhall"
19 # Nix hash of the input Dhall file.
20 # example: "sha256-ZTSiQUXpPbPfPvS8OeK6dDQE6j6NbP27ho1cg9YfENI="
23 # Dhall hash of the input Dhall file.
24 # example: "sha256:6534a24145e93db3df3ef4bc39e2ba743404ea3e8d6cfdbb868d5c83d61f10d2"
27 # Name for this derivation.
28 , name ? (baseNameOf url + "-cache")
30 # `buildDhallUrl` can include both a "source distribution" in
31 # `source.dhall` and a "binary distribution" in `binary.dhall`:
33 # * `source.dhall` is a dependency-free αβ-normalized Dhall expression
35 # * `binary.dhall` is an expression of the form: `missing sha256:${HASH}`
37 # This expression requires you to install the cache product located at
38 # `.cache/dhall/1220${HASH}` to successfully resolve
40 # By default, `buildDhallUrl` only includes "binary.dhall" to conserve
41 # space within the Nix store, but if you set the following `source` option to
42 # `true` then the package will also include `source.dhall`.
47 # HTTP support is disabled in order to force that HTTP dependencies are built
48 # using Nix instead of using Dhall's support for HTTP imports.
49 dhallNoHTTP = haskell.lib.appendConfigureFlag dhall "-f-with-http";
51 # This uses Dhall's remote importing capabilities for downloading a Dhall file.
52 # The output Dhall file has all imports resolved, and then is
53 # alpha-normalized and binary-encoded.
54 downloadedEncodedFile =
58 outputHashAlgo = null;
60 name = baseNameOf url;
61 nativeBuildInputs = [ cacert ];
62 impureEnvVars = lib.fetchers.proxyImpureEnvVars;
65 echo "${url} ${dhallHash}" > in-dhall-file
66 ${dhall}/bin/dhall --alpha --plain --file in-dhall-file | ${dhallNoHTTP}/bin/dhall encode > $out
71 data = ".local/share";
73 cacheDhall = "${cache}/dhall";
75 dataDhall = "${data}/dhall";
77 sourceFile = "source.dhall";
84 mkdir -p ${cacheDhall} $out/${cacheDhall}
86 export XDG_CACHE_HOME=$PWD/${cache}
88 SHA_HASH="${dhallHash}"
90 HASH_FILE="''${SHA_HASH/sha256:/1220}"
92 cp ${downloadedEncodedFile} $out/${cacheDhall}/$HASH_FILE
94 echo "missing $SHA_HASH" > $out/binary.dhall
96 lib.optionalString source ''
97 ${dhallNoHTTP}/bin/dhall decode --file ${downloadedEncodedFile} > $out/${sourceFile}