Skip to content

Commit

Permalink
settings: add removeReferencesTo (#225)
Browse files Browse the repository at this point in the history
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 <3998+srid@users.noreply.github.com>
Co-authored-by: Sridhar Ratnakumar <srid@srid.ca>
  • Loading branch information
3 people authored Feb 13, 2024
1 parent 88715eb commit 5113f70
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

- #210: Add `extraLibraries` to `settings` module.
- #225: settings: add `removeReferencesTo`
- #215: Improved debug logging.
- #216: Remove `debug` option (pass `--trace-verbose` to nix instead)
- Fixes
Expand Down
13 changes: 12 additions & 1 deletion doc/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,18 @@ haskellProjects.default = {

## Custom settings {#custom}

- [Emanote overrides](https://github.com/srid/emanote/commit/5b24bd04f94e03afe66ee01da723e4a05d854953): demonstrates how to add a *new* setting option (`removeReferencesTo`).
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`).

## Extra settings {#extra}

haskell-flake provides the following settings on top of those provided by [nixpkgs].

### `removeReferencesTo`

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.

> [!info] For more, see
> - https://github.com/NixOS/nixpkgs/pull/204675
> - https://srid.ca/remove-references-to
[nixpkgs]: https://nixos.asia/en/nixpkgs
22 changes: 22 additions & 0 deletions nix/modules/project/settings/all.nix
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,28 @@ in
impl = triggerRebuild;
};

removeReferencesTo = {
type = types.listOf types.package;
description = ''
Packages to remove references to.
This is useful to ditch unnecessary data dependencies from your Haskell
executable so as to reduce its closure size.
cf.
- https://github.com/NixOS/nixpkgs/pull/204675
- https://srid.ca/remove-references-to
'';
impl = disallowedReferences: drv:
drv.overrideAttrs (old: rec {
inherit disallowedReferences;
postInstall = (old.postInstall or "") + ''
${lib.concatStrings (map (e: "echo Removing reference to: ${e}\n") disallowedReferences)}
${lib.concatStrings (map (e: "remove-references-to -t ${e} $out/bin/*\n") disallowedReferences)}
'';
});
};

# When none of the above settings is suitable:
custom = {
type = types.functionTo types.package;
Expand Down

0 comments on commit 5113f70

Please sign in to comment.