From f9e038e2356b9652eab27676bd0c1b31d3a6da9e Mon Sep 17 00:00:00 2001 From: "(cdep)illabout" Date: Tue, 2 Nov 2021 15:11:58 +0900 Subject: [PATCH 1/7] dhallToNix: remove explicit argument in callPackage --- pkgs/top-level/all-packages.nix | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 6bf57630a928..0543ac09be1c 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -301,9 +301,7 @@ with pkgs; crow-translate = libsForQt5.callPackage ../applications/misc/crow-translate { }; - dhallToNix = callPackage ../build-support/dhall-to-nix.nix { - inherit dhall-nix; - }; + dhallToNix = callPackage ../build-support/dhall-to-nix.nix { }; deadcode = callPackage ../development/tools/deadcode { }; From 32c93844f5c14cf7135f96b27649dc8e36442866 Mon Sep 17 00:00:00 2001 From: "(cdep)illabout" Date: Tue, 2 Nov 2021 15:50:13 +0900 Subject: [PATCH 2/7] dhallToNix: rename file from build-support/dhall-to-nix.nix to build-support/dhall/to-nix.nix --- pkgs/build-support/{dhall-to-nix.nix => dhall/to-nix.nix} | 0 pkgs/top-level/all-packages.nix | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename pkgs/build-support/{dhall-to-nix.nix => dhall/to-nix.nix} (100%) diff --git a/pkgs/build-support/dhall-to-nix.nix b/pkgs/build-support/dhall/to-nix.nix similarity index 100% rename from pkgs/build-support/dhall-to-nix.nix rename to pkgs/build-support/dhall/to-nix.nix diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 0543ac09be1c..d0d1b6f1a03c 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -301,7 +301,7 @@ with pkgs; crow-translate = libsForQt5.callPackage ../applications/misc/crow-translate { }; - dhallToNix = callPackage ../build-support/dhall-to-nix.nix { }; + dhallToNix = callPackage ../build-support/dhall/to-nix.nix { }; deadcode = callPackage ../development/tools/deadcode { }; From 6e020a08e2045a6393b67dcdc01a78ff8a77b40f Mon Sep 17 00:00:00 2001 From: "(cdep)illabout" Date: Tue, 2 Nov 2021 15:12:21 +0900 Subject: [PATCH 3/7] dhall-nixpkgs: lift to top-level --- pkgs/top-level/all-packages.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index d0d1b6f1a03c..a4b7c07fc2e3 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -13283,6 +13283,8 @@ with pkgs; dhall-nix = haskell.lib.compose.justStaticExecutables haskellPackages.dhall-nix; + dhall-nixpkgs = haskell.lib.compose.justStaticExecutables haskellPackages.dhall-nixpkgs; + dhall-text = haskell.lib.compose.justStaticExecutables haskellPackages.dhall-text; dhallPackages = recurseIntoAttrs (callPackage ./dhall-packages.nix { }); From a1933f6a9d0605cc3de49cd34eec6e47fad0789a Mon Sep 17 00:00:00 2001 From: "(cdep)illabout" Date: Mon, 1 Nov 2021 15:17:28 +0900 Subject: [PATCH 4/7] dhallPackages.generateDhallDirectoryPackage: init --- .../generate-dhall-directory-package.nix | 27 +++++++++++++++++++ pkgs/top-level/dhall-packages.nix | 4 +++ 2 files changed, 31 insertions(+) create mode 100644 pkgs/development/interpreters/dhall/generate-dhall-directory-package.nix diff --git a/pkgs/development/interpreters/dhall/generate-dhall-directory-package.nix b/pkgs/development/interpreters/dhall/generate-dhall-directory-package.nix new file mode 100644 index 000000000000..03dfb72d7aba --- /dev/null +++ b/pkgs/development/interpreters/dhall/generate-dhall-directory-package.nix @@ -0,0 +1,27 @@ +{ dhall-nixpkgs, lib, stdenv }: + +# This function calls `dhall-to-nixpkgs directory --fixed-output-derivations` +# within a Nix derivation. +# +# This is possible because +# `dhall-to-nixpkgs directory --fixed-output-derivations` will turn remote +# Dhall imports protected with Dhall integrity checksinto fixed-output +# derivations (with the `buildDhallUrl` function), so no unrestricted network +# access is necessary. +lib.makePackageOverridable + ( { src + , # The file to import, relative to the root directory + file ? "package.dhall" + , # Set to `true` to generate documentation for the package + document ? false + }: + stdenv.mkDerivation { + name = "dhall-directory-package.nix"; + + buildCommand = '' + dhall-to-nixpkgs directory --fixed-output-derivations --file "${file}" "${src}" ${if document then "--document" else ""} > $out + ''; + + nativeBuildInputs = [ dhall-nixpkgs ]; + } + ) diff --git a/pkgs/top-level/dhall-packages.nix b/pkgs/top-level/dhall-packages.nix index 1910cb372741..646f2b7e9d39 100644 --- a/pkgs/top-level/dhall-packages.nix +++ b/pkgs/top-level/dhall-packages.nix @@ -20,6 +20,9 @@ let buildDhallUrl = callPackage ../development/interpreters/dhall/build-dhall-url.nix { }; + generateDhallDirectoryPackage = + callPackage ../development/interpreters/dhall/generate-dhall-directory-package.nix { }; + in { inherit callPackage @@ -27,6 +30,7 @@ let buildDhallGitHubPackage buildDhallDirectoryPackage buildDhallUrl + generateDhallDirectoryPackage ; lib = import ../development/dhall-modules/lib.nix { inherit lib; }; From cfb2fd768ee71c68312a2fd02dcda10cdb2d43ad Mon Sep 17 00:00:00 2001 From: "(cdep)illabout" Date: Mon, 1 Nov 2021 15:22:10 +0900 Subject: [PATCH 5/7] tests.dhall.generateDhallDirectoryPackage: init --- pkgs/test/dhall/default.nix | 1 + .../generateDhallDirectoryPackage/default.nix | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 pkgs/test/dhall/generateDhallDirectoryPackage/default.nix diff --git a/pkgs/test/dhall/default.nix b/pkgs/test/dhall/default.nix index bdb33acf0238..4c7eba6c9579 100644 --- a/pkgs/test/dhall/default.nix +++ b/pkgs/test/dhall/default.nix @@ -2,4 +2,5 @@ lib.recurseIntoAttrs { buildDhallUrl = callPackage ./buildDhallUrl { }; + generateDhallDirectoryPackage = callPackage ./generateDhallDirectoryPackage { }; } diff --git a/pkgs/test/dhall/generateDhallDirectoryPackage/default.nix b/pkgs/test/dhall/generateDhallDirectoryPackage/default.nix new file mode 100644 index 000000000000..4771e1629806 --- /dev/null +++ b/pkgs/test/dhall/generateDhallDirectoryPackage/default.nix @@ -0,0 +1,17 @@ +{ dhallPackages, fetchFromGitHub }: + +# This file tests that dhallPackages.generateDhallDirectoryPackage works. +# +# TODO: It would be nice to extend this test to make sure that the resulting +# Nix file has the expected contents, but it might be tough to do that easily +# without IFD. + +dhallPackages.generateDhallDirectoryPackage { + src = fetchFromGitHub { + owner = "cdepillabout"; + repo = "example-dhall-nix"; + rev = "e6a675c72ecd4dd23d254a02aea8181fe875747f"; + sha256 = "sha256-c/EZq76s/+hmLkaeJWKqgh2KrHuJRYI6kWry0E0YQ6s="; + }; + file = "mydhallfile.dhall"; +} From 599e3c2e8370752f84bd985af5b1d36d304768d5 Mon Sep 17 00:00:00 2001 From: "(cdep)illabout" Date: Mon, 8 Nov 2021 15:39:38 +0900 Subject: [PATCH 6/7] dhallPackageToNix: function for turning Nixpkgs Dhall package into Nix code --- pkgs/build-support/dhall/package-to-nix.nix | 36 +++++++++++++++++++++ pkgs/top-level/all-packages.nix | 2 ++ 2 files changed, 38 insertions(+) create mode 100644 pkgs/build-support/dhall/package-to-nix.nix 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 a4b7c07fc2e3..663c40b25eea 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -301,6 +301,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 { }; From 69bbd81c628133ceeed4f1eafaaae3c53215e126 Mon Sep 17 00:00:00 2001 From: "(cdep)illabout" Date: Wed, 10 Nov 2021 15:40:40 +0900 Subject: [PATCH 7/7] dhallDirectoryToNix: add this utility function --- pkgs/build-support/dhall/directory-to-nix.nix | 25 +++++++++++++++++++ pkgs/top-level/all-packages.nix | 2 ++ 2 files changed, 27 insertions(+) create mode 100644 pkgs/build-support/dhall/directory-to-nix.nix diff --git a/pkgs/build-support/dhall/directory-to-nix.nix b/pkgs/build-support/dhall/directory-to-nix.nix new file mode 100644 index 000000000000..d751e19df3fc --- /dev/null +++ b/pkgs/build-support/dhall/directory-to-nix.nix @@ -0,0 +1,25 @@ +{ dhallPackages, dhallPackageToNix}: + +# `dhallDirectoryToNix is a utility function to take a directory of Dhall files +# and read them 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 +# `dhallDirectoryToNix` utility. It is not possible to use +# `dhallDirectoryToNix` in Nixpkgs, since the Nixpkgs Hydra doesn't allow IFD. + +{ src +, # The file to import, relative to the src root directory + file ? "package.dhall" +}@args: + +let + generatedPkg = dhallPackages.generateDhallDirectoryPackage args; + + builtPkg = dhallPackages.callPackage generatedPkg { }; + +in + dhallPackageToNix builtPkg diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 663c40b25eea..33aa4ae76338 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -301,6 +301,8 @@ with pkgs; crow-translate = libsForQt5.callPackage ../applications/misc/crow-translate { }; + dhallDirectoryToNix = callPackage ../build-support/dhall/directory-to-nix.nix { }; + dhallPackageToNix = callPackage ../build-support/dhall/package-to-nix.nix { }; dhallToNix = callPackage ../build-support/dhall/to-nix.nix { };