2020-05-15 21:57:56 +00:00
|
|
|
# Builder for Agda packages.
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2020-05-15 21:57:56 +00:00
|
|
|
{ stdenv, lib, self, Agda, runCommandNoCC, makeWrapper, writeText, mkShell, ghcWithPackages }:
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2020-05-15 21:57:56 +00:00
|
|
|
with lib.strings;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
let
|
2020-05-15 21:57:56 +00:00
|
|
|
withPackages' = {
|
|
|
|
pkgs,
|
2021-02-05 17:12:51 +00:00
|
|
|
ghc ? ghcWithPackages (p: with p; [ ieee754 ])
|
2020-05-15 21:57:56 +00:00
|
|
|
}: let
|
|
|
|
pkgs' = if builtins.isList pkgs then pkgs else pkgs self;
|
|
|
|
library-file = writeText "libraries" ''
|
|
|
|
${(concatMapStringsSep "\n" (p: "${p}/${p.libraryFile}") pkgs')}
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
2020-05-15 21:57:56 +00:00
|
|
|
pname = "agdaWithPackages";
|
|
|
|
version = Agda.version;
|
|
|
|
in runCommandNoCC "${pname}-${version}" {
|
|
|
|
inherit pname version;
|
|
|
|
nativeBuildInputs = [ makeWrapper ];
|
|
|
|
passthru.unwrapped = Agda;
|
|
|
|
} ''
|
|
|
|
mkdir -p $out/bin
|
|
|
|
makeWrapper ${Agda}/bin/agda $out/bin/agda \
|
|
|
|
--add-flags "--with-compiler=${ghc}/bin/ghc" \
|
|
|
|
--add-flags "--library-file=${library-file}" \
|
|
|
|
--add-flags "--local-interfaces"
|
|
|
|
makeWrapper ${Agda}/bin/agda-mode $out/bin/agda-mode
|
|
|
|
''; # Local interfaces has been added for now: See https://github.com/agda/agda/issues/4526
|
|
|
|
|
|
|
|
withPackages = arg: if builtins.isAttrs arg then withPackages' arg else withPackages' { pkgs = arg; };
|
|
|
|
|
2020-06-18 07:06:33 +00:00
|
|
|
extensions = [
|
|
|
|
"agda"
|
|
|
|
"agda-lib"
|
|
|
|
"agdai"
|
|
|
|
"lagda"
|
|
|
|
"lagda.md"
|
|
|
|
"lagda.org"
|
|
|
|
"lagda.rst"
|
|
|
|
"lagda.tex"
|
|
|
|
];
|
2020-05-15 21:57:56 +00:00
|
|
|
|
|
|
|
defaults =
|
|
|
|
{ pname
|
|
|
|
, buildInputs ? []
|
|
|
|
, everythingFile ? "./Everything.agda"
|
|
|
|
, libraryName ? pname
|
|
|
|
, libraryFile ? "${libraryName}.agda-lib"
|
|
|
|
, buildPhase ? null
|
|
|
|
, installPhase ? null
|
2020-06-18 07:06:33 +00:00
|
|
|
, extraExtensions ? []
|
2020-05-15 21:57:56 +00:00
|
|
|
, ...
|
|
|
|
}: let
|
|
|
|
agdaWithArgs = withPackages (builtins.filter (p: p ? isAgdaDerivation) buildInputs);
|
|
|
|
in
|
|
|
|
{
|
|
|
|
inherit libraryName libraryFile;
|
|
|
|
|
|
|
|
isAgdaDerivation = true;
|
|
|
|
|
|
|
|
buildInputs = buildInputs ++ [ agdaWithArgs ];
|
|
|
|
|
|
|
|
buildPhase = if buildPhase != null then buildPhase else ''
|
|
|
|
runHook preBuild
|
|
|
|
agda -i ${dirOf everythingFile} ${everythingFile}
|
|
|
|
runHook postBuild
|
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = if installPhase != null then installPhase else ''
|
|
|
|
runHook preInstall
|
|
|
|
mkdir -p $out
|
2021-02-05 17:12:51 +00:00
|
|
|
find -not \( -path ${everythingFile} -or -path ${lib.interfaceFile everythingFile} \) -and \( ${concatMapStringsSep " -or " (p: "-name '*.${p}'") (extensions ++ extraExtensions)} \) -exec cp -p --parents -t "$out" {} +
|
2020-05-15 21:57:56 +00:00
|
|
|
runHook postInstall
|
|
|
|
'';
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
in
|
2020-05-15 21:57:56 +00:00
|
|
|
{
|
|
|
|
mkDerivation = args: stdenv.mkDerivation (args // defaults args);
|
|
|
|
|
|
|
|
inherit withPackages withPackages';
|
2020-04-24 23:36:52 +00:00
|
|
|
}
|