|
1 | | -# this file should be very close to a copy of nixpkgs/pkgs/build-support/agda/default.nix |
2 | | -# I think I took the version from https://github.com/NixOS/nixpkgs/blob/bbe6402ecacfc3a0e2c65e3527c2cbe148b98ff8/pkgs/build-support/agda/default.nix |
| 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 |
3 | 5 | # but it would be nice to expose this in upstream so that we don't have to duplicate the file |
4 | | -{stdenv, lib, self, agda2hs, runCommandNoCC, makeWrapper, writeText, mkShell, ghcWithPackages}: |
| 6 | +{ |
| 7 | + stdenv, |
| 8 | + lib, |
| 9 | + self, |
| 10 | + agda2hs, |
| 11 | + runCommandNoCC, |
| 12 | + makeWrapper, |
| 13 | + writeText, |
| 14 | + ghcWithPackages, |
| 15 | +}: |
| 16 | + |
5 | 17 | with lib.strings; |
6 | 18 | let |
7 | 19 | withPackages' = { |
|
26 | 38 | --add-flags "--local-interfaces" |
27 | 39 | ''; # Local interfaces has been added for now: See https://github.com/agda/agda/issues/4526 |
28 | 40 | withPackages = arg: if builtins.isAttrs arg then withPackages' arg else withPackages' { pkgs = arg; }; |
| 41 | + |
| 42 | + extensions = [ |
| 43 | + "agda" |
| 44 | + "agda-lib" |
| 45 | + "agdai" |
| 46 | + "lagda" |
| 47 | + "lagda.md" |
| 48 | + "lagda.org" |
| 49 | + "lagda.rst" |
| 50 | + "lagda.tex" |
| 51 | + "lagda.typ" |
| 52 | + ]; |
| 53 | + |
| 54 | + defaults = |
| 55 | + { |
| 56 | + pname, |
| 57 | + meta, |
| 58 | + buildInputs ? [ ], |
| 59 | + everythingFile ? "./Everything.agda", |
| 60 | + includePaths ? [ ], |
| 61 | + libraryName ? pname, |
| 62 | + libraryFile ? "${libraryName}.agda-lib", |
| 63 | + buildPhase ? null, |
| 64 | + installPhase ? null, |
| 65 | + extraExtensions ? [ ], |
| 66 | + ... |
| 67 | + }: |
| 68 | + let |
| 69 | + agdaWithArgs = withPackages (filter (p: p ? isAgdaDerivation) buildInputs); |
| 70 | + includePathArgs = concatMapStrings (path: "-i" + path + " ") ( |
| 71 | + includePaths ++ [ (dirOf everythingFile) ] |
| 72 | + ); |
| 73 | + in |
| 74 | + { |
| 75 | + inherit libraryName libraryFile; |
| 76 | + |
| 77 | + isAgdaDerivation = true; |
| 78 | + |
| 79 | + buildInputs = buildInputs ++ [ agdaWithArgs ]; |
| 80 | + |
| 81 | + buildPhase = |
| 82 | + if buildPhase != null then |
| 83 | + buildPhase |
| 84 | + else |
| 85 | + '' |
| 86 | + runHook preBuild |
| 87 | + agda2hs ${includePathArgs} ${everythingFile} |
| 88 | + rm ${everythingFile} ${everythingFile}i |
| 89 | + runHook postBuild |
| 90 | + ''; |
| 91 | + |
| 92 | + installPhase = |
| 93 | + if installPhase != null then |
| 94 | + installPhase |
| 95 | + else |
| 96 | + '' |
| 97 | + runHook preInstall |
| 98 | + mkdir -p $out |
| 99 | + find \( ${ |
| 100 | + concatMapStringsSep " -or " (p: "-name '*.${p}'") (extensions ++ extraExtensions) |
| 101 | + } \) -exec cp -p --parents -t "$out" {} + |
| 102 | + runHook postInstall |
| 103 | + ''; |
| 104 | + |
| 105 | + # As documented at https://github.com/NixOS/nixpkgs/issues/172752, |
| 106 | + # we need to set LC_ALL to an UTF-8-supporting locale. However, on |
| 107 | + # darwin, it seems that there is no standard such locale; luckily, |
| 108 | + # the referenced issue doesn't seem to surface on darwin. Hence let's |
| 109 | + # set this only on non-darwin. |
| 110 | + LC_ALL = optionalString (!stdenv.hostPlatform.isDarwin) "C.UTF-8"; |
| 111 | + }; |
| 112 | + |
29 | 113 | in { |
| 114 | + mkDerivation = args: stdenv.mkDerivation (args // defaults args); |
| 115 | + |
30 | 116 | inherit withPackages; |
31 | 117 | agda2hs = withPackages []; |
32 | 118 | } |
0 commit comments