Skip to content

Commit

Permalink
Per component pre-exisiting depends
Browse files Browse the repository at this point in the history
  • Loading branch information
hamishmack committed Aug 19, 2024
1 parent cfe3bf2 commit 278df11
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
5 changes: 3 additions & 2 deletions builder/make-config-files.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
let
# Sort and remove duplicates from nonReinstallablePkgs.
# That way changes to the order of nonReinstallablePkgs does not require rebuilds.
nonReinstallablePkgs' = __attrNames (lib.genAttrs nonReinstallablePkgs (x: x));
nonReinstallablePkgs' = __attrNames (lib.genAttrs nonReinstallablePkgs (x: x))
++ lib.filter (x: builtins.isString x) component.depends;

ghc = if enableDWARF then defaults.ghc.dwarf else defaults.ghc;

Expand Down Expand Up @@ -55,7 +56,7 @@ let
map chooseDrv (
(if enableDWARF then (x: map (p: p.dwarf or p) x) else x: x)
((if needsProfiling then (x: map (p: p.profiled or p) x) else x: x)
(map haskellLib.dependToLib component.depends))
(map haskellLib.dependToLib (lib.filter (x: !builtins.isString x) component.depends)))
)
);
script = ''
Expand Down
35 changes: 22 additions & 13 deletions overlays/haskell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -650,13 +650,24 @@ final: prev: {
builtins.unsafeDiscardStringContext (
builtins.readFile (callProjectResults.projectNix + "/plan.json")));
by-id = final.lib.listToAttrs (map (x: { name = x.id; value = x; }) plan-json.install-plan);
to-key = p: if p.type == "pre-existing"
then p.pkg-name
else p.id;
lookupPreExisting = depends:
final.lib.concatMap (d: builtins.attrNames pre-existing-depends.${d}) depends;
pre-existing-depends =
final.lib.listToAttrs (map (p: {
name = p.id;
value = final.lib.optionalAttrs (p.type == "pre-existing") { ${p.pkg-name} = null; } //
final.lib.listToAttrs (
map (dname: { name = dname; value = null; }) (lookupPreExisting (p.depends or p.components.lib.depends)));
}) plan-json.install-plan);
to-key = p: p.id;
lookupDependency = hsPkgs: d:
if by-id.${d}.component-name or "lib" == "lib"
then hsPkgs.${to-key by-id.${d}} or hsPkgs.${by-id.${d}.pkg-name}
else hsPkgs.${to-key by-id.${d}}.components.sublibs.${final.lib.removePrefix "lib:" by-id.${d}.component-name};
final.lib.optional (by-id.${d}.type != "pre-existing") (
if by-id.${d}.component-name or "lib" == "lib"
then hsPkgs.${to-key by-id.${d}} or hsPkgs.${by-id.${d}.pkg-name}
else hsPkgs.${to-key by-id.${d}}.components.sublibs.${final.lib.removePrefix "lib:" by-id.${d}.component-name});
lookupDependencies = hsPkgs: depends:
final.lib.concatMap (lookupDependency hsPkgs) depends
++ lookupPreExisting depends;
lookupExeDependency = hsPkgs: d:
# Try to lookup by ID, but if that fails use the name (currently a different plan is used by pkgsBuildBuild when cross compiling)
(hsPkgs.pkgsBuildBuild.${to-key by-id.${d}} or hsPkgs.pkgsBuildBuild.${by-id.${d}.pkg-name}).components.exes.${final.lib.removePrefix "exe:" by-id.${d}.component-name};
Expand All @@ -670,7 +681,7 @@ final: prev: {
name = final.lib.removePrefix "${prefix}:" n;
value = (if cabal2nixComponents == null then {} else cabal2nixComponents.${collectionName}.${name}) // {
buildable = true;
depends = map (lookupDependency hsPkgs) c.depends;
depends = lookupDependencies hsPkgs c.depends;
build-tools = map lookupExeDependency c.exe-depends;
};
in { inherit name value; }
Expand All @@ -680,7 +691,7 @@ final: prev: {
// final.lib.optionalAttrs (components ? lib) {
library = (if cabal2nixComponents == null then {} else cabal2nixComponents.library) // {
buildable = true;
depends = map (lookupDependency hsPkgs) components.lib.depends;
depends = lookupDependencies hsPkgs components.lib.depends;
build-tools = map (lookupExeDependency hsPkgs) components.lib.exe-depends;
};
};
Expand Down Expand Up @@ -721,7 +732,7 @@ final: prev: {
package = cabal2nix.package // {
identifier = { name = p.pkg-name; version = p.pkg-version; };
isProject = false;
setup-depends = map (lookupDependency hsPkgs.pkgsBuildBuild) (p.components.setup.depends or []);
setup-depends = lookupDependencies hsPkgs.pkgsBuildBuild (p.components.setup.depends or []);
# TODO = map (lookupExeDependency hsPkgs.pkgsBuildBuild) (p.components.setup.exe-depends or []);
};
};
Expand Down Expand Up @@ -751,16 +762,14 @@ final: prev: {
package = cabal2nix.package // {
identifier = { name = p.pkg-name; version = p.pkg-version; };
isProject = true;
setup-depends = map (lookupDependency hsPkgs.pkgsBuildBuild) (p.components.setup.depends or []);
setup-depends = lookupDependencies hsPkgs.pkgsBuildBuild (p.components.setup.depends or []);
# TODO = map (lookupExeDependency hsPkgs.pkgsBuildBuild) (p.components.setup.exe-depends or []);
};
};
}) plan-json.install-plan);
});
modules = [{
preExistingPkgs =
final.lib.concatMap (p:
final.lib.optional (p.type == "pre-existing") p.pkg-name) plan-json.install-plan;
preExistingPkgs = [];
}
({config, ...}: {
packages = final.lib.listToAttrs (map (p: {
Expand Down

0 comments on commit 278df11

Please sign in to comment.