settings: add removeReferencesTo (#225)

This setting helps remove unnecessary dependencies to your haskell package that
bloats up the final closure size

Source: 5623bb3814/nix/removeReferencesTo.nix (L9)


---------

Co-authored-by: Sridhar Ratnakumar <3998+srid@users.noreply.github.com>
Co-authored-by: Sridhar Ratnakumar <srid@srid.ca>
This commit is contained in:
Shivaraj B H 2024-02-13 20:19:51 +05:30 committed by GitHub
parent 88715ebf33
commit 5113f700d6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 35 additions and 1 deletions

View File

@ -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

View File

@ -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

View File

@ -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;