Skip to content

Commit 7595b61

Browse files
committed
Add pre-existing to component module
1 parent c69b53f commit 7595b61

File tree

3 files changed

+22
-17
lines changed

3 files changed

+22
-17
lines changed

builder/make-config-files.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ let
66
# Sort and remove duplicates from nonReinstallablePkgs.
77
# That way changes to the order of nonReinstallablePkgs does not require rebuilds.
88
nonReinstallablePkgs' = __attrNames (lib.genAttrs nonReinstallablePkgs (x: x))
9-
++ lib.filter (x: builtins.isString x) component.depends;
9+
++ component.pre-existing or [];
1010

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

@@ -56,7 +56,7 @@ let
5656
map chooseDrv (
5757
(if enableDWARF then (x: map (p: p.dwarf or p) x) else x: x)
5858
((if needsProfiling then (x: map (p: p.profiled or p) x) else x: x)
59-
(map haskellLib.dependToLib (lib.filter (x: !builtins.isString x) component.depends)))
59+
(map haskellLib.dependToLib component.depends))
6060
)
6161
);
6262
script = ''

modules/component.nix

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ in
3838
default = [ ];
3939
};
4040

41+
pre-existing = lib.mkOption {
42+
type = types.listOf types.str;
43+
default = [ ];
44+
};
45+
4146
libs = lib.mkOption {
4247
type = listOfFilteringNulls (types.either (types.nullOr types.package) (listOfFilteringNulls types.package));
4348
default = [ ];

overlays/haskell.nix

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -665,12 +665,14 @@ final: prev: {
665665
if by-id.${d}.component-name or "lib" == "lib"
666666
then hsPkgs.${to-key by-id.${d}} or hsPkgs.${by-id.${d}.pkg-name}
667667
else hsPkgs.${to-key by-id.${d}}.components.sublibs.${final.lib.removePrefix "lib:" by-id.${d}.component-name});
668-
lookupDependencies = hsPkgs: depends:
669-
final.lib.concatMap (lookupDependency hsPkgs) depends
670-
++ lookupPreExisting depends;
671668
lookupExeDependency = hsPkgs: d:
672669
# Try to lookup by ID, but if that fails use the name (currently a different plan is used by pkgsBuildBuild when cross compiling)
673670
(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};
671+
lookupDependencies = hsPkgs: depends: exe-depends: {
672+
depends = final.lib.concatMap (lookupDependency hsPkgs) depends;
673+
pre-existing = lookupPreExisting depends;
674+
build-tools = map (lookupExeDependency hsPkgs) exe-depends;
675+
};
674676
getComponents = cabal2nixComponents: hsPkgs: p:
675677
let
676678
components = p.components or { ${p.component-name or "lib"} = { inherit (p) depends; exe-depends = p.exe-depends or []; }; };
@@ -681,19 +683,19 @@ final: prev: {
681683
name = final.lib.removePrefix "${prefix}:" n;
682684
value = (if cabal2nixComponents == null then {} else cabal2nixComponents.${collectionName}.${name}) // {
683685
buildable = true;
684-
depends = lookupDependencies hsPkgs c.depends;
685-
build-tools = map lookupExeDependency c.exe-depends;
686-
};
686+
} // lookupDependencies hsPkgs c.depends c.exe-depends;
687687
in { inherit name value; }
688688
)) components));
689689
in
690690
final.lib.mapAttrs componentsWithPrefix haskellLib.componentPrefix
691691
// final.lib.optionalAttrs (components ? lib) {
692692
library = (if cabal2nixComponents == null then {} else cabal2nixComponents.library) // {
693693
buildable = true;
694-
depends = lookupDependencies hsPkgs components.lib.depends;
695-
build-tools = map (lookupExeDependency hsPkgs) components.lib.exe-depends;
696-
};
694+
} // lookupDependencies hsPkgs components.lib.depends components.lib.exe-depends;
695+
} // final.lib.optionalAttrs (components ? setup) {
696+
setup = {
697+
buildable = true;
698+
} // lookupDependencies hsPkgs (components.setup.depends or []) (components.setup.exe-depends or []);
697699
};
698700
callProjectResults = callCabalProjectToNix config;
699701
nixFilesDir = callProjectResults.projectNix + callProjectResults.src.origSubDir or "";
@@ -732,8 +734,7 @@ final: prev: {
732734
package = cabal2nix.package // {
733735
identifier = { name = p.pkg-name; version = p.pkg-version; };
734736
isProject = false;
735-
setup-depends = lookupDependencies hsPkgs.pkgsBuildBuild (p.components.setup.depends or []);
736-
# TODO = map (lookupExeDependency hsPkgs.pkgsBuildBuild) (p.components.setup.exe-depends or []);
737+
setup-depends = [];
737738
};
738739
};
739740
}) plan-json.install-plan);
@@ -762,8 +763,7 @@ final: prev: {
762763
package = cabal2nix.package // {
763764
identifier = { name = p.pkg-name; version = p.pkg-version; };
764765
isProject = true;
765-
setup-depends = lookupDependencies hsPkgs.pkgsBuildBuild (p.components.setup.depends or []);
766-
# TODO = map (lookupExeDependency hsPkgs.pkgsBuildBuild) (p.components.setup.exe-depends or []);
766+
setup-depends = [];
767767
};
768768
};
769769
}) plan-json.install-plan);
@@ -803,7 +803,7 @@ final: prev: {
803803
in {
804804
name = to-key p;
805805
value.components = final.lib.mapAttrs (type: x:
806-
if type == "library"
806+
if type == "library" || type == "setup"
807807
then { planned = lib.mkOverride 900 true; }
808808
else
809809
final.lib.mapAttrs (_: _: {
@@ -835,7 +835,7 @@ final: prev: {
835835
else config.hsPkgs.${(builtins.head available).id}.components.${collectionName}.${name};
836836
componentsWithPrefix = collectionName: prefix:
837837
final.lib.listToAttrs (final.lib.concatLists (final.lib.mapAttrsToList (n: available:
838-
final.lib.optional (final.lib.hasPrefix "${prefix}:" n && (builtins.length available != 1 || builtins.head available != "TargetNotBuildable")) (
838+
final.lib.optional (final.lib.hasPrefix "${prefix}:" n && (builtins.length available != 1 || !builtins.elem (builtins.head available) ["TargetNotBuildable" "TargetNotLocal"])) (
839839
let
840840
name = final.lib.removePrefix "${prefix}:" n;
841841
value = lookupComponent collectionName name available;

0 commit comments

Comments
 (0)