Home Explore Blog Models CI



nixpkgs

3rd chunk of `doc/languages-frameworks/agda.section.md`
241d254f5f1847cfb9c18e4a48e89444b264e5d10ba9453d0000000100000a5a
We are aiming at providing all common Agda libraries as packages on `nixpkgs`,
and keeping them up to date.
Contributions and maintenance help is always appreciated,
but the maintenance effort is typically low since the Agda ecosystem is quite small.

The `nixpkgs` Agda package set tries to take up a role similar to that of [Stackage](https://www.stackage.org/) in the Haskell world.
It is a curated set of libraries that:

1. Always work together.
2. Are as up-to-date as possible.

While the Haskell ecosystem is huge, and Stackage is highly automated,
the Agda package set is small and can (still) be maintained by hand.

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

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:

```nix
{
  mkDerivation,
  standard-library,
  fetchFromGitHub,
}:

mkDerivation {
  pname = "my-library";
  version = "1.0";
  src = <...>;
  buildInputs = [ standard-library ];
  meta = <...>;
}
```

You can look at other files under `pkgs/development/libraries/agda/` for more inspiration.

Note that the derivation function is called with `mkDerivation` set to `agdaPackages.mkDerivation`, therefore you
could use a similar set as in your `default.nix` from [Writing Agda Packages](#writing-agda-packages) with
`agdaPackages.mkDerivation` replaced with `mkDerivation`.

Here is an example skeleton derivation for iowa-stdlib:

```nix
mkDerivation {
  version = "1.5.0";
  pname = "iowa-stdlib";

  src = <...>;

  libraryFile = "";
  libraryName = "IAL-1.3";

  buildPhase = ''
    runHook preBuild

    patchShebangs find-deps.sh
    make

    runHook postBuild
  '';
}
```

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`.

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://githcub.com/agda/agda/issues/4613).

Title: Maintaining and Adding Agda Packages to Nixpkgs
Summary
This section details the process for maintaining and contributing Agda libraries to Nixpkgs. It explains that Nixpkgs aims to provide a curated, compatible, and up-to-date set of Agda libraries, similar to Haskell's Stackage but manually maintained. To add an Agda package, users must create a Nix derivation at `pkgs/development/libraries/agda/${library-name}/default.nix` and add an entry to `pkgs/top-level/agda-packages.nix`. The derivation uses `mkDerivation` (an alias for `agdaPackages.mkDerivation`), with examples showing how to configure `pname`, `version`, `src`, `buildInputs`, and `meta`. A specific example for `iowa-stdlib` demonstrates customizing `libraryFile`, `libraryName`, and `buildPhase` for libraries with non-standard setups. A critical warning advises against adding standalone `.agda-lib` files directly to the Nix store, as this can cause Agda to attempt write operations to the read-only store.