From 0ebb19509e64a51c5cd6f86a32e3c859f40c8941 Mon Sep 17 00:00:00 2001 From: shivaraj-bh Date: Tue, 13 Feb 2024 11:29:01 +0530 Subject: [PATCH] settings: add removeReferencesTo 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 --- nix/modules/project/settings/all.nix | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/nix/modules/project/settings/all.nix b/nix/modules/project/settings/all.nix index a1a9c663..e5e2ad86 100644 --- a/nix/modules/project/settings/all.nix +++ b/nix/modules/project/settings/all.nix @@ -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;