nixpkgs-suyu/pkgs/build-support/agda/default.nix

72 lines
2.1 KiB
Nix
Raw Normal View History

2019-12-29 13:14:16 +01:00
# Builder for Agda packages.
2014-08-31 19:40:11 +02:00
2019-12-29 13:14:16 +01:00
{ stdenv, lib, self, Agda, runCommandNoCC, makeWrapper, writeText, mkShell, ghcWithPackages }:
2014-08-31 19:40:11 +02:00
2019-12-29 13:14:16 +01:00
with lib.strings;
2014-08-31 19:40:11 +02:00
let
2019-12-29 13:14:16 +01:00
withPackages' = {
pkgs,
ghc ? ghcWithPackages (p: with p; [ ieee ])
}: let
pkgs' = if builtins.isList pkgs then pkgs else pkgs self;
library-file = writeText "libraries" ''
${(concatMapStringsSep "\n" (p: "${p}/${p.libraryFile}") pkgs')}
'';
2019-12-29 13:14:16 +01: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; };
defaults =
{ pname
, buildInputs ? []
, everythingFile ? "./Everything.agda"
, libraryName ? pname
, libraryFile ? "${libraryName}.agda-lib"
, buildPhase ? null
, installPhase ? null
, ...
}: 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
find \( -name '*.agda' -or -name '*.agdai' -or -name '*.agda-lib' \) -exec cp -p --parents -t "$out" {} +
runHook postInstall
'';
2014-08-31 19:40:11 +02:00
};
in
2019-12-29 13:14:16 +01:00
{
mkDerivation = args: stdenv.mkDerivation (args // defaults args);
inherit withPackages withPackages';
}