226299e1a2
The Everthing module is not part of a library and should therefore not be copied to the nix store. This is particularly bad, if the Everything module is defined in an agda library included directory, e.g. consider an agda-lib with include: . and Everything.agda in the project root (.), in which case the Everything module would become part of the library. If multiple such projects are in the dependency tree, the Everything module becomes ambiguous and the build would fail.
83 lines
2.4 KiB
Nix
83 lines
2.4 KiB
Nix
# Builder for Agda packages.
|
|
|
|
{ stdenv, lib, self, Agda, runCommandNoCC, makeWrapper, writeText, mkShell, ghcWithPackages }:
|
|
|
|
with lib.strings;
|
|
|
|
let
|
|
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')}
|
|
'';
|
|
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; };
|
|
|
|
extensions = [
|
|
"agda"
|
|
"agda-lib"
|
|
"agdai"
|
|
"lagda"
|
|
"lagda.md"
|
|
"lagda.org"
|
|
"lagda.rst"
|
|
"lagda.tex"
|
|
];
|
|
|
|
defaults =
|
|
{ pname
|
|
, buildInputs ? []
|
|
, everythingFile ? "./Everything.agda"
|
|
, libraryName ? pname
|
|
, libraryFile ? "${libraryName}.agda-lib"
|
|
, buildPhase ? null
|
|
, installPhase ? null
|
|
, extraExtensions ? []
|
|
, ...
|
|
}: 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 -not \( -path ${everythingFile} -or -path ${lib.interfaceFile everythingFile} \) -and \( ${concatMapStringsSep " -or " (p: "-name '*.${p}'") (extensions ++ extraExtensions)} \) -exec cp -p --parents -t "$out" {} +
|
|
runHook postInstall
|
|
'';
|
|
};
|
|
in
|
|
{
|
|
mkDerivation = args: stdenv.mkDerivation (args // defaults args);
|
|
|
|
inherit withPackages withPackages';
|
|
}
|