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