Skip to content

Commit 8309423

Browse files
authored
Fix #518: examples in documentation need to be tested (#1714)
1 parent b6fc426 commit 8309423

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+1673
-594
lines changed

.buildkite/pipeline.yml

+5
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ steps:
7474
agents:
7575
system: x86_64-linux
7676

77+
- label: 'Test examples in documentation ...'
78+
command: "./test/tests.sh ghc8107 docs"
79+
agents:
80+
system: x86_64-linux
81+
7782
- label: 'Check that jobset will evaluate in Hydra at ifdLevel 0 and 1'
7883
command:
7984
- nix-build build.nix -A maintainer-scripts.check-hydra -o check-hydra.sh

.gitignore

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
# The output of "mkdocs build"
2-
/site/
3-
docs/reference/modules.md
1+
# The output of "mdbook build"
2+
/book/
3+
/docs/reference/modules.md
4+
/docs/**/index.html
45

56
# Nix build results
67
result*

book.toml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[book]
2+
language = "en"
3+
multilingual = false
4+
src = "docs"
5+
title = "Alternative Haskell Infrastructure for Nixpkgs"

docs/SUMMARY.md

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
- [Introduction](./index.md)
2+
- [Motivation](./motivation.md)
3+
- [Architecture](./architecture.md)
4+
- [Tutorials](./tutorials/index.md)
5+
- [Getting started](./tutorials/getting-started.md)
6+
- [Getting started with Flakes](./tutorials/getting-started-flakes.md)
7+
- [Getting started with Hix](./tutorials/getting-started-hix.md)
8+
- [Creating a development environment](./tutorials/development.md)
9+
- [Sourcing files only part of git repository using cleanGit](./tutorials/clean-git.md)
10+
- [Handling git repositories in projects](./tutorials/source-repository-hashes.md)
11+
- [Mapping non-Haskell dependencies to Nixpkgs](./tutorials/pkg-map.md)
12+
- [Bumping Hackage and Stackage snapshots](./tutorials/hackage-stackage.md)
13+
- [Materialization: Speeding up Nix evaluation](./tutorials/materialization.md)
14+
- [Cross-compiling your project](./tutorials/cross-compilation.md)
15+
- [Generating coverage information](./tutorials/coverage.md)
16+
- [Build a specific package from Hackage or Stackage](./tutorials/building-package-from-stackage-hackage.md)
17+
- [Content addressed derivations](./tutorials/ca-derivations.md)
18+
- [Reference](./reference/index.md)
19+
- [Supported GHC versions](./reference/supported-ghc-versions.md)
20+
- [Command-line tools](./reference/commands.md)
21+
- [Haskell.nix Library](./reference/library.md)
22+
- [Module options](./reference/modules.md)
23+
- [Troubleshooting](./troubleshooting.md)
24+
- [Templates / Abstraction](./template/index.html)
25+
- [IOHKs nix library](./template/iohk-nix.md)
26+
- [Dev Notes](./dev/index.html)
27+
- [Architecture](./dev/dev-architecture.md)
28+
- [Installing nix-tools](./dev/installing-nix-tools.md)
29+
- [How to update nix-tools](./dev/nix-tools-pin.md)
30+
- [Manually generating Nix expressions](./dev/manually-generating-nix-expressions.md)
31+
- [Maintainer Scripts](./dev/maintainer-scripts.md)
32+
- [Nixpkgs Pin](./dev/nixpkgs-pin.md)
33+
- [Removing withPackage wrapper](./dev/removing-with-package-wrapper.md)
34+
- [Test Suite](./dev/tests.md)
35+
- [Adding a new GHC version](./dev/adding-new-ghc.md)
36+
- [Coverage](./dev/coverage.md)
37+
- [Making changes to Hix](./dev/hix.md)
38+
- [ChangeLog](./changelog.md)

docs/dev/adding-new-ghc.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Check the LLVM version that should be used in the
1616

1717
In the haskell.nix repo run:
1818

19-
```
19+
```shell
2020
mkdir materialized/ghc884
2121
nix-build scripts/check-compiler-materialization --argstr compiler-nix-name ghc884
2222
```

docs/dev/coverage.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ reports (as detailed in the [coverage tutorial](../tutorials/coverage.md#custom)
5252

5353
The coverage information generated will look something like this:
5454

55-
```bash
55+
```shell
5656
/nix/store/...-my-project-0.1.0.0-coverage-report/
5757
└── share
5858
└── hpc
@@ -105,7 +105,7 @@ The coverage information generated will look something like this:
105105
The coverage information for an entire project will look something
106106
like this:
107107

108-
```bash
108+
```shell
109109
/nix/store/...-coverage-report
110110
└── share
111111
└── hpc

docs/dev/hix.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@ test the changes locally before uploading them to github.
77

88
Install the hix command wrappers after making changes to a local clone of haskell.nix:
99

10-
```
10+
```shell
1111
nix-env -iA hix -f /path/to/local/haskell.nix
1212
hix-shell
1313
```
1414

