|
1 | 1 | # This file should be very close to a copy of nixpkgs/pkgs/build-support/agda/default.nix |
2 | | -# The present file appears to be an amalgaman of |
3 | | -# https://github.com/NixOS/nixpkgs/blob/bbe6402ecacfc3a0e2c65e3527c2cbe148b98ff8/pkgs/build-support/agda/default.nix |
4 | | -# https://github.com/NixOS/nixpkgs/blob/583eef75e722741878b186f5bdf5a826d638f868/pkgs/build-support/agda/default.nix |
| 2 | +# The present file is based on https://github.com/NixOS/nixpkgs/blob/1d2cfef5e965ca6933a8aa696eadfa556d90fab3/pkgs/build-support/agda/default.nix |
| 3 | +# FIXME: this file is haskell-updates, double-check that nothing changes once it gets merged in unstable |
5 | 4 | # but it would be nice to expose this in upstream so that we don't have to duplicate the file |
6 | 5 | { |
7 | 6 | stdenv, |
8 | 7 | lib, |
9 | 8 | self, |
10 | 9 | agda2hs, |
11 | | - runCommandNoCC, |
| 10 | + runCommand, |
12 | 11 | makeWrapper, |
13 | 12 | writeText, |
14 | 13 | ghcWithPackages, |
15 | 14 | }: |
16 | | - |
17 | | -with lib.strings; |
18 | 15 | let |
19 | | - withPackages' = { |
20 | | - pkgs, |
21 | | - ghc ? ghcWithPackages (p: with p; [ ieee754 ]) |
22 | | - }: let |
23 | | - pkgs' = if builtins.isList pkgs then pkgs else pkgs self; |
24 | | - library-file = writeText "libraries" '' |
| 16 | + inherit (lib) |
| 17 | + elem |
| 18 | + filter |
| 19 | + filterAttrs |
| 20 | + isList |
| 21 | + isAttrs |
| 22 | + platforms |
| 23 | + ; |
| 24 | + |
| 25 | + inherit (lib.strings) |
| 26 | + concatMapStringsSep |
| 27 | + optionalString |
| 28 | + ; |
| 29 | + |
| 30 | + mkLibraryFile = |
| 31 | + pkgs: |
| 32 | + let |
| 33 | + pkgs' = if isList pkgs then pkgs else pkgs self; |
| 34 | + in |
| 35 | + writeText "libraries" '' |
25 | 36 | ${(concatMapStringsSep "\n" (p: "${p}/${p.libraryFile}") pkgs')} |
26 | 37 | ''; |
27 | | - pname = "agda2hsWithPackages"; |
28 | | - version = agda2hs.version; |
29 | | - in runCommandNoCC "${pname}-${version}" { |
30 | | - inherit pname version; |
31 | | - nativeBuildInputs = [ makeWrapper ]; |
32 | | - passthru.unwrapped = agda2hs; |
33 | | - } '' |
34 | | - mkdir -p $out/bin |
35 | | - makeWrapper ${agda2hs}/bin/agda2hs $out/bin/agda2hs \ |
36 | | - --add-flags "--with-compiler=${ghc}/bin/ghc" \ |
37 | | - --add-flags "--library-file=${library-file}" |
38 | | - ''; |
39 | | - withPackages = arg: if builtins.isAttrs arg then withPackages' arg else withPackages' { pkgs = arg; }; |
| 38 | + |
| 39 | + withPackages' = |
| 40 | + { |
| 41 | + pkgs, |
| 42 | + ghc ? ghcWithPackages (p: with p; [ ieee754 ]), |
| 43 | + }: |
| 44 | + let |
| 45 | + library-file = mkLibraryFile pkgs; |
| 46 | + pname = "agda2hsWithPackages"; |
| 47 | + version = agda2hs.version; |
| 48 | + in |
| 49 | + runCommand "${pname}-${version}" |
| 50 | + { |
| 51 | + inherit pname version; |
| 52 | + nativeBuildInputs = [ makeWrapper ]; |
| 53 | + passthru = { |
| 54 | + unwrapped = agda2hs; |
| 55 | + inherit withPackages; |
| 56 | + }; |
| 57 | + } |
| 58 | + '' |
| 59 | + mkdir -p $out/bin |
| 60 | + makeWrapper ${agda2hs}/bin/agda2hs $out/bin/agda2hs \ |
| 61 | + ${lib.optionalString (ghc != null) ''--add-flags "--with-compiler=${ghc}/bin/ghc"''} \ |
| 62 | + --add-flags "--library-file=${library-file}" |
| 63 | + ''; |
| 64 | + |
| 65 | + withPackages = arg: if isAttrs arg then withPackages' arg else withPackages' { pkgs = arg; }; |
40 | 66 |
|
41 | 67 | extensions = [ |
42 | 68 | "agda" |
|
55 | 81 | pname, |
56 | 82 | meta, |
57 | 83 | buildInputs ? [ ], |
58 | | - everythingFile ? "./Everything.agda", |
59 | | - includePaths ? [ ], |
60 | 84 | libraryName ? pname, |
61 | 85 | libraryFile ? "${libraryName}.agda-lib", |
62 | 86 | buildPhase ? null, |
|
65 | 89 | ... |
66 | 90 | }: |
67 | 91 | let |
68 | | - agdaWithArgs = withPackages (filter (p: p ? isAgdaDerivation) buildInputs); |
69 | | - includePathArgs = concatMapStrings (path: "-i" + path + " ") ( |
70 | | - includePaths ++ [ (dirOf everythingFile) ] |
71 | | - ); |
| 92 | + agdaWithPkgs = withPackages (filter (p: p ? isAgdaDerivation) buildInputs); |
72 | 93 | in |
73 | 94 | { |
74 | 95 | inherit libraryName libraryFile; |
75 | 96 |
|
76 | 97 | isAgdaDerivation = true; |
77 | 98 |
|
78 | | - buildInputs = buildInputs ++ [ agdaWithArgs ]; |
| 99 | + buildInputs = buildInputs ++ [ agdaWithPkgs ]; |
79 | 100 |
|
80 | 101 | buildPhase = |
81 | 102 | if buildPhase != null then |
82 | 103 | buildPhase |
83 | 104 | else |
84 | 105 | '' |
85 | 106 | runHook preBuild |
86 | | - agda2hs ${includePathArgs} ${everythingFile} |
87 | | - rm ${everythingFile} ${everythingFile}i |
| 107 | + agda2hs --build-library |
88 | 108 | runHook postBuild |
89 | 109 | ''; |
90 | 110 |
|
|
112 | 132 | in { |
113 | 133 | mkDerivation = args: stdenv.mkDerivation (args // defaults args); |
114 | 134 |
|
115 | | - inherit withPackages; |
| 135 | + inherit mkLibraryFile withPackages withPackages'; |
116 | 136 | agda2hs = withPackages []; |
117 | 137 | } |
0 commit comments