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