on iko/ghcjs-patch-master help sign in
Add haskellLib.collectComponents (#224)
d4869aaRodney Lorrimar
@@ -1,6 +1,9 @@
1This file contains a summary of changes to Haskell.nix and `nix-tools`
1This file contains a summary of changes to Haskell.nix and `nix-tools`
2that will impact users.
2that will impact users.
3
3
4+## August 9, 2019
5+ * Add the [`haskellLib.collectComponents`](https://input-output-hk.github.io/haskell.nix/reference/library/#haskellLib) function.
6+
4## June 21, 2019
7## June 21, 2019
5 * Add `ghcWithPackages` and `ghcWithHoogle` to hsPkgs ([documentation](https://input-output-hk.github.io/haskell.nix/reference/library/#package-set-functions).
8 * Add `ghcWithPackages` and `ghcWithHoogle` to hsPkgs ([documentation](https://input-output-hk.github.io/haskell.nix/reference/library/#package-set-functions).
6 * Benchmark components can now build successfully.
9 * Benchmark components can now build successfully.
docs/reference/library.md+45−5
@@ -73,7 +73,7 @@ components = {
73 all = COMPONENT;
73 all = COMPONENT;
74}
74}
75```
75```
76−
76+
77## Component
77## Component
78
78
79In [Haskell.nix][], a _component_ is a derivation corresponding to a
79In [Haskell.nix][], a _component_ is a derivation corresponding to a
@@ -104,7 +104,7 @@ set. They are either:
104If using the function form of a module, the following named parameters
104If using the function form of a module, the following named parameters
105will be passed to it:
105will be passed to it:
106
106
107−| Argument | Type | Description |
107+| Argument | Type | Description |
108|------------------|------|---------------------|
108|------------------|------|---------------------|
109| `haskellLib` | attrset | The [haskellLib](#haskelllib) utility functions. |
109| `haskellLib` | attrset | The [haskellLib](#haskelllib) utility functions. |
110| `pkgs` | | The Nixpkgs collection. |
110| `pkgs` | | The Nixpkgs collection. |
@@ -126,7 +126,7 @@ mkStackPkgSet =
126 { stack-pkgs, pkg-def-extras ? [], modules ? []}: ...
126 { stack-pkgs, pkg-def-extras ? [], modules ? []}: ...
127```
127```
128
128
129−| Argument | Type | Description |
129+| Argument | Type | Description |
130|------------------|------|---------------------|
130|------------------|------|---------------------|
131| `stack-pkgs` | | `import ./pkgs.nix` — The imported file generated by `stack‑to‑nix`. |
131| `stack-pkgs` | | `import ./pkgs.nix` — The imported file generated by `stack‑to‑nix`. |
132| `pkg‑def‑extras` | List of [Extras](#extras) | For overriding the package set. |
132| `pkg‑def‑extras` | List of [Extras](#extras) | For overriding the package set. |
@@ -144,7 +144,7 @@ mkCabalProjectPkgSet =
144 { plan-pkgs, pkg-def-extras ? [], modules ? []}: ...
144 { plan-pkgs, pkg-def-extras ? [], modules ? []}: ...
145```
145```
146
146
147−| Argument | Type | Description |
147+| Argument | Type | Description |
148|------------------|------|---------------------|
148|------------------|------|---------------------|
149| `plan-pkgs` | | `import ./pkgs.nix` — The imported file generated by `plan‑to‑nix`. |
149| `plan-pkgs` | | `import ./pkgs.nix` — The imported file generated by `plan‑to‑nix`. |
150| `pkg‑def‑extras` | List of [Extras](#extras) | For overriding the package set. |
150| `pkg‑def‑extras` | List of [Extras](#extras) | For overriding the package set. |
@@ -192,6 +192,46 @@ Assorted functions for operating on [Haskell.nix][] data. This is
192distinct from `pkgs.haskell.lib` in the current Nixpkgs Haskell
192distinct from `pkgs.haskell.lib` in the current Nixpkgs Haskell
193Infrastructure.
193Infrastructure.
194
194
195+### collectComponents
196+
197+Extracts a selection of components from a Haskell [package set](#package-set).
198+
199+This can be used to filter out all test suites or benchmarks of
200+your project, so that they can be built in Hydra.
201+
202+```
203+collectComponents =
204+ group: packageSel: haskellPackages: ...
205+```
206+
207+
208+| Argument | Type | Description |
209+|-------------------|--------|---------------------|
210+| `group` | String | A [sub-component type](#subComponentTypes). |
211+| `packageSel` | A function `Package -> Bool` | A predicate to filter packages with. |
212+| `haskellPackages` | [Package set](#package-set) | All packages in the build. |
213+
214+**Return value**: a recursive attrset mapping package names → component names → components.
215+
216+**Example**:
217+
218+```nix
219+tests = collectComponents "tests" (package: package.identifier.name == "mypackage") hsPkgs;
220+```
221+
222+Will result in moving derivations from `hsPkgs.mypackage.components.tests.unit-tests`
223+to `tests.mypackage.unit-tests`.
224+
225+#### subComponentTypes
226+
227+Sub-component types identify [components](#component) and are one of:
228+
229+ - `sublibs`
230+ - `foreignlibs`
231+ - `exes`
232+ - `tests`
233+ - `benchmarks`
234+
195# Package-set functions
235# Package-set functions
196
236
197These functions exist within the `hsPkgs` package set.
237These functions exist within the `hsPkgs` package set.
@@ -208,7 +248,7 @@ shellFor =
208```
248```
209
249
210
250
211−| Argument | Type | Description |
251+| Argument | Type | Description |
212|----------------|------|---------------------|
252|----------------|------|---------------------|
213| `packages` | Function | Package selection function. It takes a list of [Haskell packages](#haskell-package) and returns a subset of these packages. |
253| `packages` | Function | Package selection function. It takes a list of [Haskell packages](#haskell-package) and returns a subset of these packages. |
214| `withHoogle` | Boolean | Whether to build a Hoogle documentation index and provide the `hoogle` command. |
254| `withHoogle` | Boolean | Whether to build a Hoogle documentation index and provide the `hoogle` command. |
lib/default.nix+18
@@ -94,4 +94,22 @@ with haskellLib;
94 operator = {val,...}: makePairs val.config.depends;
94 operator = {val,...}: makePairs val.config.depends;
95 };
95 };
96 in map ({val,...}: val) closure;
96 in map ({val,...}: val) closure;
97+
98+ # Extracts a selection of components from a Haskell package set.
99+ #
100+ # This can be used to filter out all test suites or benchmarks of
101+ # your project, so that they can be built in Hydra.
102+ #
103+ # For example:
104+ #
105+ # tests = collectComponents "tests" (package: package.identifier.name == "mypackage") hsPkgs;
106+ #
107+ # Will result in moving:
108+ # from: hsPkgs.mypackage.components.tests.unit-tests
109+ # to: tests.mypackage.unit-tests
110+ #
111+ collectComponents = group: packageSel: haskellPackages:
112+ (mapAttrs (_: package: package.components.${group} // { recurseForDerivations = true; })
113+ (filterAttrs (name: package: (package.isHaskell or false) && packageSel package) haskellPackages))
114+ // { recurseForDerivations = true; };
97}
115}