@@ -7,100 +7,86 @@
77, extension ? (self: super: {})
88}:
99
10−let
11− optionalString = stdenv.lib.optionalString;
12− filter = stdenv.lib.filter;
13− concatMapStringsSep = stdenv.lib.strings.concatMapStringsSep;
14− concatMapStrings = stdenv.lib.strings.concatMapStrings;
15− unwords = stdenv.lib.strings.concatStringsSep " ";
16− mapInside = xs: unwords (map (x: x + "/*") xs);
17−in
18−{ mkDerivation = args:
19− let
20− postprocess = x: x // {
21− sourceDirectories = filter (y: !(y == null)) x.sourceDirectories;
22− propagatedBuildInputs = filter (y : ! (y == null)) x.propagatedBuildInputs;
23− propagatedUserEnvPkgs = filter (y : ! (y == null)) x.propagatedUserEnvPkgs;
24− everythingFile = if x.everythingFile == "" then "Everything.agda" else x.everythingFile;
25−
26− passthru = { inherit (x) extras; };
27− extras = null;
28− };
29−
30− defaults = self : {
31− # There is no Hackage for Agda so we require src.
32− inherit (self) src name;
33−
34− isAgdaPackage = true;
35−
36− buildInputs = [ Agda ] ++ self.buildDepends;
37− buildDepends = [];
38−
39− buildDependsAgda = filter
40− (dep: dep ? isAgdaPackage && dep.isAgdaPackage)
41− self.buildDepends;
42− buildDependsAgdaShareAgda = map (x: x + "/share/agda") self.buildDependsAgda;
43−
44− # Not much choice here ;)
45− LANG = "en_US.UTF-8";
46− LOCALE_ARCHIVE = optionalString stdenv.isLinux "${glibcLocales}/lib/locale/locale-archive";
47−
48− everythingFile = "Everything.agda";
49−
50− propagatedBuildInputs = self.buildDependsAgda;
51− propagatedUserEnvPkgs = self.buildDependsAgda;
10+with stdenv.lib.strings;
5211
53− # Immediate source directories under which modules can be found.
54− sourceDirectories = [ ];
55−
56− # This is used if we have a top-level element that only serves
57− # as the container for the source and we only care about its
58− # contents. The directories put here will have their
59− # *contents* copied over as opposed to sourceDirectories which
60− # would make a direct copy of the whole thing.
61− topSourceDirectories = [ "src" ];
62−
63− # FIXME: `dirOf self.everythingFile` is what we really want, not hardcoded "./"
64− includeDirs = self.buildDependsAgdaShareAgda
65− ++ self.sourceDirectories ++ self.topSourceDirectories
66− ++ [ "." ];
67− buildFlags = unwords (map (x: "-i " + x) self.includeDirs);
68−
69− agdaWithArgs = "${Agda}/bin/agda ${self.buildFlags}";
70−
71− buildPhase = ''
72− runHook preBuild
73− ${self.agdaWithArgs} ${self.everythingFile}
74− runHook postBuild
75− '';
76−
77− installPhase = ''
78− runHook preInstall
79− mkdir -p $out/share/agda
80− cp -pR ${unwords self.sourceDirectories} ${mapInside self.topSourceDirectories} $out/share/agda
81− runHook postInstall
82− '';
83−
84− # Optionally-built conveniences
85− extras = {
12+let
13+ defaults = self : {
14+ # There is no Hackage for Agda so we require src.
15+ inherit (self) src name;
16+
17+ isAgdaPackage = true;
18+
19+ buildInputs = [ Agda ] ++ self.buildDepends;
20+ buildDepends = [];
21+
22+ buildDependsAgda = stdenv.lib.filter
23+ (dep: dep ? isAgdaPackage && dep.isAgdaPackage)
24+ self.buildDepends;
25+ buildDependsAgdaShareAgda = map (x: x + "/share/agda") self.buildDependsAgda;
26+
27+ # Not much choice here ;)
28+ LANG = "en_US.UTF-8";
29+ LOCALE_ARCHIVE = stdenv.lib.optionalString
30+ stdenv.isLinux
31+ "${glibcLocales}/lib/locale/locale-archive";
32+
33+ everythingFile = "Everything.agda";
34+
35+ propagatedBuildInputs = self.buildDependsAgda;
36+ propagatedUserEnvPkgs = self.buildDependsAgda;
37+
38+ # Immediate source directories under which modules can be found.
39+ sourceDirectories = [ ];
40+
41+ # This is used if we have a top-level element that only serves
42+ # as the container for the source and we only care about its
43+ # contents. The directories put here will have their
44+ # *contents* copied over as opposed to sourceDirectories which
45+ # would make a direct copy of the whole thing.
46+ topSourceDirectories = [ "src" ];
47+
48+ # FIXME: `dirOf self.everythingFile` is what we really want, not hardcoded "./"
49+ includeDirs = self.buildDependsAgdaShareAgda
50+ ++ self.sourceDirectories ++ self.topSourceDirectories
51+ ++ [ "." ];
52+ buildFlags = concatStringsSep " " (map (x: "-i " + x) self.includeDirs);
53+
54+ agdaWithArgs = "${Agda}/bin/agda ${self.buildFlags}";
55+
56+ buildPhase = ''
57+ runHook preBuild
58+ ${self.agdaWithArgs} ${self.everythingFile}
59+ runHook postBuild
60+ '';
61+
62+ installPhase = let
63+ srcFiles = self.sourceDirectories
64+ ++ map (x: x + "/*") self.topSourceDirectories;
65+ in ''
66+ runHook preInstall
67+ mkdir -p $out/share/agda
68+ cp -pR ${concatStringsSep " " srcFiles} $out/share/agda
69+ runHook postInstall
70+ '';
71+
72+ passthru = {
73+ env = stdenv.mkDerivation {
74+ name = "interactive-${self.name}";
75+ inherit (self) LANG LOCALE_ARCHIVE;
76+ AGDA_PACKAGE_PATH = concatMapStrings (x: x + ":") self.buildDependsAgdaShareAgda;
77+ buildInputs = let
8678 # Makes a wrapper available to the user. Very useful in
8779 # nix-shell where all dependencies are -i'd.
8880 agdaWrapper = writeScriptBin "agda" ''
8981 ${self.agdaWithArgs} "$@"
9082 '';
91−
92− # Use this to stick `agdaWrapper` at the front of the PATH:
93− #
94− # agda.mkDerivation (self: { PATH = self.extras.agdaWrapperPATH; })
95− #
96− # Not sure this is the best way to handle conflicts....
97− agdaWrapperPATH = "${self.extras.agdaWrapper}/bin:$PATH";
98−
99− AGDA_PACKAGE_PATH = concatMapStrings (x: x + ":") self.buildDependsAgdaShareAgda;
100− };
83+ in [agdaWrapper] ++ self.buildDepends;
10184 };
102− in stdenv.mkDerivation
103− (postprocess (let super = defaults self // args self;
104− self = super // extension self super;
105− in self));
85+ };
86+ };
87+in
88+{ mkDerivation = args: let
89+ super = defaults self // args self;
90+ self = super // extension self super;
91+ in stdenv.mkDerivation self;
10692}