Skip to content

Commit

Permalink
settings: add removeReferencesTo
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
  • Loading branch information
shivaraj-bh committed Feb 13, 2024
1 parent c301f31 commit 0ebb195
Showing 1 changed file with 22 additions and 0 deletions.
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 0ebb195

Please sign in to comment.