You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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).
Copy file name to clipboardExpand all lines: doc/languages-frameworks/agda.section.md
+14-31Lines changed: 14 additions & 31 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -125,11 +125,10 @@ To install Agda without GHC, use `ghc = null;`.
125
125
126
126
## Writing Agda packages {#writing-agda-packages}
127
127
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.
129
129
130
130
A derivation can then be written using `agdaPackages.mkDerivation`. This has similar arguments to `stdenv.mkDerivation` with the following additions:
131
131
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).
133
132
*`libraryName` should be the name that appears in the `*.agda-lib` file, defaulting to `pname`.
134
133
*`libraryFile` should be the file name of the `*.agda-lib` file, defaulting to `${libraryName}.agda-lib`.
135
134
@@ -152,9 +151,9 @@ agdaPackages.mkDerivation {
152
151
153
152
### Building Agda packages {#building-agda-packages}
154
153
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`.
156
155
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.
158
157
`agda` and the Agda libraries contained in `buildInputs` are made available during the build phase.
@@ -182,53 +181,37 @@ the Agda package set is small and can (still) be maintained by hand.
182
181
183
182
### Adding Agda packages to Nixpkgs {#adding-agda-packages-to-nixpkgs}
184
183
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:
186
185
187
186
```nix
188
187
{
189
188
mkDerivation,
190
189
standard-library,
191
190
fetchFromGitHub,
192
191
}:
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`.
199
192
200
-
Here is an example skeleton derivation for iowa-stdlib:
201
-
202
-
```nix
203
193
mkDerivation {
204
-
version = "1.5.0";
205
-
pname = "iowa-stdlib";
206
-
194
+
pname = "my-library";
195
+
version = "1.0";
207
196
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 = <...>;
220
199
}
221
200
```
222
201
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`.
224
207
225
208
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).
226
209
227
210
In the pull request adding this library,
228
211
you can test whether it builds correctly by writing in a comment:
0 commit comments