1515
Or override the version of haskell.nix used by the commands with the `HIX_ROOT` environment variable:
1616

17-
```
17+
```shell
1818
HIX_ROOT=/path/to/local/haskell.nix hix-shell
1919
```
2020

2121
## Flakes
2222

2323
For flakes use `--override-input` to point to the modified haskell.nix:
2424

25-
```
25+
```shell
2626
nix develop --override-input haskellNix /path/to/local/haskell.nix
2727
```

docs/dev/index.md

Whitespace-only changes.

docs/dev/installing-nix-tools.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
To build the latest `nix-tools` and store the result at `./nt`, run:
44

5-
```bash
5+
```shell
66
nix build -f https://github.com/input-output-hk/haskell.nix/archive/master.tar.gz pkgs.haskell-nix.nix-tools.ghc884 --out-link nt
77
```
88

99
If you would like to then install `nix-tools` into your profile, run:
1010

11-
```bash
11+
```shell
1212
nix-env -i ./nt
1313
```
1414

@@ -18,7 +18,7 @@ The [Haskell.nix][] and `nix-tools` source will be useful if you would
1818
like to contribute improvements, or read the source code to fully
1919
understand something that the documentation doesn't cover.
2020

21-
```bash
21+
```shell
2222
git clone https://github.com/input-output-hk/nix-tools
2323
git clone https://github.com/input-output-hk/haskell.nix
2424
cd haskell.nix

docs/dev/maintainer-scripts.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ scripts in this repo.
88

99
To run the updater scripts manually, use:
1010

11-
nix-build build.nix -A maintainer-scripts.update-hackage -o update-hackage.sh
12-
./update-hackage.sh
11+
```shell
12+
nix-build build.nix -A maintainer-scripts.update-hackage -o update-hackage.sh
13+
./update-hackage.sh
1314

14-
nix-build build.nix -A maintainer-scripts.update-stackage -o update-stackage.sh
15-
./update-stackage.sh
15+
nix-build build.nix -A maintainer-scripts.update-stackage -o update-stackage.sh
16+
./update-stackage.sh
17+
```
1618

1719
The scripts will clone the repo, generate the latest data, then
1820
attempt to push back to the repo and update the source JSON file.

docs/dev/manually-generating-nix-expressions.md

+16-57
Original file line numberDiff line numberDiff line change
@@ -19,62 +19,19 @@ Let us assume for now that we have already generated a `pkgs.nix`
1919
expression (see the links bellow). The following file then produces a package set:
2020

2121
```nix
22-
# default.nix
23-
let
24-
# Import the Haskell.nix library,
25-
pkgs = import <nixpkgs> (import (builtins.fetchTarball https://github.com/input-output-hk/haskell.nix/archive/master.tar.gz) {}).nixpkgsArgs;
26-
27-
# Import the file you will create in the stack-to-nix or cabal-to-nix step.
28-
my-pkgs = import ./pkgs.nix;
29-
30-
# Stack projects use this:
31-
pkgSet = pkgs.haskell-nix.mkStackPkgSet {
32-
stack-pkgs = my-pkgs;
33-
pkg-def-extras = [
34-
# these extras will provide additional packages
35-
# ontop of the package set. E.g. extra-deps
36-
# for stack packages. or local packages for
37-
# cabal.projects
38-
];
39-
modules = [
40-
# specific package overrides would go here
41-
# example:
42-
# packages.cbors.package.ghcOptions = "-Werror";
43-
# packages.cbors.patches = [ ./one.patch ];
44-
# packages.cbors.flags.optimize-gmp = false;
45-
# It may be better to set flags in stack.yaml instead
46-
# (`stack-to-nix` will include them as defaults).
47-
];
48-
};
49-
50-
# Cabal projects use this:
51-
pkgSet = pkgs.haskell-nix.mkCabalProjectPkgSet {
52-
plan-pkgs = my-pkgs;
53-
pkg-def-extras = [];
54-
modules = [
55-
# specific package overrides would go here
56-
# example:
57-
# packages.cbors.package.ghcOptions = "-Werror";
58-
# packages.cbors.patches = [ ./one.patch ];
59-
# packages.cbors.flags.optimize-gmp = false;
60-
# It may be better to set flags in `cabal.project` instead
61-
# (`plan-to-nix` will include them as defaults).
62-
];
63-
};
64-
65-
in pkgSet.config.hsPkgs // { _config = pkgSet.config; }
22+
{{#include manually-generating-nix-expressions/default.nix}}
6623
```
6724

6825
With this setup you can then start building the components of
6926
interest:
7027

71-
```bash
28+
```shell
7229
nix build -f default.nix $pkg.components.library
7330
```
7431

7532
to build the library for `$pkg` or
7633

77-
```bash
34+
```shell
7835
nix build -f default.nix $pkg.components.exes.$exe
7936
```
8037

