1# Idris {#idris}
2
3## Installing Idris
4
5The easiest way to get a working idris version is to install the `idris` attribute:
6
7```ShellSesssion
8$ # On NixOS
9$ nix-env -i nixos.idris
10$ # On non-NixOS
11$ nix-env -i nixpkgs.idris
12```
13
14This however only provides the `prelude` and `base` libraries. To install idris with additional libraries, you can use the `idrisPackages.with-packages` function, e.g. in an overlay in `~/.config/nixpkgs/overlays/my-idris.nix`:
15
16```nix
17self: super: {
18 myIdris = with self.idrisPackages; with-packages [ contrib pruviloj ];
19}
20```
21
22And then:
23
24```ShellSesssion
25$ # On NixOS
26$ nix-env -iA nixos.myIdris
27$ # On non-NixOS
28$ nix-env -iA nixpkgs.myIdris
29```
30
31To see all available Idris packages:
32```ShellSesssion
33$ # On NixOS
34$ nix-env -qaPA nixos.idrisPackages
35$ # On non-NixOS
36$ nix-env -qaPA nixpkgs.idrisPackages
37```
38
39Similarly, entering a `nix-shell`:
40```ShellSesssion
41$ nix-shell -p 'idrisPackages.with-packages (with idrisPackages; [ contrib pruviloj ])'
42```
43
44## Starting Idris with library support
45
46To have access to these libraries in idris, call it with an argument `-p <library name>` for each library:
47
48```ShellSesssion
49$ nix-shell -p 'idrisPackages.with-packages (with idrisPackages; [ contrib pruviloj ])'
50[nix-shell:~]$ idris -p contrib -p pruviloj
51```
52
53A listing of all available packages the Idris binary has access to is available via `--listlibs`:
54
55```ShellSesssion
56$ idris --listlibs
5700prelude-idx.ibc
58pruviloj
59base
60contrib
61prelude
6200pruviloj-idx.ibc
6300base-idx.ibc
6400contrib-idx.ibc
65```
66
67## Building an Idris project with Nix
68
69As an example of how a Nix expression for an Idris package can be created, here is the one for `idrisPackages.yaml`:
70
71```nix
72{ lib
73, build-idris-package
74, fetchFromGitHub
75, contrib
76, lightyear
77}:
78build-idris-package {
79 name = "yaml";
80 version = "2018-01-25";
81
82 # This is the .ipkg file that should be built, defaults to the package name
83 # In this case it should build `Yaml.ipkg` instead of `yaml.ipkg`
84 # This is only necessary because the yaml packages ipkg file is
85 # different from its package name here.
86 ipkgName = "Yaml";
87 # Idris dependencies to provide for the build
88 idrisDeps = [ contrib lightyear ];
89
90 src = fetchFromGitHub {
91 owner = "Heather";
92 repo = "Idris.Yaml";
93 rev = "5afa51ffc839844862b8316faba3bafa15656db4";
94 sha256 = "1g4pi0swmg214kndj85hj50ccmckni7piprsxfdzdfhg87s0avw7";
95 };
96
97 meta = with lib; {
98 description = "Idris YAML lib";
99 homepage = "https://github.com/Heather/Idris.Yaml";
100 license = licenses.mit;
101 maintainers = [ maintainers.brainrape ];
102 };
103}
104```
105
106Assuming this file is saved as `yaml.nix`, it's buildable using
107
108```ShellSesssion
109$ nix-build -E '(import <nixpkgs> {}).idrisPackages.callPackage ./yaml.nix {}'
110```
111
112Or it's possible to use
113
114```nix
115with import <nixpkgs> {};
116
117{
118 yaml = idrisPackages.callPackage ./yaml.nix {};
119}
120```
121
122in another file (say `default.nix`) to be able to build it with
123
124```ShellSesssion
125$ nix-build -A yaml
126```
127
128## Passing options to `idris` commands
129
130The `build-idris-package` function provides also optional input values to set additional options for the used `idris` commands.
131
132Specifically, you can set `idrisBuildOptions`, `idrisTestOptions`, `idrisInstallOptions` and `idrisDocOptions` to provide additional options to the `idris` command respectively when building, testing, installing and generating docs for your package.
133
134For example you could set
135
136```nix
137build-idris-package {
138 idrisBuildOptions = [ "--log" "1" "--verbose" ]
139
140 ...
141}
142```
143
144to require verbose output during `idris` build phase.