@@ -0,0 +1,203 @@
1+# Getting started with Hix
3+The `hix` tools are wrappers for the various `nix` tools that
4+use `haskell.nix` without the need to add any `.nix` files.
8+* A quick way to try out haskell.nix for new users.
10+* Using haskell.nix to work on projects that do not have
13+* Testing to see if `haskell.nix` can build a project.
15+* Making `flake` and `non flake` configurations to check `haskell.nix`
16+ treats them the same.
20+To use Hix you will need to install [Nix](https://nixos.org/download.html).
22+## Setting up the binary cache
24+IMPORTANT: you *must* do this or you *will* build several copies of GHC!
26+You can configure Nix to use our binary cache, which is pushed to by CI, so should contain the artifacts that you need.
28+You need to add the following sections to `/etc/nix/nix.conf` or, if you are a trusted user, `~/.config/nix/nix.conf` (if you don't know what a "trusted user" is, you probably want to do the former).
31+trusted-public-keys = [...] hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ= [...]
32+substituters = [...] https://hydra.iohk.io [...]
35+This can be tricky to get setup properly. If you're still having trouble getting cache hits, consult the corresponding [troubleshooting section](../reference/troubleshooting#why-am-i-building-ghc).
40+nix-env -iA hix -f https://github.com/input-output-hk/haskell.nix/tarball/master
43+## Updating Hix (also updates hackage)
49+This is also necessary to make the latest nightly snapshot of hackage
54+To run `cabal build` in a nix-shell with all the dependencies required:
59+hix-shell --run 'cabal build'
65+hix-build -A hsPkgs.hello.components.exes.hello
68+Cross compile to JavaScript:
71+hix-build -A projectCross.ghcjs.hsPkgs.hello.components.exes.hello
76+The configuration arguments for `Hix` can be (from highest precedence to lowest):
78+* Passed on the command line with `--arg` (or `--argstr` for string args).
80+* Placed in `nix/hix.nix` file in the project dir.
82+* Placed in `~/.config/hix/hix.conf`
84+For example to build with GHC 8.10.5:
87+hix-shell --argstr compiler-nix-name ghc8105 --run 'cabal build'
90+or add a `nix/hix.nix` or `~/.config/hix/hix.conf` file:
93+{ compiler-nix-name = "ghc8105"; }
96+Here are just a few of the other configuration arguments you could use
97+in the files or on the command line (they are all optional):
100+{ name = "hello"; # for better error messages and derivation names
101+ nixpkgsPin = "nixpkgs-unstable"; # or nixpkgs-2009 or nixpkgs-2003
102+ nixpkgs = <nixpkgs>; # use this instead of nixpkgsPin
103+ subDir = "some/sub/dir"; # sub dir containing the haskell project
104+ projectFileName = "stack.yaml"; # use this project file
105+ tools.haskell-language-server = "latest";
106+ tools.hlint = "latest"; # Include the latest hls and hlint in the shell
107+ index-state = "2021-02-22T00:00:00Z"; # It is normally best to put this in `cabal.project` (not here)
109+# PLUS MANY MORE! Almost any argument you can pass to the project functions
110+# or to `shellFor` can be used in as a Hix configuration argument.
115+## Adding Nix Support with Niv
117+If you have a `nix/hix.nix` file with suitable configuration that
118+you want to make available to users with Nix (without having to
121+[Niv](https://github.com/nmattia/niv) is a command line tool for keeping tack of Nix project dependencies.
123+After installing niv you can initialize niv and pin the latest haskell.nix
124+commit by running the following in the root directory of the project:
128+niv add input-output-hk/haskell.nix -n haskellNix
134+(import (import nix/sources.nix).haskellNix {}).hix.project { src = ./.; }
137+If you want to also pin `nixpkgs` with Niv use:
141+ sources = import nix/sources.nix;
143+ (import sources.haskellNix {}).hix.project {
144+ inherit (sources) nixpkgs;
155+When you want to update to the latest version of haskell.nix use:
158+niv update haskellNix
161+## Adding Nix Flake Support
163+To add flake support that uses the `nix/hix.nix` configuration in your
164+follow the [Getting started with flakes](getting-started.md) guide, but
165+use `haskell-nix.hix.project` instead of `haskell-nix.project'`
167+The `nixpkgs` used will need to be selected as a flake input (any selection
168+made in `nix/hix.nix` will be ignored).
170+Example `flake.nix` file:
174+ description = "A very basic flake";
175+ inputs.haskellNix.url = "github:input-output-hk/haskell.nix";
176+ inputs.nixpkgs.follows = "haskellNix/nixpkgs-unstable";
177+ inputs.flake-utils.url = "github:numtide/flake-utils";
178+ outputs = { self, nixpkgs, flake-utils, haskellNix }:
179+ flake-utils.lib.eachSystem [ "x86_64-linux" "x86_64-darwin" ] (system:
181+ overlays = [ haskellNix.overlay
183+ # This overlay adds our project to pkgs
185+ final.haskell-nix.hix.project {
187+ # Other project options can be put in `nix/hix.nix`
191+ pkgs = import nixpkgs { inherit system overlays; };
192+ flake = pkgs.helloProject.flake {
193+ # This adds support for `nix build .#js-unknown-ghcjs:hello:exe:hello`
194+ crossPlatforms = p: [p.ghcjs];
197+ # Built by `nix build .`
198+ defaultPackage = flake.packages."hello:exe:hello";