Skip to content

Commit 1288f57

Browse files
committed
agdaPackages: switch to --build-library
Use the new `--build-library` mode introduced in Agda 2.8.0 to build libraries instead of relying on ad-hoc `Everything` files. This simplifies most derivations (except cubical-mini which imports generated `Everything` files from various modules).
1 parent 5be62c2 commit 1288f57

File tree

12 files changed

+24
-98
lines changed

12 files changed

+24
-98
lines changed

doc/languages-frameworks/agda.section.md

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,10 @@ To install Agda without GHC, use `ghc = null;`.
125125

126126
## Writing Agda packages {#writing-agda-packages}
127127

128-
To write a nix derivation for an Agda library, first check that the library has a `*.agda-lib` file.
128+
To write a nix derivation for an Agda library, first check that the library has a (single) `*.agda-lib` file.
129129

130130
A derivation can then be written using `agdaPackages.mkDerivation`. This has similar arguments to `stdenv.mkDerivation` with the following additions:
131131

132-
* `everythingFile` can be used to specify the location of the `Everything.agda` file, defaulting to `./Everything.agda`. If this file does not exist then either it should be patched in or the `buildPhase` should be overridden (see below).
133132
* `libraryName` should be the name that appears in the `*.agda-lib` file, defaulting to `pname`.
134133
* `libraryFile` should be the file name of the `*.agda-lib` file, defaulting to `${libraryName}.agda-lib`.
135134

