change the way import-dhall works

This commit is contained in:
Charlotte 🦝 Delenk 2022-09-14 18:50:13 +01:00
parent 067764c4a5
commit feb637855c
Signed by: darkkirb
GPG key ID: AB2BD8DAF2E37122
3 changed files with 46 additions and 19 deletions

View file

@ -1,18 +0,0 @@
{pkgs ? import <nixpkgs> {}}: code: let
codeString = builtins.toString code;
file =
if builtins.isPath code
then code
else builtins.toFile "dhall-expr" codeString;
drv = pkgs.stdenvNoCC.mkDerivation {
name = "dhall-expr-as-nix";
src = ./.;
buildCommand = ''
cd $src
dhall-to-nix < ${file} > $out
'';
nativeBuildInputs = [pkgs.dhall-nix];
};
in
import "${drv}" (import ./runtime.nix pkgs.lib)

View file

@ -33,7 +33,6 @@
devShells.default = pkgs.mkShell {
nativeBuildInputs = [self.packages.${system}.dhall self.packages.${system}.dhall-nix];
};
lib.dhallToNix = import ./dhallToNix.nix {inherit pkgs;};
})
// {
overlays.default = final: prev: {
@ -44,6 +43,8 @@
sha256 = "157x95yw9hibpifa8figawgclnc1d1bapmbp1zw60l2viy936b83";
};
inherit (self.packages.${prev.emptyDirectory.system}) dhall-nix-lib;
dhall-to-nix-package = super.callPackage ./pkgs/dhall-to-nix-package.nix {};
import-dhall-package = path: let drv = super.callPackage (path + "/package.nix") { buildDhallDirectoryPackage = self.dhall-to-nix-package; }; in import "${drv}" (import ./runtime.nix final.lib);
};
});
inherit (self.packages.${prev.system}) dhall dhall-nix dhall-nixpkgs;

View file

@ -0,0 +1,44 @@
{ 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
'';
}