10 # `buildDhallUrl` is similar to `buildDhallDirectoryPackage` or
11 # `buildDhallGitHubPackage`, but instead builds a Nixpkgs Dhall package
12 # based on a hashed URL. This will generally be a URL that has an integrity
13 # check in a Dhall file.
15 # Similar to `buildDhallDirectoryPackage` and `buildDhallGitHubPackage`, the output
16 # of this function is a derivation that has a `binary.dhall` file, along with
17 # a `.cache/` directory with the actual contents of the Dhall file from the
20 # This function is primarily used by `dhall-to-nixpkgs directory --fixed-output-derivations`.
23 # URL of the input Dhall file.
24 # example: "https://raw.githubusercontent.com/cdepillabout/example-dhall-repo/c1b0d0327146648dcf8de997b2aa32758f2ed735/example1.dhall"
27 # Nix hash of the input Dhall file.
28 # example: "sha256-ZTSiQUXpPbPfPvS8OeK6dDQE6j6NbP27ho1cg9YfENI="
31 # Dhall hash of the input Dhall file.
32 # example: "sha256:6534a24145e93db3df3ef4bc39e2ba743404ea3e8d6cfdbb868d5c83d61f10d2"
35 # Name for this derivation.
36 name ? (baseNameOf url + "-cache"),
38 # `buildDhallUrl` can include both a "source distribution" in
39 # `source.dhall` and a "binary distribution" in `binary.dhall`:
41 # * `source.dhall` is a dependency-free αβ-normalized Dhall expression
43 # * `binary.dhall` is an expression of the form: `missing sha256:${HASH}`
45 # This expression requires you to install the cache product located at
46 # `.cache/dhall/1220${HASH}` to successfully resolve
48 # By default, `buildDhallUrl` only includes "binary.dhall" to conserve
49 # space within the Nix store, but if you set the following `source` option to
50 # `true` then the package will also include `source.dhall`.
55 # HTTP support is disabled in order to force that HTTP dependencies are built
56 # using Nix instead of using Dhall's support for HTTP imports.
57 dhallNoHTTP = haskell.lib.appendConfigureFlag dhall "-f-with-http";
59 # This uses Dhall's remote importing capabilities for downloading a Dhall file.
60 # The output Dhall file has all imports resolved, and then is
61 # alpha-normalized and binary-encoded.
62 downloadedEncodedFile =
63 runCommand (baseNameOf url)
65 outputHashAlgo = null;
67 name = baseNameOf url;
68 nativeBuildInputs = [ cacert ];
69 impureEnvVars = lib.fetchers.proxyImpureEnvVars;
72 echo "${url} ${dhallHash}" > in-dhall-file
73 ${dhall}/bin/dhall --alpha --plain --file in-dhall-file | ${dhallNoHTTP}/bin/dhall encode > $out
78 data = ".local/share";
80 cacheDhall = "${cache}/dhall";
82 dataDhall = "${data}/dhall";
84 sourceFile = "source.dhall";
91 mkdir -p ${cacheDhall} $out/${cacheDhall}
93 export XDG_CACHE_HOME=$PWD/${cache}
95 SHA_HASH="${dhallHash}"
97 HASH_FILE="''${SHA_HASH/sha256:/1220}"
99 cp ${downloadedEncodedFile} $out/${cacheDhall}/$HASH_FILE
101 echo "missing $SHA_HASH" > $out/binary.dhall
103 + lib.optionalString source ''
104 ${dhallNoHTTP}/bin/dhall decode --file ${downloadedEncodedFile} > $out/${sourceFile}