@@ -152,9 +151,9 @@ agdaPackages.mkDerivation {
152151

153152
### Building Agda packages {#building-agda-packages}
154153

155-
The default build phase for `agdaPackages.mkDerivation` runs `agda` on the `Everything.agda` file.
154+
The default build phase for `agdaPackages.mkDerivation` runs `agda --build-library`.
156155
If something else is needed to build the package (e.g. `make`) then the `buildPhase` should be overridden.
157-
Additionally, a `preBuild` or `configurePhase` can be used if there are steps that need to be done prior to checking the `Everything.agda` file.
156+
Additionally, a `preBuild` or `configurePhase` can be used if there are steps that need to be done prior to checking the library.
158157
`agda` and the Agda libraries contained in `buildInputs` are made available during the build phase.
159158

160159
### Installing Agda packages {#installing-agda-packages}
@@ -182,53 +181,37 @@ the Agda package set is small and can (still) be maintained by hand.
182181

183182
### Adding Agda packages to Nixpkgs {#adding-agda-packages-to-nixpkgs}
184183

185-
To add an Agda package to `nixpkgs`, the derivation should be written to `pkgs/development/libraries/agda/${library-name}/` and an entry should be added to `pkgs/top-level/agda-packages.nix`. Here it is called in a scope with access to all other Agda libraries, so the top line of the `default.nix` can look like:
184+
To add an Agda package to `nixpkgs`, the derivation should be written to `pkgs/development/libraries/agda/${library-name}/default.nix` and an entry should be added to `pkgs/top-level/agda-packages.nix`. Here it is called in a scope with access to all other Agda libraries, so the derivation could look like:
186185

187186
```nix
188187
{
189188
mkDerivation,
190189
standard-library,
191190
fetchFromGitHub,
192191
}:
193-
{ }
194-
```
195-
196-
Note that the derivation function is called with `mkDerivation` set to `agdaPackages.mkDerivation`, therefore you
197-
could use a similar set as in your `default.nix` from [Writing Agda Packages](#writing-agda-packages) with
198-
`agdaPackages.mkDerivation` replaced with `mkDerivation`.
199192
200-
Here is an example skeleton derivation for iowa-stdlib:
201-
202-
```nix
203193
mkDerivation {
204-
version = "1.5.0";
205-
pname = "iowa-stdlib";
206-
194+
pname = "my-library";
195+
version = "1.0";
207196
src = <...>;
208-
209-
libraryFile = "";
210-
libraryName = "IAL-1.3";
211-
212-
buildPhase = ''
213-
runHook preBuild
214-
215-
patchShebangs find-deps.sh
216-
make
217-
218-
runHook postBuild
219-
'';
197+
buildInputs = [ standard-library ];
198+
meta = <...>;
220199
}
221200
```
222201

223-
This library has a file called `.agda-lib`, and so we give an empty string to `libraryFile` as nothing precedes `.agda-lib` in the filename. This file contains `name: IAL-1.3`, and so we let `libraryName = "IAL-1.3"`. This library does not use an `Everything.agda` file and instead has a Makefile, so there is no need to set `everythingFile` and we set a custom `buildPhase`.
202+
You can look at other files under `pkgs/development/libraries/agda/` for more inspiration.
203+
204+
Note that the derivation function is called with `mkDerivation` set to `agdaPackages.mkDerivation`, therefore you
205+
could use a similar set as in your `default.nix` from [Writing Agda Packages](#writing-agda-packages) with
206+
`agdaPackages.mkDerivation` replaced with `mkDerivation`.
224207

225208
When writing an Agda package it is essential to make sure that no `.agda-lib` file gets added to the store as a single file (for example by using `writeText`). This causes Agda to think that the nix store is a Agda library and it will attempt to write to it whenever it typechecks something. See [https://github.com/agda/agda/issues/4613](https://github.com/agda/agda/issues/4613).
226209

227210
In the pull request adding this library,
228211
you can test whether it builds correctly by writing in a comment:
229212

230213
```
231-
@ofborg build agdaPackages.iowa-stdlib
214+
@ofborg build agdaPackages.my-library
232215
```
233216

234217
### Maintaining Agda packages {#agda-maintaining-packages}

pkgs/build-support/agda/default.nix

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,6 @@ let
9090
pname,
9191
meta,
9292
buildInputs ? [ ],
93-
everythingFile ? "./Everything.agda",
94-
includePaths ? [ ],
9593
libraryName ? pname,
9694
libraryFile ? "${libraryName}.agda-lib",
9795
buildPhase ? null,
@@ -100,26 +98,22 @@ let
10098
...
10199
}:
102100
let
103-
agdaWithArgs = withPackages (filter (p: p ? isAgdaDerivation) buildInputs);
104-
includePathArgs = concatMapStrings (path: "-i" + path + " ") (
105-
includePaths ++ [ (dirOf everythingFile) ]
106-
);
101+
agdaWithPkgs = withPackages (filter (p: p ? isAgdaDerivation) buildInputs);
107102
in
108103
{
109104
inherit libraryName libraryFile;
110105

111106
isAgdaDerivation = true;
112107

113-
buildInputs = buildInputs ++ [ agdaWithArgs ];
108+
buildInputs = buildInputs ++ [ agdaWithPkgs ];
114109

115110
buildPhase =
116111
if buildPhase != null then
117112
buildPhase
118113
else
119114
''
120115
runHook preBuild
121-
agda ${includePathArgs} ${everythingFile}
122-
rm ${everythingFile} ${lib.interfaceFile Agda.version everythingFile}
116+
agda --build-library
123117
runHook postBuild
124118
'';
125119

pkgs/build-support/agda/lib.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
* The resulting path may not be normalized.
77
*
88
* Examples:
9-
* interfaceFile pkgs.agda.version "./Everything.agda" == "_build/2.6.4.3/agda/./Everything.agdai"
10-
* interfaceFile pkgs.agda.version "src/Everything.lagda.tex" == "_build/2.6.4.3/agda/src/Everything.agdai"
9+
* interfaceFile pkgs.agda.version "./Foo.agda" == "_build/AGDA_VERSION/agda/./Foo.agdai"
10+
* interfaceFile pkgs.agda.version "src/Foo.lagda.tex" == "_build/AGDA_VERSION/agda/src/Foo.agdai"
1111
*/
1212
interfaceFile =
1313
agdaVersion: agdaFile:

pkgs/development/libraries/agda/1lab/default.nix

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,8 @@ mkDerivation rec {
2323
shopt -s globstar extglob
2424
files=(src/**/*.@(agda|lagda.md))
2525
sed -Ei '/OPTIONS/s/ -v ?[^ #]+//g' "''${files[@]}"
26-
27-
# Generate all-pages manually instead of building the build script.
28-
mkdir -p _build
29-
for f in "''${files[@]}"; do
30-
f=''${f#src/} f=''${f%%.*} f=''${f//\//.}
31-
echo "open import $f"
32-
done > _build/all-pages.agda
3326
'';
3427

35-
libraryName = "1lab";
36-
libraryFile = "1lab.agda-lib";
37-
everythingFile = "_build/all-pages.agda";
38-
3928
meta = with lib; {
4029
description = "A formalised, cross-linked reference resource for mathematics done in Homotopy Type Theory ";
4130
homepage = src.meta.homepage;

pkgs/development/libraries/agda/agda-categories/default.nix

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@ mkDerivation rec {
2424
# version update of the stdlib, so we get rid of the version constraint
2525
# altogether.
2626
sed -Ei 's/standard-library-[0-9.]+/standard-library/' agda-categories.agda-lib
27-
28-
# The Makefile of agda-categories uses git(1) instead of find(1) to
29-
# determine the list of source files. We cannot use git, as $PWD will not
30-
# be a valid Git working directory.
31-
find src -name '*.agda' | sed -e 's|^src/[/]*|import |' -e 's|/|.|g' -e 's/.agda//' -e '/import Everything/d' | LC_COLLATE='C' sort > Everything.agda
3227
'';
3328

3429
buildInputs = [ standard-library ];

pkgs/development/libraries/agda/agda-prelude/default.nix

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,6 @@ mkDerivation {
1515
hash = "sha256-ab+KojzRbkUTAFNH5OA78s0F5SUuXTbliai6badveg4=";
1616
};
1717

18-
preConfigure = ''
19-
cd test
20-
make everything
21-
mv Everything.agda ..
22-
cd ..
23-
'';
24-
2518
meta = with lib; {
2619
homepage = "https://github.com/UlfNorell/agda-prelude";
2720
description = "Programming library for Agda";

pkgs/development/libraries/agda/agdarsec/default.nix

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,6 @@ mkDerivation rec {
1616
sha256 = "02fqkycvicw6m2xsz8p01aq8n3gj2d2gyx8sgj15l46f8434fy0x";
1717
};
1818

19-
everythingFile = "./index.agda";
20-
21-
includePaths = [
22-
"src"
23-
"examples"
24-
];
25-
2619
buildInputs = [ standard-library ];
2720

2821
meta = with lib; {

pkgs/development/libraries/agda/cubical/default.nix

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
lib,
33
mkDerivation,
44
fetchFromGitHub,
5-
ghc,
65
}:
76

87
mkDerivation rec {
@@ -16,13 +15,10 @@ mkDerivation rec {
1615
hash = "sha256-KwwN2g2naEo4/rKTz2L/0Guh5LxymEYP53XQzJ6eMjM=";
1716
};
1817

19-
# The cubical library has several `Everything.agda` files, which are
20-
# compiled through the make file they provide.
21-
nativeBuildInputs = [ ghc ];
22-
buildPhase = ''
23-
runHook preBuild
24-
make
25-
runHook postBuild
18+
postPatch = ''
19+
# This imports the Everything files, which we don't generate.
20+
# TODO: remove for the next release
21+
rm -rf Cubical/README.agda Cubical/Talks/EPA2020.agda
2622
'';
2723

2824
meta = with lib; {

pkgs/development/libraries/agda/functional-linear-algebra/default.nix

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ mkDerivation rec {
1818
sha256 = "sha256-3nme/eH4pY6bD0DkhL4Dj/Vp/WnZqkQtZTNk+n1oAyY=";
1919
};
2020

21-
preConfigure = ''
22-
sh generate-everything.sh
23-
'';
24-
2521
meta = with lib; {
2622
homepage = "https://github.com/ryanorendorff/functional-linear-algebra";
2723
description = ''

pkgs/development/libraries/agda/generics/default.nix

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ mkDerivation rec {
2525
rm tests.agda-lib
2626
'';
2727

28-
# everythingFile = "./README.agda";
29-
3028
meta = with lib; {
3129
description = "Library for datatype-generic programming in Agda";
3230
homepage = src.meta.homepage;

0 commit comments

Comments
 (0)