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