···11+22+# `dhallPackageToNix` is a utility function to take a Nixpkgs Dhall package
33+# (created with a function like `dhallPackages.buildDhallDirectoryPackage`)
44+# and read it in as a Nix expression.
55+#
66+# This function is similar to `dhallToNix`, but takes a Nixpkgs Dhall package
77+# as input instead of raw Dhall code.
88+#
99+# Note that this uses "import from derivation" (IFD), meaning that Nix will
1010+# perform a build during the evaluation phase if you use this
1111+# `dhallPackageToNix` utility. It is not possible to use `dhallPackageToNix`
1212+# in Nixpkgs, since the Nixpkgs Hydra doesn't allow IFD.
1313+1414+{ stdenv, dhall-nix }:
1515+1616+dhallPackage:
1717+ let
1818+ drv = stdenv.mkDerivation {
1919+ name = "dhall-compiled-package.nix";
2020+2121+ buildCommand = ''
2222+ # Dhall requires that the cache is writable, even if it is never written to.
2323+ # We copy the cache from the input package to the current directory and
2424+ # set the cache as writable.
2525+ cp -r "${dhallPackage}/.cache" ./
2626+ export XDG_CACHE_HOME=$PWD/.cache
2727+ chmod -R +w ./.cache
2828+2929+ dhall-to-nix <<< "${dhallPackage}/binary.dhall" > $out
3030+ '';
3131+3232+ nativeBuildInputs = [ dhall-nix ];
3333+ };
3434+3535+ in
3636+ import drv