dhallPackageToNix: function for turning Nixpkgs Dhall package into Nix code

This commit is contained in:
(cdep)illabout 2021-11-08 15:39:38 +09:00
parent cfb2fd768e
commit 599e3c2e83
2 changed files with 38 additions and 0 deletions

View File

@ -0,0 +1,36 @@
# `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:
let
drv = stdenv.mkDerivation {
name = "dhall-compiled-package.nix";
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
dhall-to-nix <<< "${dhallPackage}/binary.dhall" > $out
'';
nativeBuildInputs = [ dhall-nix ];
};
in
import drv

View File

@ -301,6 +301,8 @@ with pkgs;
crow-translate = libsForQt5.callPackage ../applications/misc/crow-translate { };
dhallPackageToNix = callPackage ../build-support/dhall/package-to-nix.nix { };
dhallToNix = callPackage ../build-support/dhall/to-nix.nix { };
deadcode = callPackage ../development/tools/deadcode { };