Skip to content

Instantly share code, notes, and snippets.

@cdepillabout
Created September 14, 2021 06:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdepillabout/9178e32d070ab62814f68299519a6870 to your computer and use it in GitHub Desktop.
Save cdepillabout/9178e32d070ab62814f68299519a6870 to your computer and use it in GitHub Desktop.
demonstrate how to fetch URL imports in Dhall by turning the integrity checks into Nix fixed-output-derivations
with import <nixpkgs> {};
let
packageSet = fetchurl {
url = "https://github.com/purescript/package-sets/releases/download/psc-0.14.4-20210905/packages.dhall";
# The hash below is a base64-encoded version of the base-16 hash that is
# specified in our local packages.dhall file:
# ```
# $ cat packages.dhall
# let upstream =
# https://github.com/purescript/package-sets/releases/download/psc-0.14.4-20210905/packages.dhall sha256:140f3630801f2b02d5f3a405d4872e0af317e4ef187016a6b00f97d59d6275c6
# in upstream
# ```
#
# So sha256-FA82MIAfKwLV86QF1IcuCvMX5O8YcBamsA+X1Z1idcY= is the base64-encoded version of
# 140f3630801f2b02d5f3a405d4872e0af317e4ef187016a6b00f97d59d6275c6 (which is base16-encoded).
# This proves that we can turn URL references in dhall into a FOD in
# Nix (as long as the URL references has an integrity check).
hash = "sha256-FA82MIAfKwLV86QF1IcuCvMX5O8YcBamsA+X1Z1idcY=";
downloadToTemp = true;
postFetch = ''
${dhall}/bin/dhall encode --file "$downloadedFile" > $out
'';
};
decodedPackageSet = runCommand "decodedPackageSet" {} ''
${dhall}/bin/dhall decode --file "${packageSet}" > $out
'';
in
dhallToNix (builtins.readFile decodedPackageSet)
@cdepillabout
Copy link
Author

This Nix file demonstrates how Dhall URLs with integrity checks can be turned into Nix fixed-output derivations (FODs).

This Nix file can be evaluated like the following:

$ nix eval --file ./fetch-dhall-as-binary.nix
{ abides = { dependencies = [ "enums" "foldable-traversable" ]; repo = "https://github.com/athanclark/purescript-abides.git"; version = "v0.0.1"; }; ace = { dependencies = [ "arrays" "effect" "foreign" "nullable" "prelude" "web-html" "web-uievents" ]; repo = "https://github.com/purescript-contrib/purescript-ace.git"; version = "v8.0.0"; }; aff = { dependencies = [ "datetime" "effect" "exceptions" "functions" "parallel" "transformers" "unsafe-coerce" ]; repo = "https://github.com/purescript-contrib/purescript-aff.git"; version = "v6.0.0"; }; ...

<nixpkgs> is currently pointing to 21.05.2549.a1007637cea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment