2014-08-31 18:40:11 +01:00
|
|
|
# Builder for Agda packages. Mostly inspired by the cabal builder.
|
|
|
|
#
|
|
|
|
# Contact: stdenv.lib.maintainers.fuuzetsu
|
|
|
|
|
|
|
|
{ stdenv, Agda, glibcLocales
|
|
|
|
, writeScriptBin
|
|
|
|
, extension ? (self: super: {})
|
|
|
|
}:
|
|
|
|
|
2015-05-30 20:30:24 +01:00
|
|
|
with stdenv.lib.strings;
|
|
|
|
|
2014-08-31 18:40:11 +01:00
|
|
|
let
|
2015-05-30 20:22:32 +01:00
|
|
|
defaults = self : {
|
|
|
|
# There is no Hackage for Agda so we require src.
|
|
|
|
inherit (self) src name;
|
|
|
|
|
|
|
|
isAgdaPackage = true;
|
|
|
|
|
|
|
|
buildInputs = [ Agda ] ++ self.buildDepends;
|
|
|
|
buildDepends = [];
|
|
|
|
|
2015-05-30 20:33:20 +01:00
|
|
|
buildDependsAgda = stdenv.lib.filter
|
2015-05-30 20:22:32 +01:00
|
|
|
(dep: dep ? isAgdaPackage && dep.isAgdaPackage)
|
|
|
|
self.buildDepends;
|
|
|
|
buildDependsAgdaShareAgda = map (x: x + "/share/agda") self.buildDependsAgda;
|
|
|
|
|
|
|
|
# Not much choice here ;)
|
|
|
|
LANG = "en_US.UTF-8";
|
2015-05-30 20:33:20 +01:00
|
|
|
LOCALE_ARCHIVE = stdenv.lib.optionalString
|
|
|
|
stdenv.isLinux
|
|
|
|
"${glibcLocales}/lib/locale/locale-archive";
|
2015-05-30 20:22:32 +01:00
|
|
|
|
|
|
|
everythingFile = "Everything.agda";
|
|
|
|
|
|
|
|
propagatedBuildInputs = self.buildDependsAgda;
|
|
|
|
propagatedUserEnvPkgs = self.buildDependsAgda;
|
|
|
|
|
|
|
|
# Immediate source directories under which modules can be found.
|
|
|
|
sourceDirectories = [ ];
|
|
|
|
|
|
|
|
# This is used if we have a top-level element that only serves
|
|
|
|
# as the container for the source and we only care about its
|
|
|
|
# contents. The directories put here will have their
|
|
|
|
# *contents* copied over as opposed to sourceDirectories which
|
|
|
|
# would make a direct copy of the whole thing.
|
|
|
|
topSourceDirectories = [ "src" ];
|
|
|
|
|
|
|
|
# FIXME: `dirOf self.everythingFile` is what we really want, not hardcoded "./"
|
|
|
|
includeDirs = self.buildDependsAgdaShareAgda
|
|
|
|
++ self.sourceDirectories ++ self.topSourceDirectories
|
|
|
|
++ [ "." ];
|
2015-05-30 20:33:20 +01:00
|
|
|
buildFlags = concatStringsSep " " (map (x: "-i " + x) self.includeDirs);
|
2015-05-30 20:22:32 +01:00
|
|
|
|
|
|
|
agdaWithArgs = "${Agda}/bin/agda ${self.buildFlags}";
|
|
|
|
|
|
|
|
buildPhase = ''
|
|
|
|
runHook preBuild
|
|
|
|
${self.agdaWithArgs} ${self.everythingFile}
|
|
|
|
runHook postBuild
|
|
|
|
'';
|
|
|
|
|
2015-05-30 20:33:20 +01:00
|
|
|
installPhase = let
|
|
|
|
srcFiles = self.sourceDirectories
|
|
|
|
++ map (x: x + "/*") self.topSourceDirectories;
|
|
|
|
in ''
|
2015-05-30 20:22:32 +01:00
|
|
|
runHook preInstall
|
|
|
|
mkdir -p $out/share/agda
|
2015-05-30 20:33:20 +01:00
|
|
|
cp -pR ${concatStringsSep " " srcFiles} $out/share/agda
|
2015-05-30 20:22:32 +01:00
|
|
|
runHook postInstall
|
|
|
|
'';
|
|
|
|
|
|
|
|
passthru = {
|
|
|
|
env = stdenv.mkDerivation {
|
|
|
|
name = "interactive-${self.name}";
|
|
|
|
inherit (self) LANG LOCALE_ARCHIVE;
|
|
|
|
AGDA_PACKAGE_PATH = concatMapStrings (x: x + ":") self.buildDependsAgdaShareAgda;
|
|
|
|
buildInputs = let
|
|
|
|
# Makes a wrapper available to the user. Very useful in
|
|
|
|
# nix-shell where all dependencies are -i'd.
|
|
|
|
agdaWrapper = writeScriptBin "agda" ''
|
|
|
|
${self.agdaWithArgs} "$@"
|
|
|
|
'';
|
|
|
|
in [agdaWrapper] ++ self.buildDepends;
|
2014-08-31 18:40:11 +01:00
|
|
|
};
|
2015-05-30 20:22:32 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
in
|
|
|
|
{ mkDerivation = args: let
|
|
|
|
super = defaults self // args self;
|
|
|
|
self = super // extension self super;
|
2015-05-30 20:33:20 +01:00
|
|
|
in stdenv.mkDerivation self;
|
2015-04-05 02:49:07 +01:00
|
|
|
}
|