2014-08-31 17:40:11 +00:00
|
|
|
# Builder for Agda packages. Mostly inspired by the cabal builder.
|
|
|
|
#
|
|
|
|
# Contact: stdenv.lib.maintainers.fuuzetsu
|
|
|
|
|
|
|
|
{ stdenv, Agda, glibcLocales
|
|
|
|
, writeScriptBin
|
|
|
|
, extension ? (self: super: {})
|
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
|
|
|
optionalString = stdenv.lib.optionalString;
|
|
|
|
filter = stdenv.lib.filter;
|
|
|
|
concatMapStringsSep = stdenv.lib.strings.concatMapStringsSep;
|
|
|
|
concatMapStrings = stdenv.lib.strings.concatMapStrings;
|
|
|
|
unwords = stdenv.lib.strings.concatStringsSep " ";
|
|
|
|
mapInside = xs: unwords (map (x: x + "/*") xs);
|
|
|
|
in
|
|
|
|
{ mkDerivation = args:
|
|
|
|
let
|
|
|
|
postprocess = x: x // {
|
|
|
|
sourceDirectories = filter (y: !(y == null)) x.sourceDirectories;
|
|
|
|
propagatedBuildInputs = filter (y : ! (y == null)) x.propagatedBuildInputs;
|
|
|
|
propagatedUserEnvPkgs = filter (y : ! (y == null)) x.propagatedUserEnvPkgs;
|
|
|
|
everythingFile = if x.everythingFile == "" then "Everything.agda" else x.everythingFile;
|
|
|
|
};
|
|
|
|
|
|
|
|
defaults = self : {
|
|
|
|
# There is no Hackage for Agda so we require src.
|
|
|
|
inherit (self) src name;
|
|
|
|
|
2015-05-18 04:46:48 +00:00
|
|
|
isAgdaPackage = true;
|
|
|
|
|
2014-08-31 17:40:11 +00:00
|
|
|
buildInputs = [ Agda ] ++ self.buildDepends;
|
|
|
|
buildDepends = [];
|
2015-05-18 04:46:48 +00:00
|
|
|
|
|
|
|
buildDependsAgda = filter
|
|
|
|
(dep: dep ? isAgdaPackage && dep.isAgdaPackage)
|
|
|
|
self.buildDepends;
|
|
|
|
buildDependsAgdaShareAgda = map (x: x + "/share/agda") self.buildDependsAgda;
|
|
|
|
|
2014-08-31 17:40:11 +00:00
|
|
|
# Not much choice here ;)
|
|
|
|
LANG = "en_US.UTF-8";
|
|
|
|
LOCALE_ARCHIVE = optionalString stdenv.isLinux "${glibcLocales}/lib/locale/locale-archive";
|
|
|
|
|
|
|
|
everythingFile = "Everything.agda";
|
|
|
|
|
2015-05-18 04:46:48 +00:00
|
|
|
propagatedBuildInputs = self.buildDependsAgda;
|
|
|
|
propagatedUserEnvPkgs = self.buildDependsAgda;
|
2014-08-31 17:40:11 +00:00
|
|
|
|
|
|
|
# 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" ];
|
|
|
|
|
2015-05-18 04:21:50 +00:00
|
|
|
# FIXME: `dirOf self.everythingFile` is what we really want, not hardcoded "./"
|
2015-05-18 04:46:48 +00:00
|
|
|
includeDirs = self.buildDependsAgdaShareAgda
|
|
|
|
++ self.sourceDirectories ++ self.topSourceDirectories
|
|
|
|
++ [ "." ];
|
2015-05-18 04:21:50 +00:00
|
|
|
buildFlags = unwords (map (x: "-i " + x) self.includeDirs);
|
2014-08-31 17:40:11 +00:00
|
|
|
|
2015-05-18 04:50:37 +00:00
|
|
|
agdaWithArgs = "${Agda}/bin/agda ${self.buildFlags}";
|
2014-08-31 17:40:11 +00:00
|
|
|
|
|
|
|
buildPhase = ''
|
2015-05-09 00:58:18 +00:00
|
|
|
runHook preBuild
|
2015-05-18 04:50:37 +00:00
|
|
|
${self.agdaWithArgs} ${self.everythingFile}
|
2015-05-09 00:58:18 +00:00
|
|
|
runHook postBuild
|
2014-08-31 17:40:11 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = ''
|
2015-05-09 00:58:18 +00:00
|
|
|
runHook preInstall
|
2014-08-31 17:40:11 +00:00
|
|
|
mkdir -p $out/share/agda
|
|
|
|
cp -pR ${unwords self.sourceDirectories} ${mapInside self.topSourceDirectories} $out/share/agda
|
2015-05-09 00:58:18 +00:00
|
|
|
runHook postInstall
|
2014-08-31 17:40:11 +00:00
|
|
|
'';
|
2015-05-18 04:50:37 +00:00
|
|
|
|
2015-05-30 15:10:30 +00:00
|
|
|
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;
|
|
|
|
};
|
2015-05-18 04:50:37 +00:00
|
|
|
};
|
2014-08-31 17:40:11 +00:00
|
|
|
};
|
|
|
|
in stdenv.mkDerivation
|
|
|
|
(postprocess (let super = defaults self // args self;
|
|
|
|
self = super // extension self super;
|
|
|
|
in self));
|
2015-04-05 01:49:07 +00:00
|
|
|
}
|