···5050check, so the first step is to freeze the expression using `dhall freeze`,5151like this:52525353-```bash5353+```ShellSession5454$ dhall freeze --inplace ./true.dhall5555```5656···113113114114… which we can then build using this command:115115116116-```bash116116+```ShellSession117117$ nix build --file ./example.nix dhallPackages.true118118```119119···121121122122The above package produces the following directory tree:123123124124-```bash124124+```ShellSession125125$ tree -a ./result126126result127127├── .cache···135135136136* `source.dhall` contains the result of interpreting our Dhall package:137137138138- ```bash138138+ ```ShellSession139139 $ cat ./result/source.dhall140140 True141141 ```···143143* The `.cache` subdirectory contains one binary cache product encoding the144144 same result as `source.dhall`:145145146146- ```bash146146+ ```ShellSession147147 $ dhall decode < ./result/.cache/dhall/122027abdeddfe8503496adeb623466caa47da5f63abd2bc6fa19f6cfcb73ecfed70148148 True149149 ```···151151* `binary.dhall` contains a Dhall expression which handles fetching and decoding152152 the same cache product:153153154154- ```bash154154+ ```ShellSession155155 $ cat ./result/binary.dhall156156 missing sha256:27abdeddfe8503496adeb623466caa47da5f63abd2bc6fa19f6cfcb73ecfed70157157 $ cp -r ./result/.cache .cache···168168example, if we build the Prelude package it will only contain the binary169169encoding of the expression:170170171171-```bash171171+```ShellSession172172$ nix build --file ./example.nix dhallPackages.Prelude173173174174$ tree -a result···199199… and now the Prelude will contain the fully decoded result of interpreting200200the Prelude:201201202202-```bash202202+```ShellSession203203$ nix build --file ./example.nix dhallPackages.Prelude204204205205$ tree -a result···302302You can use the `dhall-to-nixpkgs` command-line utility to automate303303packaging Dhall code. For example:304304305305-```bash305305+```ShellSession306306$ nix-env --install --attr haskellPackages.dhall-nixpkgs307307308308$ nix-env --install --attr nix-prefetch-git # Used by dhall-to-nixpkgs···329329them to package dependencies. You can also use the utility on local330330Dhall directories, too:331331332332-```bash332332+```ShellSession333333$ dhall-to-nixpkgs directory ~/proj/dhall-semver334334{ buildDhallDirectoryPackage, Prelude }:335335 buildDhallDirectoryPackage {336336 name = "proj";337337- src = /Users/gabriel/proj/dhall-semver;337337+ src = ~/proj/dhall-semver;338338 file = "package.dhall";339339 source = false;340340 document = false;341341 dependencies = [ (Prelude.overridePackage { file = "package.dhall"; }) ];342342 }343343```344344+345345+### Remote imports as fixed-output derivations {#ssec-dhall-remote-imports-as-fod}346346+347347+`dhall-to-nixpkgs` has the ability to fetch and build remote imports as348348+fixed-output derivations by using their Dhall integrity check. This is349349+sometimes easier than manually packaging all remote imports.350350+351351+This can be used like the following:352352+353353+```ShellSession354354+$ dhall-to-nixpkgs directory --fixed-output-derivations ~/proj/dhall-semver355355+{ buildDhallDirectoryPackage, buildDhallUrl }:356356+ buildDhallDirectoryPackage {357357+ name = "proj";358358+ src = ~/proj/dhall-semver;359359+ file = "package.dhall";360360+ source = false;361361+ document = false;362362+ dependencies = [363363+ (buildDhallUrl {364364+ url = "https://prelude.dhall-lang.org/v17.0.0/package.dhall";365365+ hash = "sha256-ENs8kZwl6QRoM9+Jeo/+JwHcOQ+giT2VjDQwUkvlpD4=";366366+ dhallHash = "sha256:10db3c919c25e9046833df897a8ffe2701dc390fa0893d958c3430524be5a43e";367367+ })368368+ ];369369+ }370370+```371371+372372+Here, `dhall-semver`'s `Prelude` dependency is fetched and built with the373373+`buildDhallUrl` helper function, instead of being passed in as a function374374+argument.344375345376## Overriding dependency versions {#ssec-dhall-overriding-dependency-versions}346377···390359391360If we try to rebuild that expression the build will fail:392361393393-```362362+```ShellSession394363$ nix build --file ./example.nix dhallPackages.true395364builder for '/nix/store/0f1hla7ff1wiaqyk1r2ky4wnhnw114fi-true.drv' failed with exit code 1; last 10 log lines:396365···416385However, we can override the default Prelude version by using `dhall-to-nixpkgs`417386to create a Dhall package for our desired Prelude:418387419419-```bash388388+```ShellSession420389$ dhall-to-nixpkgs github https://github.com/dhall-lang/dhall-lang.git \421390 --name Prelude \422391 --directory Prelude \···427396… and then referencing that package in our Dhall overlay, by either overriding428397the Prelude globally for all packages, like this:429398430430-```bash399399+```nix431400 dhallOverrides = self: super: {432401 true = self.callPackage ./true.nix { };433402···438407… or selectively overriding the Prelude dependency for just the `true` package,439408like this:440409441441-```bash410410+```nix442411 dhallOverrides = self: super: {443412 true = self.callPackage ./true.nix {444413 Prelude = self.callPackage ./Prelude.nix { };
···11+{ cacert, dhall, dhall-docs, haskell, lib, runCommand }:22+33+# `buildDhallUrl` is similar to `buildDhallDirectoryPackage` or44+# `buildDhallGitHubPackage`, but instead builds a Nixpkgs Dhall package55+# based on a hashed URL. This will generally be a URL that has an integrity66+# check in a Dhall file.77+#88+# Similar to `buildDhallDirectoryPackage` and `buildDhallGitHubPackage`, the output99+# of this function is a derivation that has a `binary.dhall` file, along with1010+# a `.cache/` directory with the actual contents of the Dhall file from the1111+# suppiled URL.1212+#1313+# This function is primarily used by `dhall-to-nixpkgs directory --fixed-output-derivations`.1414+1515+{ # URL of the input Dhall file.1616+ # example: "https://raw.githubusercontent.com/cdepillabout/example-dhall-repo/c1b0d0327146648dcf8de997b2aa32758f2ed735/example1.dhall"1717+ url1818+1919+ # Nix hash of the input Dhall file.2020+ # example: "sha256-ZTSiQUXpPbPfPvS8OeK6dDQE6j6NbP27ho1cg9YfENI="2121+, hash2222+2323+ # Dhall hash of the input Dhall file.2424+ # example: "sha256:6534a24145e93db3df3ef4bc39e2ba743404ea3e8d6cfdbb868d5c83d61f10d2"2525+, dhallHash2626+2727+ # Name for this derivation.2828+, name ? (baseNameOf url + "-cache")2929+3030+ # `buildDhallUrl` can include both a "source distribution" in3131+ # `source.dhall` and a "binary distribution" in `binary.dhall`:3232+ #3333+ # * `source.dhall` is a dependency-free αβ-normalized Dhall expression3434+ #3535+ # * `binary.dhall` is an expression of the form: `missing sha256:${HASH}`3636+ #3737+ # This expression requires you to install the cache product located at3838+ # `.cache/dhall/1220${HASH}` to successfully resolve3939+ #4040+ # By default, `buildDhallUrl` only includes "binary.dhall" to conserve4141+ # space within the Nix store, but if you set the following `source` option to4242+ # `true` then the package will also include `source.dhall`.4343+, source ? false4444+}:4545+4646+let4747+ # HTTP support is disabled in order to force that HTTP dependencies are built4848+ # using Nix instead of using Dhall's support for HTTP imports.4949+ dhallNoHTTP = haskell.lib.appendConfigureFlag dhall "-f-with-http";5050+5151+ # This uses Dhall's remote importing capabilities for downloading a Dhall file.5252+ # The output Dhall file has all imports resolved, and then is5353+ # alpha-normalized and binary-encoded.5454+ downloadedEncodedFile =5555+ runCommand5656+ (baseNameOf url)5757+ {5858+ outputHashAlgo = null;5959+ outputHash = hash;6060+ name = baseNameOf url;6161+ nativeBuildInputs = [ cacert ];6262+ }6363+ ''6464+ echo "${url} ${dhallHash}" > in-dhall-file6565+ ${dhall}/bin/dhall --alpha --plain --file in-dhall-file | ${dhallNoHTTP}/bin/dhall encode > $out6666+ '';6767+6868+ cache = ".cache";6969+7070+ data = ".local/share";7171+7272+ cacheDhall = "${cache}/dhall";7373+7474+ dataDhall = "${data}/dhall";7575+7676+ sourceFile = "source.dhall";7777+7878+in7979+ runCommand name { } (''8080+ set -eu8181+8282+ mkdir -p ${cacheDhall} $out/${cacheDhall}8383+8484+ export XDG_CACHE_HOME=$PWD/${cache}8585+8686+ SHA_HASH="${dhallHash}"8787+8888+ HASH_FILE="''${SHA_HASH/sha256:/1220}"8989+9090+ cp ${downloadedEncodedFile} $out/${cacheDhall}/$HASH_FILE9191+9292+ echo "missing $SHA_HASH" > $out/binary.dhall9393+ '' +9494+ lib.optionalString source ''9595+ ${dhallNoHTTP}/bin/dhall decode --file ${downloadedEncodedFile} > $out/${sourceFile}9696+ '')
···4545 url = "https://developer.nvidia.com/vulkan-beta-${lib.concatStrings (lib.splitString "." version)}-linux";4646 };47474848+ # Update note:4949+ # If you add a legacy driver here, also update `top-level/linux-kernels.nix`,5050+ # adding to the `nvidia_x11_legacy*` entries.5151+4852 # Last one supporting Kepler architecture4953 legacy_470 = generic {5054 version = "470.82.00";
···11+{ dhallPackages, lib }:22+33+# This file tests that dhallPackages.buildDhallUrl is able to successfully44+# build a Nix Dhall package for a given remote Dhall import.55+#66+# TODO: It would be nice to extend this test to make sure that the resulting77+# Nix Dhall package is has the expected contents.88+99+dhallPackages.buildDhallUrl {1010+ url = "https://raw.githubusercontent.com/cdepillabout/example-dhall-nix/e6a675c72ecd4dd23d254a02aea8181fe875747f/mydhallfile.dhall";1111+ hash = "sha256-434x+QjHRzuprBdw0h6wmwB1Zj6yZqQb533me8XdO4c=";1212+ dhallHash = "sha256:e37e31f908c7473ba9ac1770d21eb09b0075663eb266a41be77de67bc5dd3b87";1313+ source = true;1414+}