summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author(cdep)illabout <cdep.illabout@gmail.com>2021-11-08 15:39:38 +0900
committer(cdep)illabout <cdep.illabout@gmail.com>2021-11-12 14:36:25 +0900
commit0fb3acc2f7c26f5132c60b3e32b72f35891e21c4 (patch)
tree6dbe987cb990a6a27bdacdb33513c10e09a672f9
parenttests.dhall.generateDhallDirectoryPackage: init (diff)
downloadnixpkgs-0fb3acc2f7c26f5132c60b3e32b72f35891e21c4.tar.gz
dhallPackageToNix: function for turning Nixpkgs Dhall package into Nix code
-rw-r--r--pkgs/build-support/dhall/package-to-nix.nix36
-rw-r--r--pkgs/top-level/all-packages.nix2
2 files changed, 38 insertions, 0 deletions
diff --git a/pkgs/build-support/dhall/package-to-nix.nix b/pkgs/build-support/dhall/package-to-nix.nix
new file mode 100644
index 000000000000..301501ad49df
--- /dev/null
+++ b/pkgs/build-support/dhall/package-to-nix.nix
@@ -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
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index d2b1306414cb..9f0b07924166 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -293,6 +293,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 { };