@@ -85,7 +42,7 @@ to build a specific executable. The same holds for test suites and benchmarks.
8542
With [nix-tools installed](./installing-nix-tools.md), we can simply run the
8643
following command on a stack project:
8744

88-
```bash
45+
```shell
8946
stack-to-nix --output . --stack-yaml stack.yaml
9047
```
9148

@@ -121,34 +78,36 @@ about how to choose a specific compiler version.
12178

12279
[compiler]: https://nixos.org/nixpkgs/manual/#how-to-install-a-compiler
12380

124-
!!! note "Cabal version"
125-
The minimum Cabal version is 2.4. This version is available
126-
in the NixOS 19.03 release.
81+
> **Note:** Cabal version
82+
>
83+
> The minimum Cabal version is 2.4. This version is available
84+
> in the NixOS 19.03 release.
12785
12886
For this example, we will run a `nix-shell` with the default GHC
12987
version for Nixpkgs.
13088

131-
```bash
89+
```shell
13290
nix-shell -p haskellPackages.cabal-install haskellPackages.ghc \
13391
--run "cabal new-configure"
13492
```
13593

13694
If all goes well, you should now have the file
13795
`dist-newstyle/cache/plan.json`.
13896

139-
!!! tip "Specifying the GHC version"
140-
To use a specific compiler version, replace `haskellPackages.ghc`
141-
with something like `haskell-nix.compiler.ghc865`. The given compiler
142-
must exist in your Nixpkgs version, of course. See also the
143-
[Nixpkgs Manual][compiler].
97+
> **Tip:** Specifying the GHC version
98+
>
99+
> To use a specific compiler version, replace `haskellPackages.ghc`
100+
> with something like `haskell-nix.compiler.ghc865`. The given compiler
101+
> must exist in your Nixpkgs version, of course. See also the
102+
> [Nixpkgs Manual][compiler].
144103
145104
### Using `plan-to-nix`
146105

147106
With [nix-tools installed](./installing-nix-tools.md), we can then run the
148107
following command on a Cabal project and its build plan. Omit the
149108
`--cabal-project` option if you don't have a project file.
150109

151-
```bash
110+
```shell
152111
# convert the plan.json file into a pkgs.nix file
153112
plan-to-nix --output . \
154113
--plan-json dist-newstyle/cache/plan.json
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# default.nix
2+
let
3+
# Import the Haskell.nix library,
4+
pkgs = import <nixpkgs> (import (builtins.fetchTarball "https://github.com/input-output-hk/haskell.nix/archive/master.tar.gz") {}).nixpkgsArgs;
5+
6+
# Import the file you will create in the stack-to-nix or cabal-to-nix step.
7+
my-pkgs = import ./pkgs.nix;
8+
9+
# Stack projects use this:
10+
# pkgSet = pkgs.haskell-nix.mkStackPkgSet {
11+
# stack-pkgs = my-pkgs;
12+
# pkg-def-extras = [
13+
# # these extras will provide additional packages
14+
# # ontop of the package set. E.g. extra-deps
15+
# # for stack packages. or local packages for
16+
# # cabal.projects
17+
# ];
18+
# modules = [
19+
# # specific package overrides would go here
20+
# # example:
21+
# # packages.cbors.package.ghcOptions = "-Werror";
22+
# # packages.cbors.patches = [ ./one.patch ];
23+
# # packages.cbors.flags.optimize-gmp = false;
24+
# # It may be better to set flags in stack.yaml instead
25+
# # (`stack-to-nix` will include them as defaults).
26+
# ];
27+
# };
28+
29+
# Cabal projects use this:
30+
pkgSet = pkgs.haskell-nix.mkCabalProjectPkgSet {
31+
plan-pkgs = my-pkgs;
32+
pkg-def-extras = [];
33+
modules = [
34+
# specific package overrides would go here
35+
# example:
36+
# packages.cbors.package.ghcOptions = "-Werror";
37+
# packages.cbors.patches = [ ./one.patch ];
38+
# packages.cbors.flags.optimize-gmp = false;
39+
# It may be better to set flags in `cabal.project` instead
40+
# (`plan-to-nix` will include them as defaults).
41+
];
42+
};
43+
44+
in pkgSet.config.hsPkgs // { _config = pkgSet.config; }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# FIXME

docs/dev/nix-tools-pin.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
## How to update [`nix-tools`](https://github.com/input-output-hk/nix-tools)
22

33
1. Use niv to update the sources.json:
4-
```
4+
```shell
55
nix flake lock --update-input nix-tools
66
```
77

88
2. If `nix-tools.cabal` or `plan-to-nix` have changed, check the
99
materialized files for each of the compiler nix name in
1010
`ls -d materialized/ghc*/nix-tools` with:
11-
```
11+
```shell
1212
nix-build scripts/check-compiler-materialization --argstr compiler-nix-name ghc884
1313
```

0 commit comments

Comments
 (0)