core/pkgs/build-support/dhall/package-to-nix.nix

35 lines
1.1 KiB
Nix
Raw Normal View History

2024-05-02 00:46:19 +00:00
# `dhallPackageToNix` is a utility function to take a Nixpkgs Dhall package
# (created with a function like `dhallPackages.buildDhallDirectoryPackage`)
# and read it in as a Nix expression.
#
# This function is similar to `dhallToNix`, but takes a Nixpkgs Dhall package
# as input instead of raw Dhall code.
#
# Note that this uses "import from derivation" (IFD), meaning that Nix will
# perform a build during the evaluation phase if you use this
# `dhallPackageToNix` utility. It is not possible to use `dhallPackageToNix`
# in Nixpkgs, since the Nixpkgs Hydra doesn't allow IFD.
{ stdenv, dhall-nix }:
dhallPackage:
2024-05-13 21:24:10 +00:00
let
drv = stdenv.mkDerivation {
name = "dhall-compiled-package.nix";
2024-05-02 00:46:19 +00:00
2024-05-13 21:24:10 +00:00
buildCommand = ''
# Dhall requires that the cache is writable, even if it is never written to.
# We copy the cache from the input package to the current directory and
# set the cache as writable.
cp -r "${dhallPackage}/.cache" ./
export XDG_CACHE_HOME=$PWD/.cache
chmod -R +w ./.cache
2024-05-02 00:46:19 +00:00
2024-05-13 21:24:10 +00:00
dhall-to-nix <<< "${dhallPackage}/binary.dhall" > $out
'';
2024-05-02 00:46:19 +00:00
2024-05-13 21:24:10 +00:00
nativeBuildInputs = [ dhall-nix ];
};
2024-05-02 00:46:19 +00:00
2024-05-13 21:24:10 +00:00
in import drv