From c1b64a3cee0c9e83dd8a01873df581fc91c2923e Mon Sep 17 00:00:00 2001 From: Teo Camarasu Date: Sun, 27 Jun 2021 12:37:49 +0100 Subject: [PATCH 1/2] factor out isSelectedComponent --- builder/shell-for.nix | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/builder/shell-for.nix b/builder/shell-for.nix index bafd0d7cc8..2daf161f56 100644 --- a/builder/shell-for.nix +++ b/builder/shell-for.nix @@ -55,19 +55,20 @@ let (builtins.map (x: lib.nameValuePair (x.name) x) (haskellLib.flatLibDepends {depends = directlySelectedComponents;})); + isSelectedComponent = + comp: selectedComponentsBitmap."${((haskellLib.dependToLib comp).name or null)}" or false; selectedComponentsBitmap = lib.mapAttrs - (_: x: (builtins.any - (dep: selectedComponentsBitmap."${(haskellLib.dependToLib dep).name}") x.config.depends)) + (_: x: (builtins.any isSelectedComponent x.config.depends)) transitiveDependenciesComponents // builtins.listToAttrs (map (x: lib.nameValuePair x.name true) directlySelectedComponents); # base case selectedComponents = - lib.filter (x: selectedComponentsBitmap."${x.name}") (lib.attrValues transitiveDependenciesComponents); + lib.filter isSelectedComponent (lib.attrValues transitiveDependenciesComponents); # Given a list of `depends`, removes those which are selected components removeSelectedInputs = - lib.filter (input: !(selectedComponentsBitmap."${((haskellLib.dependToLib input).name or null)}" or false)); + lib.filter (input: !(isSelectedComponent input)); # The configs of all the selected components selectedConfigs = map (c: c.config) selectedComponents From 2aecbef7ea089c5ab1765a10ccda41ad1bb08440 Mon Sep 17 00:00:00 2001 From: Teo Camarasu Date: Sun, 27 Jun 2021 12:39:35 +0100 Subject: [PATCH 2/2] Optimise `flatLibDepends` We no longer force the `outPath` attribute to avoid instantiating the derivation, which is expensive --- lib/default.nix | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/lib/default.nix b/lib/default.nix index 359367d512..92e9e77ba2 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -132,14 +132,7 @@ in { ## flatLibDepends :: Component -> [Package] flatLibDepends = component: let - # this is a minor improvement over the "cannot coerce set to string" - # error. It will now say: - # - # > The option `packages.Win32.package.identifier.name' is used but not defined. - # - # which indicates that the package.Win32 is missing and not defined. - getKey = x: if x ? "outPath" then "${x}" else (throw x.identifier.name); - makePairs = map (p: rec { key=getKey val; val=(p.components.library or p); }); + makePairs = map (p: rec { key=val.name; val=(p.components.library or p); }); closure = builtins.genericClosure { startSet = makePairs component.depends; operator = {val,...}: makePairs val.config.depends;