Merge pull request #8077 from Ericson2314/agda

Interactive `env` for developing Agda packages, and misc cleanup
This commit is contained in:
Mateusz Kowalczyk 2015-06-08 14:57:38 +01:00
commit 9bb5c2c488

View File

@ -7,26 +7,9 @@
, extension ? (self: super: {}) , extension ? (self: super: {})
}: }:
with stdenv.lib.strings;
let 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;
passthru = { inherit (x) extras; };
extras = null;
};
defaults = self : { defaults = self : {
# There is no Hackage for Agda so we require src. # There is no Hackage for Agda so we require src.
inherit (self) src name; inherit (self) src name;
@ -36,14 +19,16 @@ in
buildInputs = [ Agda ] ++ self.buildDepends; buildInputs = [ Agda ] ++ self.buildDepends;
buildDepends = []; buildDepends = [];
buildDependsAgda = filter buildDependsAgda = stdenv.lib.filter
(dep: dep ? isAgdaPackage && dep.isAgdaPackage) (dep: dep ? isAgdaPackage && dep.isAgdaPackage)
self.buildDepends; self.buildDepends;
buildDependsAgdaShareAgda = map (x: x + "/share/agda") self.buildDependsAgda; buildDependsAgdaShareAgda = map (x: x + "/share/agda") self.buildDependsAgda;
# Not much choice here ;) # Not much choice here ;)
LANG = "en_US.UTF-8"; LANG = "en_US.UTF-8";
LOCALE_ARCHIVE = optionalString stdenv.isLinux "${glibcLocales}/lib/locale/locale-archive"; LOCALE_ARCHIVE = stdenv.lib.optionalString
stdenv.isLinux
"${glibcLocales}/lib/locale/locale-archive";
everythingFile = "Everything.agda"; everythingFile = "Everything.agda";
@ -64,7 +49,7 @@ in
includeDirs = self.buildDependsAgdaShareAgda includeDirs = self.buildDependsAgdaShareAgda
++ self.sourceDirectories ++ self.topSourceDirectories ++ self.sourceDirectories ++ self.topSourceDirectories
++ [ "." ]; ++ [ "." ];
buildFlags = unwords (map (x: "-i " + x) self.includeDirs); buildFlags = concatStringsSep " " (map (x: "-i " + x) self.includeDirs);
agdaWithArgs = "${Agda}/bin/agda ${self.buildFlags}"; agdaWithArgs = "${Agda}/bin/agda ${self.buildFlags}";
@ -74,33 +59,34 @@ in
runHook postBuild runHook postBuild
''; '';
installPhase = '' installPhase = let
srcFiles = self.sourceDirectories
++ map (x: x + "/*") self.topSourceDirectories;
in ''
runHook preInstall runHook preInstall
mkdir -p $out/share/agda mkdir -p $out/share/agda
cp -pR ${unwords self.sourceDirectories} ${mapInside self.topSourceDirectories} $out/share/agda cp -pR ${concatStringsSep " " srcFiles} $out/share/agda
runHook postInstall runHook postInstall
''; '';
# Optionally-built conveniences passthru = {
extras = { 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 # Makes a wrapper available to the user. Very useful in
# nix-shell where all dependencies are -i'd. # nix-shell where all dependencies are -i'd.
agdaWrapper = writeScriptBin "agda" '' agdaWrapper = writeScriptBin "agda" ''
${self.agdaWithArgs} "$@" ${self.agdaWithArgs} "$@"
''; '';
in [agdaWrapper] ++ self.buildDepends;
# Use this to stick `agdaWrapper` at the front of the PATH:
#
# agda.mkDerivation (self: { PATH = self.extras.agdaWrapperPATH; })
#
# Not sure this is the best way to handle conflicts....
agdaWrapperPATH = "${self.extras.agdaWrapper}/bin:$PATH";
AGDA_PACKAGE_PATH = concatMapStrings (x: x + ":") self.buildDependsAgdaShareAgda;
}; };
}; };
in stdenv.mkDerivation };
(postprocess (let super = defaults self // args self; in
{ mkDerivation = args: let
super = defaults self // args self;
self = super // extension self super; self = super // extension self super;
in self)); in stdenv.mkDerivation self;
} }