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