Skip to content

Commit 5113f70

Browse files
shivaraj-bhsrid
andauthored
settings: add removeReferencesTo (#225)
This setting helps remove unnecessary dependencies to your haskell package that bloats up the final closure size Source: https://github.com/srid/emanote/blob/5623bb3814e382dfea7ffd21d3da25c2d3179001/nix/removeReferencesTo.nix#L9 --------- Co-authored-by: Sridhar Ratnakumar <[email protected]> Co-authored-by: Sridhar Ratnakumar <[email protected]>
1 parent 88715eb commit 5113f70

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Unreleased
44

55
- #210: Add `extraLibraries` to `settings` module.
6+
- #225: settings: add `removeReferencesTo`
67
- #215: Improved debug logging.
78
- #216: Remove `debug` option (pass `--trace-verbose` to nix instead)
89
- Fixes

doc/settings.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,18 @@ haskellProjects.default = {
4646

4747
## Custom settings {#custom}
4848

49-
- [Emanote overrides](https://github.com/srid/emanote/commit/5b24bd04f94e03afe66ee01da723e4a05d854953): demonstrates how to add a *new* setting option (`removeReferencesTo`).
49+
You can provide custom settings for use in multiple packages (even across multiple repos). For example, see [this Emanote change](https://github.com/srid/emanote/commit/5b24bd04f94e03afe66ee01da723e4a05d854953) which demonstrates how to add a *new* setting option (`removeReferencesTo`).
5050

51+
## Extra settings {#extra}
52+
53+
haskell-flake provides the following settings on top of those provided by [nixpkgs].
54+
55+
### `removeReferencesTo`
56+
57+
Remove references to other packages from this Haskell package. This is useful to eliminate unnecessary data dependencies from your Haskell executable so as to reduce its closure size.
58+
59+
> [!info] For more, see
60+
> - https://github.com/NixOS/nixpkgs/pull/204675
61+
> - https://srid.ca/remove-references-to
5162
5263
[nixpkgs]: https://nixos.asia/en/nixpkgs

nix/modules/project/settings/all.nix

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,28 @@ in
311311
impl = triggerRebuild;
312312
};
313313

314+
removeReferencesTo = {
315+
type = types.listOf types.package;
316+
description = ''
317+
Packages to remove references to.
318+
319+
This is useful to ditch unnecessary data dependencies from your Haskell
320+
executable so as to reduce its closure size.
321+
322+
cf.
323+
- https://github.com/NixOS/nixpkgs/pull/204675
324+
- https://srid.ca/remove-references-to
325+
'';
326+
impl = disallowedReferences: drv:
327+
drv.overrideAttrs (old: rec {
328+
inherit disallowedReferences;
329+
postInstall = (old.postInstall or "") + ''
330+
${lib.concatStrings (map (e: "echo Removing reference to: ${e}\n") disallowedReferences)}
331+
${lib.concatStrings (map (e: "remove-references-to -t ${e} $out/bin/*\n") disallowedReferences)}
332+
'';
333+
});
334+
};
335+
314336
# When none of the above settings is suitable:
315337
custom = {
316338
type = types.functionTo types.package;

0 commit comments

Comments
 (0)