2019-12-29 12:14:16 +00:00
|
|
|
# Builder for Agda packages.
|
2014-08-31 18:40:11 +01:00
|
|
|
|
2021-08-15 16:12:23 +01:00
|
|
|
{ stdenv, lib, self, Agda, runCommand, makeWrapper, writeText, ghcWithPackages, nixosTests }:
|
2014-08-31 18:40:11 +01:00
|
|
|
|
2019-12-29 12:14:16 +00:00
|
|
|
with lib.strings;
|
2015-05-30 20:30:24 +01:00
|
|
|
|
2014-08-31 18:40:11 +01:00
|
|
|
let
|
2019-12-29 12:14:16 +00:00
|
|
|
withPackages' = {
|
|
|
|
pkgs,
|
2021-01-07 14:55:52 +00:00
|
|
|
ghc ? ghcWithPackages (p: with p; [ ieee754 ])
|
2019-12-29 12:14:16 +00:00
|
|
|
}: let
|
|
|
|
pkgs' = if builtins.isList pkgs then pkgs else pkgs self;
|
|
|
|
library-file = writeText "libraries" ''
|
|
|
|
${(concatMapStringsSep "\n" (p: "${p}/${p.libraryFile}") pkgs')}
|
2015-05-30 20:22:32 +01:00
|
|
|
'';
|
2019-12-29 12:14:16 +00:00
|
|
|
pname = "agdaWithPackages";
|
|
|
|
version = Agda.version;
|
2021-08-15 16:12:23 +01:00
|
|
|
in runCommand "${pname}-${version}" {
|
2019-12-29 12:14:16 +00:00
|
|
|
inherit pname version;
|
|
|
|
nativeBuildInputs = [ makeWrapper ];
|
2021-03-30 13:54:02 +01:00
|
|
|
passthru = {
|
|
|
|
unwrapped = Agda;
|
|
|
|
tests = { inherit (nixosTests) agda; };
|
|
|
|
};
|
2019-12-29 12:14:16 +00:00
|
|
|
} ''
|
|
|
|
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-05-31 11:02:48 +01:00
|
|
|
extensions = [
|
|
|
|
"agda"
|
|
|
|
"agda-lib"
|
|
|
|
"agdai"
|
|
|
|
"lagda"
|
|
|
|
"lagda.md"
|
|
|
|
"lagda.org"
|
|
|
|
"lagda.rst"
|
|
|
|
"lagda.tex"
|
|
|
|
];
|
2019-12-29 12:14:16 +00:00
|
|
|
|
|
|
|
defaults =
|
|
|
|
{ pname
|
2021-07-22 15:28:09 +01:00
|
|
|
, meta
|
2019-12-29 12:14:16 +00:00
|
|
|
, buildInputs ? []
|
|
|
|
, everythingFile ? "./Everything.agda"
|
2021-02-05 13:48:07 +00:00
|
|
|
, includePaths ? []
|
2019-12-29 12:14:16 +00:00
|
|
|
, libraryName ? pname
|
|
|
|
, libraryFile ? "${libraryName}.agda-lib"
|
|
|
|
, buildPhase ? null
|
|
|
|
, installPhase ? null
|
2020-05-31 11:02:48 +01:00
|
|
|
, extraExtensions ? []
|
2019-12-29 12:14:16 +00:00
|
|
|
, ...
|
|
|
|
}: let
|
|
|
|
agdaWithArgs = withPackages (builtins.filter (p: p ? isAgdaDerivation) buildInputs);
|
2021-02-05 13:48:07 +00:00
|
|
|
includePathArgs = concatMapStrings (path: "-i" + path + " ") (includePaths ++ [(dirOf everythingFile)]);
|
2019-12-29 12:14:16 +00:00
|
|
|
in
|
|
|
|
{
|
|
|
|
inherit libraryName libraryFile;
|
|
|
|
|
|
|
|
isAgdaDerivation = true;
|
|
|
|
|
|
|
|
buildInputs = buildInputs ++ [ agdaWithArgs ];
|
|
|
|
|
|
|
|
buildPhase = if buildPhase != null then buildPhase else ''
|
|
|
|
runHook preBuild
|
2021-02-05 13:48:07 +00:00
|
|
|
agda ${includePathArgs} ${everythingFile}
|
2019-12-29 12:14:16 +00:00
|
|
|
runHook postBuild
|
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = if installPhase != null then installPhase else ''
|
|
|
|
runHook preInstall
|
|
|
|
mkdir -p $out
|
2021-01-18 19:01:31 +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" {} +
|
2019-12-29 12:14:16 +00:00
|
|
|
runHook postInstall
|
|
|
|
'';
|
2021-07-22 15:28:09 +01:00
|
|
|
meta = if meta.broken or false then meta // { hydraPlatforms = lib.platforms.none; } else meta;
|
2014-08-31 18:40:11 +01:00
|
|
|
};
|
2015-05-30 20:22:32 +01:00
|
|
|
in
|
2019-12-29 12:14:16 +00:00
|
|
|
{
|
|
|
|
mkDerivation = args: stdenv.mkDerivation (args // defaults args);
|
|
|
|
|
|
|
|
inherit withPackages withPackages';
|
2015-04-05 02:49:07 +01:00
|
|
|
}
|