nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 cacert,
3 dhall,
4 dhall-docs,
5 haskell,
6 lib,
7 runCommand,
8}:
9
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.
14#
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
18# suppiled URL.
19#
20# This function is primarily used by `dhall-to-nixpkgs directory --fixed-output-derivations`.
21
22{
23 # URL of the input Dhall file.
24 # example: "https://raw.githubusercontent.com/cdepillabout/example-dhall-repo/c1b0d0327146648dcf8de997b2aa32758f2ed735/example1.dhall"
25 url,
26
27 # Nix hash of the input Dhall file.
28 # example: "sha256-ZTSiQUXpPbPfPvS8OeK6dDQE6j6NbP27ho1cg9YfENI="
29 hash,
30
31 # Dhall hash of the input Dhall file.
32 # example: "sha256:6534a24145e93db3df3ef4bc39e2ba743404ea3e8d6cfdbb868d5c83d61f10d2"
33 dhallHash,
34
35 # Name for this derivation.
36 name ? (baseNameOf url + "-cache"),
37
38 # `buildDhallUrl` can include both a "source distribution" in
39 # `source.dhall` and a "binary distribution" in `binary.dhall`:
40 #
41 # * `source.dhall` is a dependency-free αβ-normalized Dhall expression
42 #
43 # * `binary.dhall` is an expression of the form: `missing sha256:${HASH}`
44 #
45 # This expression requires you to install the cache product located at
46 # `.cache/dhall/1220${HASH}` to successfully resolve
47 #
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`.
51 source ? false,
52}:
53
54let
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";
58
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)
64 {
65 outputHashAlgo = null;
66 outputHash = hash;
67 name = baseNameOf url;
68 nativeBuildInputs = [ cacert ];
69 impureEnvVars = lib.fetchers.proxyImpureEnvVars;
70 }
71 ''
72 echo "${url} ${dhallHash}" > in-dhall-file
73 ${dhall}/bin/dhall --alpha --plain --file in-dhall-file | ${dhallNoHTTP}/bin/dhall encode > $out
74 '';
75
76 cache = ".cache";
77
78 data = ".local/share";
79
80 cacheDhall = "${cache}/dhall";
81
82 dataDhall = "${data}/dhall";
83
84 sourceFile = "source.dhall";
85
86in
87runCommand name { } (
88 ''
89 set -eu
90
91 mkdir -p ${cacheDhall} $out/${cacheDhall}
92
93 export XDG_CACHE_HOME=$PWD/${cache}
94
95 SHA_HASH="${dhallHash}"
96
97 HASH_FILE="''${SHA_HASH/sha256:/1220}"
98
99 cp ${downloadedEncodedFile} $out/${cacheDhall}/$HASH_FILE
100
101 echo "missing $SHA_HASH" > $out/binary.dhall
102 ''
103 + lib.optionalString source ''
104 ${dhallNoHTTP}/bin/dhall decode --file ${downloadedEncodedFile} > $out/${sourceFile}
105 ''
106)