-
-
Notifications
You must be signed in to change notification settings - Fork 13.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dhallPackages.dhallDirectoryToNix: add function to turn a directory of Dhall files into Nix #144076
Conversation
Note that this PR based on #142825 and must be rebased on This PR requires support for the |
4b864a3
to
331e1ff
Compare
d66fa60
to
77c99ee
Compare
generateDhallDirectoryPackage = | ||
callPackage ../development/interpreters/dhall/generate-dhall-directory-package.nix { }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
generateDhallDirectoryPackage = | |
callPackage ../development/interpreters/dhall/generate-dhall-directory-package.nix { }; | |
generateDhallDirectoryPackage = callPackage ../development/interpreters/dhall/generate-dhall-directory-package.nix { }; |
name = "dhall-directory-package.nix"; | ||
|
||
buildCommand = '' | ||
dhall-to-nixpkgs directory --fixed-output-derivations --file "${file}" "${src}" ${if document then "--document" else ""} > $out |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dhall-to-nixpkgs directory --fixed-output-derivations --file "${file}" "${src}" ${if document then "--document" else ""} > $out | |
dhall-to-nixpkgs directory --fixed-output-derivations --file "${file}" "${src}" ${lib.optionalString document "--document"} > $out |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't necessarily feel strongly about either way, but lib.optionalString document "--document"
is actually more characters than if document then "--document" else ""
.
|
||
''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
''; | |
''; |
ec5d75e
to
70458b0
Compare
This PR now contains all the necessary code I'd like to add. It should be able to be reviewed. However, there are two points to watch out for:
In order to work around these two points, I created a Save this in your local Nixpkgs checkout as let
overlay = final: prev: {
# dhall-nixpkgs needs to be overridden because the other attributes
# in this PR require the `dhall-nixpkgs directory --fixed-output-derivation`
# flag.
dhall-nixpkgs = final.haskell.lib.justStaticExecutables (
final.haskell.lib.overrideCabal final.haskellPackages.dhall-nixpkgs (oldAttrs: {
src = final.stdenv.mkDerivation {
name = "dhall-nixpkgs-src";
src = final.fetchurl {
# This is the latest commit from
# https://github.com/dhall-lang/dhall-haskell/pull/2326 as of
# 2021-11-08.
url = "https://github.com/dhall-lang/dhall-haskell/archive/3d56794eef338962d623b55521a427cc58de88bb.tar.gz";
sha256 = "sha256-0E6+bQV6hShHL3JmtjvSo4rGmpUFm00Jmr66csJ4bGA=";
};
# This derivation is a hacky way to get only the `dhall-nixpkgs/`
# directory from the above archive. I imagine there is probably
# a better way to do this...
installPhase = ''
cp -r ./dhall-nixpkgs $out/
'';
};
# some new libs have been added in this PR
editedCabalFile = null;
executableHaskellDepends = oldAttrs.executableHaskellDepends ++ [ final.haskellPackages.memory ];
})
);
# This is just a repo of Dhall files that are used as an example
# in the following attributes.
#
# You may be interested in seeing what the `mydhallfile.dhall`
# file from this Dhall repo evaluates to, since it is used in all
# the following examples:
#
# $ nix-shell -I nixpkgs=./. -p dhall --run 'dhall <<< https://raw.githubusercontent.com/cdepillabout/example-dhall-nix/e6a675c72ecd4dd23d254a02aea8181fe875747f/mydhallfile.dhall'
# ["BILLBILLbillbill", "JANEJANEjanejane", "TESTTESTtesttest", "TESTTESTtesttest", "TESTTESTtesttest"]
myRawDhallRepo = final.fetchFromGitHub {
owner = "cdepillabout";
repo = "example-dhall-nix";
rev = "e6a675c72ecd4dd23d254a02aea8181fe875747f";
sha256 = "sha256-c/EZq76s/+hmLkaeJWKqgh2KrHuJRYI6kWry0E0YQ6s=";
};
# This tests that `dhallPackages.generateDhallDirectoryPackage` is working.
# This is actually the same as `tests.dhall.generateDhallDirectoryPackage`,
# but it has been redefined here to make it easier to work with, and to make
# this file more understandable.
#
# Note that `dhallPackages.generateDhallDirectoryPackage` produces a Nix file
# that calls `dhallPackages.buildDhallDirectoryPackage` on
# `myRawDhallRepo`.
#
# You can verify the produced Nix file with the following commands:
#
# $ nix-build ./test.nix -A myGeneratedTestDhallPackage
# $ cat ./result
myGeneratedTestDhallPackage = final.dhallPackages.generateDhallDirectoryPackage {
src = final.myRawDhallRepo;
file = "mydhallfile.dhall";
};
# This just builds the Nix file produced from `myGeneratedTestDhallPackage`.
#
# Building `myGeneratedTestDhallPackage` produces a standard Nixpkgs Dhall
# package (so it just contains a `binary.dhall` file and `.cache/`
# directory).
#
# You can confirm this with the following command:
#
# $ nix-build ./test.nix -A myTestDhallPackage
# $ ls ./result/
myTestDhallPackage = final.dhallPackages.callPackage final.myGeneratedTestDhallPackage {};
# This tests the `dhallPackageToNix` function added in this PR.
# `dhallPackageToNix` converts a Nixpkgs Dhall package into Nix
# code.
#
# You can confirm this with the following command (using nix-2.4):
#
# $ nix eval -f ./test.nix myTestNixDhallPackage
# [ "BILLBILLbillbill" "JANEJANEjanejane" "TESTTESTtesttest" "TESTTESTtesttest" "TESTTESTtesttest" ]
myTestNixDhallPackage = final.dhallPackageToNix final.myTestDhallPackage;
# This tests the `dhallDirectoryToNix` that was added in this PR.
# `dhallDirectoryToNix` is similar to `dhallPackageToNix`, but takes
# a directory of Dhall files as input, instead of a fully-built
# Nixpkgs Dhall package.
#
# `dhallDirectoryToNix` is effectively a small wrapper around
# `dhallPackages.generateDhallDirectoryPackage` and `dhallPackageToNix.
#
# You can confirm this works with the following command (using nix-2.4):
#
# $ nix eval -f ./test.nix myTestNixDhallDirectoryPackage
# [ "BILLBILLbillbill" "JANEJANEjanejane" "TESTTESTtesttest" "TESTTESTtesttest" "TESTTESTtesttest" ]
myTestNixDhallDirectoryPackage = final.dhallDirectoryToNix {
src = final.myRawDhallRepo;
file = "mydhallfile.dhall";
};
};
in
import ./. { overlays = [ overlay ]; } Test the $ nix-build ./test.nix -A tests.dhall.generateDhallDirectoryPackage
$ cat ./result Test that building this Nix Dhall Package actually works: $ nix-build ./test.nix -A myTestDhallPackage
$ ls ./result/ Test that the $ nix eval -f ./test.nix myTestNixDhallPackage
[ "BILLBILLbillbill" "JANEJANEjanejane" "TESTTESTtesttest" "TESTTESTtesttest" "TESTTESTtesttest" ] Test that the $ nix eval -f ./test.nix myTestNixDhallDirectoryPackage
[ "BILLBILLbillbill" "JANEJANEjanejane" "TESTTESTtesttest" "TESTTESTtesttest" "TESTTESTtesttest" ] See the comments in the above |
70458b0
to
8980b58
Compare
@Gabriel439 This PR should be ready for review, but it uses |
Gabriella recently released That version of |
Why not merge into |
@sternenseemann I'm not in a huge rush to get this in, and I'd definitely like a review by Gabriella before merging it in. I could retarget this on |
8980b58
to
69bbd81
Compare
@ofborg build dhall-nixpkgs I've rebased this on |
I wrote a blog post about this Thought you might be interested @Gabriel439. |
Thanks for writing that up! I scheduled a tweet tomorrow to mention it |
Motivation for this change
This is a continuation of #142825 and adds functionality for easily turning a directory of Dhall files into Nix (as long as all remote imports have integrity checks).
Things done
sandbox = true
set innix.conf
? (See Nix manual)nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
./result/bin/
)