Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev agda shellfor #98087

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions doc/languages-frameworks/agda.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,26 @@ This can be overridden.

By default, Agda sources are files ending on `.agda`, or literate Agda files ending on `.lagda`, `.lagda.tex`, `.lagda.org`, `.lagda.md`, `.lagda.rst`. The list of recognised Agda source extensions can be extended by setting the `extraExtensions` config variable.

## Creating a development environment {#creating-a-development-environment}

You can create a `nix-shell` containing `agda` with all dependency libraries with the function `agdaPackages.shellFor`.
Assuming that you have already created an agda package `mypkg` using `agdaPackages.mkDerivation`,
create a file `shell.nix` containing:

```nix
{ nixpkgs ? import <nixpkgs> {} }:
(nixpkgs.pkgs.agdaPackages.shellFor (import ./mypkg.nix))
```

For convenience, you can also arrive at the same result by accessing the `env` attribute of an Agda derivation:

```nix
(import ./mypkg.nix).env
```

This will bring `agda` in scope with all dependencies of your package,
but not build your package itself (which is useful if you are developing it currently).

## 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}/` 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:
Expand Down
13 changes: 10 additions & 3 deletions pkgs/build-support/agda/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ let
"lagda.tex"
];

filterAgdaBuildInputs = builtins.filter (p: p ? isAgdaDerivation);

shellFor = agdaDrv: mkShell {
buildInputs = [ (withPackages (filterAgdaBuildInputs agdaDrv.buildInputs)) ];
inputsFrom = agdaDrv.buildInputs ++ agdaDrv.nativeBuildInputs;
};

defaults =
{ pname
, meta
Expand All @@ -56,7 +63,7 @@ let
, extraExtensions ? []
, ...
}: let
agdaWithArgs = withPackages (builtins.filter (p: p ? isAgdaDerivation) buildInputs);
agdaWithArgs = withPackages (filterAgdaBuildInputs buildInputs);
in
{
inherit libraryName libraryFile;
Expand All @@ -81,7 +88,7 @@ let
};
in
{
mkDerivation = args: stdenv.mkDerivation (args // defaults args);
mkDerivation = args: (lib.extends (self: super: super // { env = shellFor super; }) stdenv.mkDerivation (args // defaults args));

inherit withPackages withPackages';
inherit withPackages withPackages' shellFor;
}
4 changes: 2 additions & 2 deletions pkgs/top-level/agda-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ let
inherit (callPackage ../build-support/agda {
inherit Agda self;
inherit (pkgs.haskellPackages) ghcWithPackages;
}) withPackages mkDerivation;
}) withPackages mkDerivation shellFor;
in {
inherit mkDerivation;
inherit mkDerivation shellFor;

lib = lib.extend (final: prev: import ../build-support/agda/lib.nix { lib = prev; });

Expand Down