Merge pull request #22193 from Gabriel439/gabriel/dhallToNix
Add a `pkgs.dhallToNix` utility
This commit is contained in:
commit
da1cd49747
38
pkgs/build-support/dhall-to-nix.nix
Normal file
38
pkgs/build-support/dhall-to-nix.nix
Normal file
@ -0,0 +1,38 @@
|
||||
/* `dhallToNix` is a utility function to convert expressions in the Dhall
|
||||
configuration language to their corresponding Nix expressions.
|
||||
|
||||
Example:
|
||||
dhallToNix "{ foo = 1, bar = True }"
|
||||
=> { foo = 1; bar = true; }
|
||||
dhallToNix "λ(x : Bool) → x == False"
|
||||
=> x : x == false
|
||||
dhallToNix "λ(x : Bool) → x == False" false
|
||||
=> true
|
||||
|
||||
See https://hackage.haskell.org/package/dhall-nix/docs/Dhall-Nix.html for
|
||||
a longer tutorial
|
||||
|
||||
Note that this uses "import from derivation", meaning that Nix will perform
|
||||
a build during the evaluation phase if you use this `dhallToNix` utility
|
||||
*/
|
||||
{ stdenv, dhall-nix }:
|
||||
|
||||
let
|
||||
dhallToNix = code :
|
||||
let
|
||||
file = builtins.toFile "dhall-expression" code;
|
||||
|
||||
drv = stdenv.mkDerivation {
|
||||
name = "dhall-compiled.nix";
|
||||
|
||||
buildCommand = ''
|
||||
dhall-to-nix <<< "${file}" > $out
|
||||
'';
|
||||
|
||||
buildInputs = [ dhall-nix ];
|
||||
};
|
||||
|
||||
in
|
||||
import "${drv}";
|
||||
in
|
||||
dhallToNix
|
@ -91,6 +91,10 @@ with pkgs;
|
||||
|
||||
cmark = callPackage ../development/libraries/cmark { };
|
||||
|
||||
dhallToNix = callPackage ../build-support/dhall-to-nix.nix {
|
||||
inherit (haskellPackages) dhall-nix;
|
||||
};
|
||||
|
||||
dockerTools = callPackage ../build-support/docker { };
|
||||
|
||||
dotnetenv = callPackage ../build-support/dotnetenv {
|
||||
|
Loading…
x
Reference in New Issue
Block a user