Nixpkgs support for dhall-to-nixpkgs

The motivation for this change is to enable a new Dhall command-line
utility called `dhall-to-nixpkgs` which converts Dhall packages to
buildable Nix packages.  You can think of `dhall-to-nixpkgs` as the
Dhall analog of `cabal2nix`.

You can find the matching pull request for `dhall-to-nixpkgs` here:

https://github.com/dhall-lang/dhall-haskell/pull/1826

The two main changes required to support `dhall-to-nixpkgs` are:

* Two new `buildDhall{Directory,GitHub}Package` utilities are added

  `dhall-to-nixpkgs` uses these in the generated output

* `pkgs.dhallPackages` now selects a default version for each package
  using the `prefer` utility

  All other versions are still buildable via a `passthru` attribute
This commit is contained in:
Gabriel Gonzalez 2020-05-09 19:16:06 -07:00 committed by Profpatsch
parent 2ee84ca8e2
commit 459cf94991
6 changed files with 130 additions and 72 deletions

View File

@ -1,27 +1,18 @@
{ buildDhallPackage, fetchFromGitHub, lib }: { buildDhallGitHubPackage, lib }:
let let
makePrelude = makePrelude =
version: version: { rev, sha256 }:
lib.makeOverridable buildDhallGitHubPackage {
( { rev, sha256, file ? "package.dhall" }:
buildDhallPackage {
name = "Prelude-${version}"; name = "Prelude-${version}";
code =
let
src = fetchFromGitHub {
owner = "dhall-lang"; owner = "dhall-lang";
repo = "dhall-lang"; repo = "dhall-lang";
directory = "Prelude";
file = "package.dhall";
inherit rev sha256; inherit rev sha256;
}; };
in
"${src}/Prelude/${file}";
}
);
in in
lib.mapAttrs makePrelude { lib.mapAttrs makePrelude {
# Prelude versions older than 7.0.0 use old-style union literals, which are # Prelude versions older than 7.0.0 use old-style union literals, which are

View File

@ -1,30 +1,17 @@
{ buildDhallPackage, fetchFromGitHub, lib }: { buildDhallGitHubPackage, lib }:
let let
makeDhallKubernetes = makeDhallKubernetes =
version: version: { rev, sha256 }:
lib.makeOverridable buildDhallGitHubPackage {
( { rev
, sha256
, file ? "package.dhall"
}:
buildDhallPackage {
name = "dhall-kubernetes-${version}"; name = "dhall-kubernetes-${version}";
code =
let
src = fetchFromGitHub {
owner = "dhall-lang"; owner = "dhall-lang";
repo = "dhall-kubernetes"; repo = "dhall-kubernetes";
file = "package.dhall";
inherit rev sha256; inherit rev sha256;
}; };
in
"${src}/${file}";
}
);
in in
lib.mapAttrs makeDhallKubernetes { lib.mapAttrs makeDhallKubernetes {
# 2.1.0 was the first version to introduce a top-level `package.dhall` file # 2.1.0 was the first version to introduce a top-level `package.dhall` file

View File

@ -1,47 +1,32 @@
{ buildDhallPackage, dhall-kubernetes, fetchFromGitHub, lib, Prelude }: { buildDhallGitHubPackage, dhall-kubernetes, lib, Prelude }:
let let
makeDhallPackages = makeDhallPackages =
version: version: { rev, sha256, dependencies }:
lib.makeOverridable buildDhallGitHubPackage {
( { rev
, sha256
, dependencies
}:
buildDhallPackage {
name = "dhall-packages-${version}"; name = "dhall-packages-${version}";
inherit dependencies;
code =
let
src = fetchFromGitHub {
owner = "EarnestResearch"; owner = "EarnestResearch";
repo = "dhall-packages"; repo = "dhall-packages";
file = "package.dhall";
inherit rev sha256; inherit rev sha256 dependencies;
}; };
in
"${src}/package.dhall";
}
);
in in
lib.mapAttrs makeDhallPackages { lib.mapAttrs makeDhallPackages {
"0.11.1" = "0.11.1" =
let let
k8s_6a47bd = dhall-kubernetes."3.0.0".override { k8s_6a47bd = dhall-kubernetes.override {
rev = "6a47bd50c4d3984a13570ea62382a3ad4a9919a4"; rev = "6a47bd50c4d3984a13570ea62382a3ad4a9919a4";
sha256 = "1azqs0x2kia3xw93rfk2mdi8izd7gy9aq6qzbip32gin7dncmfhh"; sha256 = "1azqs0x2kia3xw93rfk2mdi8izd7gy9aq6qzbip32gin7dncmfhh";
}; };
k8s_4ad581 = dhall-kubernetes."3.0.0".override { k8s_4ad581 = dhall-kubernetes.override {
rev = "4ad58156b7fdbbb6da0543d8b314df899feca077"; rev = "4ad58156b7fdbbb6da0543d8b314df899feca077";
sha256 = "12fm70qbhcainxia388svsay2cfg9iksc6mss0nvhgxhpypgp8r0"; sha256 = "12fm70qbhcainxia388svsay2cfg9iksc6mss0nvhgxhpypgp8r0";
}; };
k8s_fee24c = dhall-kubernetes."3.0.0".override { k8s_fee24c = dhall-kubernetes.override {
rev = "fee24c0993ba0b20190e2fdb94e386b7fb67252d"; rev = "fee24c0993ba0b20190e2fdb94e386b7fb67252d";
sha256 = "11d93z8y0jzrb8dl43gqha9z96nxxqkl7cbxpz8hw8ky9x6ggayk"; sha256 = "11d93z8y0jzrb8dl43gqha9z96nxxqkl7cbxpz8hw8ky9x6ggayk";
}; };

View File

@ -0,0 +1,25 @@
{ buildDhallPackage, lib }:
# This is a minor variation on `buildDhallPackage` that splits the `code`
# argument into `src` and `file` in such a way that you can easily override
# the `file`
#
# This function is used by `dhall-to-nixpkgs` when given a directory
lib.makeOverridable
( { # Arguments passed through to `buildDhallPackage`
name
, dependencies ? []
, source ? false
, src
, # The file to import, relative to the root directory
file ? "package.dhall"
}:
buildDhallPackage {
inherit name dependencies source;
code = "${src}/${file}";
}
)

View File

@ -0,0 +1,50 @@
{ buildDhallPackage, fetchFromGitHub, lib }:
# This function is used by `dhall-to-nixpkgs` when given a GitHub repository
lib.makeOverridable
( { # Arguments passed through to `buildDhallPackage`
name
, dependencies ? []
, source ? false
, # The directory containing the Dhall files, if other than the root of the
# repository
directory ? ""
, # The file to import, relative to the above directory
file ? "package.dhall"
# Arguments passed through to `fetchFromGitHub`
, owner
, repo
, rev
# Extra arguments passed through to `fetchFromGitHub`, such as the hash
# or `fetchSubmodules`
, ...
}@args:
buildDhallPackage {
inherit name dependencies source;
code =
let
src = fetchFromGitHub ({
name = "${name}-source";
inherit owner repo rev;
} // removeAttrs args [
"name"
"dependencies"
"source"
"directory"
"file"
"owner"
"repo"
"rev"
]);
prefix = lib.optionalString (directory != "") "${directory}/";
in
"${src}/${prefix}${file}";
}
)

View File

@ -8,20 +8,40 @@ let
let let
callPackage = newScope self; callPackage = newScope self;
prefer = version: path:
let
packages = callPackage path { };
in
packages."${version}".overrideAttrs (_: {
passthru = packages;
}
);
buildDhallPackage = buildDhallPackage =
callPackage ../development/interpreters/dhall/build-dhall-package.nix { }; callPackage ../development/interpreters/dhall/build-dhall-package.nix { };
buildDhallGitHubPackage =
callPackage ../development/interpreters/dhall/build-dhall-github-package.nix { };
buildDhallDirectoryPackage =
callPackage ../development/interpreters/dhall/build-dhall-directory-package.nix { };
in in
{ inherit buildDhallPackage; { inherit
buildDhallPackage
buildDhallGitHubPackage
buildDhallDirectoryPackage
;
dhall-kubernetes = dhall-kubernetes =
callPackage ../development/dhall-modules/dhall-kubernetes.nix { }; prefer "3.0.0" ../development/dhall-modules/dhall-kubernetes.nix;
dhall-packages = dhall-packages =
callPackage ../development/dhall-modules/dhall-packages.nix { }; prefer "0.11.1" ../development/dhall-modules/dhall-packages.nix;
Prelude = Prelude =
callPackage ../development/dhall-modules/Prelude.nix { }; prefer "13.0.0" ../development/dhall-modules/Prelude.nix;
}; };
in in