about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/interpreters/dhall
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2020-04-01 15:50:50 +0000
committerAlyssa Ross <hi@alyssa.is>2020-04-01 15:50:50 +0000
commit75eafe97f7df0d653bec67f3962214d7c357831f (patch)
tree09f2cc901e0e637876cbb78d192dfe2fcfef8156 /nixpkgs/pkgs/development/interpreters/dhall
parenta53b121bf4331497da63df3b1b7f1a7897dad146 (diff)
parenta2e06fc3423c4be53181b15c28dfbe0bcf67dd73 (diff)
downloadnixlib-75eafe97f7df0d653bec67f3962214d7c357831f.tar
nixlib-75eafe97f7df0d653bec67f3962214d7c357831f.tar.gz
nixlib-75eafe97f7df0d653bec67f3962214d7c357831f.tar.bz2
nixlib-75eafe97f7df0d653bec67f3962214d7c357831f.tar.lz
nixlib-75eafe97f7df0d653bec67f3962214d7c357831f.tar.xz
nixlib-75eafe97f7df0d653bec67f3962214d7c357831f.tar.zst
nixlib-75eafe97f7df0d653bec67f3962214d7c357831f.zip
Merge commit 'a2e06fc3423c4be53181b15c28dfbe0bcf67dd73'
Diffstat (limited to 'nixpkgs/pkgs/development/interpreters/dhall')
-rw-r--r--nixpkgs/pkgs/development/interpreters/dhall/build-dhall-package.nix83
-rw-r--r--nixpkgs/pkgs/development/interpreters/dhall/default.nix18
2 files changed, 83 insertions, 18 deletions
diff --git a/nixpkgs/pkgs/development/interpreters/dhall/build-dhall-package.nix b/nixpkgs/pkgs/development/interpreters/dhall/build-dhall-package.nix
new file mode 100644
index 000000000000..739dc9b3d52e
--- /dev/null
+++ b/nixpkgs/pkgs/development/interpreters/dhall/build-dhall-package.nix
@@ -0,0 +1,83 @@
+{ haskell, haskellPackages, lib, lndir, runCommand, writeText }:
+
+{ name
+
+  # Expressions to add to the cache before interpreting the code
+, dependencies ? []
+
+  # A Dhall expression
+  #
+  # Carefully note that the following expression must be devoid of uncached HTTP
+  # imports.  This is because the expression will be evaluated using an
+  # interpreter with HTTP support disabled, so all HTTP imports have to be
+  # protected by an integrity check that can be satisfied via cached
+  # dependencies.
+  #
+  # You can add a dependency to the cache using the preceding `dependencies`
+  # option
+, code
+
+  # `buildDhallPackage` can include both a "source distribution" in
+  # `source.dhall` and a "binary distribution" in `binary.dhall`:
+  #
+  # * `source.dhall` is a dependency-free αβ-normalized Dhall expression
+  #
+  # * `binary.dhall` is an expression of the form: `missing sha256:${HASH}`
+  #
+  #   This expression requires you to install the cache product located at
+  #   `.cache/dhall/1220${HASH}` to successfully resolve
+  #
+  # By default, `buildDhallPackage` only includes "binary.dhall" to conserve
+  # space within the Nix store, but if you set the following `source` option to
+  # `true` then the package will also include `source.dhall`.
+, source ? false
+}:
+
+let
+  # `buildDhallPackage` requires version 1.25.0 or newer of the Haskell
+  # interpreter for Dhall.  Given that the default version is 1.24.0 we choose
+  # the latest available version instead until the default is upgraded.
+  #
+  # HTTP support is disabled in order to force that HTTP dependencies are built
+  # using Nix instead of using Dhall's support for HTTP imports.
+  dhall =
+    haskell.lib.justStaticExecutables
+      (haskell.lib.appendConfigureFlag
+        haskellPackages.dhall_1_29_0
+        "-f-with-http"
+      );
+
+  file = writeText "${name}.dhall" code;
+
+  cache = ".cache";
+
+  cacheDhall = "${cache}/dhall";
+
+  sourceFile = "source.dhall";
+
+in
+  runCommand name { inherit dependencies; } ''
+    set -eu
+
+    mkdir -p ${cacheDhall}
+
+    for dependency in $dependencies; do
+      ${lndir}/bin/lndir -silent $dependency/${cacheDhall} ${cacheDhall}
+    done
+
+    export XDG_CACHE_HOME=$PWD/${cache}
+
+    mkdir -p $out/${cacheDhall}
+
+    ${dhall}/bin/dhall --alpha --file '${file}' > $out/${sourceFile}
+
+    SHA_HASH=$(${dhall}/bin/dhall hash <<< $out/${sourceFile})
+
+    HASH_FILE="''${SHA_HASH/sha256:/1220}"
+
+    ${dhall}/bin/dhall encode --file $out/${sourceFile} > $out/${cacheDhall}/$HASH_FILE
+
+    echo "missing $SHA_HASH" > $out/binary.dhall
+
+    ${lib.optionalString (!source) "rm $out/${sourceFile}"}
+  ''
diff --git a/nixpkgs/pkgs/development/interpreters/dhall/default.nix b/nixpkgs/pkgs/development/interpreters/dhall/default.nix
deleted file mode 100644
index 8e1df36e4127..000000000000
--- a/nixpkgs/pkgs/development/interpreters/dhall/default.nix
+++ /dev/null
@@ -1,18 +0,0 @@
-{ haskell, haskellPackages, stdenvNoCC }:
-
-let
-  static = haskell.lib.justStaticExecutables haskellPackages.dhall;
-
-in static.overrideAttrs (old: {
-  passthru = old.passthru or {} // {
-    prelude = stdenvNoCC.mkDerivation {
-      name = "dhall-prelude";
-      inherit (old) src;
-      phases = [ "unpackPhase" "installPhase" ];
-      installPhase = ''
-        mkdir $out
-        cp -r Prelude/* $out/
-      '';
-    };
-  };
-})