dhall-nix-lib/pkgs/dhall-to-nix-package.nix

45 lines
882 B
Nix
Raw Normal View History

2022-09-14 17:50:13 +00:00
{ dhall, dhall-nix, stdenvNoCC, lndir }:
{ name
# Expressions to add to the cache before interpreting the code
, dependencies ? []
# The root path of the expression
, src
, ...
}:
let
cache = ".cache";
data = ".local/share";
cacheDhall = "${cache}/dhall";
dataDhall = "${data}/dhall";
sourceFile = "source.dhall";
in
stdenvNoCC.mkDerivation {
name = "${name}.nix";
inherit src;
nativeBuildInputs = [lndir dhall dhall-nix];
buildInputs = dependencies;
configurePhase = ''
mkdir -p ${cacheDhall}
for dependency in $buildInputs; do
lndir -silent $dependency/${cacheDhall} ${cacheDhall}
done
export XDG_CACHE_HOME=$PWD/${cache}
'';
buildPhase = ''
cat package.dhall | dhall resolve | dhall normalize > resolved.dhall
'';
installPhase = ''
dhall-to-nix < resolved.dhall > $out
'';
}