nixpkgs/pkgs/development/dhall-modules/dhall-packages.nix

72 lines
2.1 KiB
Nix
Raw Normal View History

Add Nixpkgs support for Dhall One of the motivations for this change is the following Discourse discussion: https://discourse.dhall-lang.org/t/offline-use-of-prelude/137 Many users have requested Dhall support for "offline" packages that can be fetched/built/installed using ordinary package management tools (like Nix) instead of using Dhall's HTTP import system. I will continue to use the term "offline" to mean Dhall package builds that do not use Dhall's language support for HTTP imports (and instead use the package manager's support for HTTP requests, such as `pkgs.fetchFromGitHub`) The goal of this change is to document what is the idiomatic way to implement "offline" Dhall builds by implementing Nixpkgs support for such builds. That way when other package management tools ask me how to package Dhall with their tools I can refer them to how it is done in Nixpkgs. This change contains a fully "offline" build for the largest Dhall package in existence, known as "dhall-packages" (not to be confused with `dhallPackages`, which is our Nix attribute set containing Dhall packages). The trick to implementing offline builds in Dhall is to take advantage of Dhall's support for semantic integrity checks. If an HTTP import is protected by an integrity check and a cached build product matches the integrity check then the HTTP import is never resolved and the expression is instead fetched from cache. By "installing" dependencies in a pre-seeded and isolated cache we can replace remote HTTP imports with dependencies that have been built and supplied by Nix instead. The offline nature of the builds are enforced by compiling the Haskell interpreter with the `-f-with-http` flag, which disables the interpreter's support for HTTP imports. If a user forgets to supply a necessary dependency as a Nix build product then the build fails informing them that HTTP imports are disabled. By default, built packages are "binary distributions", containing just a cache product and a Dhall expression which can be used to resolve the corresponding cache product. Users can also optionally enable a "source distribution" of a package which already includes the equivalent fully-evaluated Dhall code (for convenience), but this is disabled by default to keep `/nix/store` utilization as compact as possible.
2020-02-12 06:02:53 +00:00
{ buildDhallPackage, dhall-kubernetes, fetchFromGitHub, lib, Prelude }:
let
makeDhallPackages =
version:
lib.makeOverridable
( { rev
, sha256
, dependencies
}:
buildDhallPackage {
name = "dhall-packages-${version}";
inherit dependencies;
code =
let
src = fetchFromGitHub {
owner = "EarnestResearch";
repo = "dhall-packages";
inherit rev sha256;
};
in
"${src}/package.dhall";
}
);
in
lib.mapAttrs makeDhallPackages {
"0.11.1" =
let
k8s_6a47bd = dhall-kubernetes."3.0.0".override {
rev = "6a47bd50c4d3984a13570ea62382a3ad4a9919a4";
sha256 = "1azqs0x2kia3xw93rfk2mdi8izd7gy9aq6qzbip32gin7dncmfhh";
};
k8s_4ad581 = dhall-kubernetes."3.0.0".override {
rev = "4ad58156b7fdbbb6da0543d8b314df899feca077";
sha256 = "12fm70qbhcainxia388svsay2cfg9iksc6mss0nvhgxhpypgp8r0";
};
k8s_fee24c = dhall-kubernetes."3.0.0".override {
rev = "fee24c0993ba0b20190e2fdb94e386b7fb67252d";
sha256 = "11d93z8y0jzrb8dl43gqha9z96nxxqkl7cbxpz8hw8ky9x6ggayk";
};
in
{ rev = "8d228f578fbc7bb16c04a7c9ac8c6c7d2e13d1f7";
sha256 = "1v4y1x13lxy6cxf8xqc6sb0mc4mrd4frkxih95v9q2wxw4vkw2h7";
dependencies = [
(k8s_6a47bd.override { kubernetesVersion = "1.14"; })
(k8s_6a47bd.override { kubernetesVersion = "1.15"; })
(k8s_6a47bd.override { kubernetesVersion = "1.16"; })
(k8s_4ad581.override { file = "types.dhall"; })
(k8s_fee24c.override { file = "types/io.k8s.api.core.v1.ServiceSpec.dhall"; })
(k8s_fee24c.override { file = "types/io.k8s.api.core.v1.PodTemplateSpec.dhall"; })
Prelude."12.0.0"
(Prelude."12.0.0".override { file = "JSON/package.dhall"; })
(Prelude."12.0.0".override { file = "JSON/Type"; })
(Prelude."12.0.0".override { file = "Map/Type"; })
];
};
}