Skip to content

Commit d1a3c56

Browse files
committed
WIP - Try two different ways of mkMerging component configs
1. Set a default value for the components.all option. 2. Add another module to merge component options for each package.
1 parent 5704909 commit d1a3c56

File tree

4 files changed

+57
-13
lines changed

4 files changed

+57
-13
lines changed

modules/all-component.nix

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{ lib, config, pkgs, ... }:
2+
3+
with lib;
4+
5+
############################################################################
6+
# this is an attempt to use mkMerge for combining package options
7+
############################################################################
8+
let
9+
haskellLib = let hl = import ../lib { inherit lib; haskellLib = hl; }; in hl;
10+
11+
subComponents = packageConfig: sub: attrValues (packageConfig.components.${sub} or {});
12+
13+
allComponent = packageConfig: {
14+
components.all = mkMerge ([ packageConfig.components.library ] ++
15+
concatMap (subComponents packageConfig) haskellLib.subComponentTypes);
16+
};
17+
18+
in {
19+
# Does not work -- infinite recursion
20+
# packages = mapAttrs (name: packageConfig: allComponent packageConfig) config.packages;
21+
22+
# A single package works
23+
# packages.cabal-simple = allComponent (config.packages.cabal-simple);
24+
}

modules/package.nix

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -175,18 +175,20 @@ in {
175175
type = attrsOf (componentType {});
176176
default = {};
177177
};
178+
# Try merging component options by setting the default to mkMerge [...].
179+
# This does not work.
178180
all = let
179-
subComponentsDepends = sub: concatLists
180-
(mapAttrsToList (_: c: c.depends or []) config.components.${sub} or {});
181-
default = {
182-
depends = config.components.library.depends ++
183-
concatMap subComponentsDepends haskellLib.subComponentTypes;
184-
};
181+
subComponents = sub: attrValues (config.components.${sub} or {});
182+
default = mkMerge ([ config.components.library ] ++
183+
concatMap subComponents haskellLib.subComponentTypes);
185184
in mkOption {
186-
type = componentType default;
185+
type = componentType {};
187186
inherit default;
188-
defaultText = "The merged dependencies of all other components";
187+
defaultText = "The merged options of all other components";
189188
};
189+
# all = mkOption {
190+
# type = componentType {};
191+
# };
190192
};
191193

192194
name = mkOption {

package-set.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ in pkgs.lib.evalModules {
7171
# Supplies metadata
7272
./modules/cabal.nix
7373

74+
./modules/all-component.nix
75+
7476
# Converts config.packages into config.hsPkgs
7577
# Replace this with compat-driver.nix to use nixpkgs haskell build infra
7678
./modules/component-driver.nix

test/with-packages/default.nix

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,33 @@ let
3939
buildInputs = (oldAttrs.buildInputs or []) ++ [ pkgs.cabal-install ];
4040
});
4141

42+
43+
package = packages.test-with-packages;
44+
inherit (package.components) library;
45+
46+
pkgId = p: "${p.identifier.name}-${p.identifier.version}";
47+
showDepends = component: concatMapStringsSep " " pkgId component.depends;
48+
4249
in
4350
stdenv.mkDerivation {
4451
name = "with-packages-test";
52+
libraryDepends = showDepends pkgSet.config.packages.test-with-packages.components.library;
53+
allDepends = showDepends pkgSet.config.packages.test-with-packages.components.all;
4554

46-
buildCommand = let
47-
package = packages.test-with-packages;
48-
inherit (package.components) library;
49-
in ''
55+
buildCommand = ''
5056
########################################################################
5157
# test with-packages
5258
59+
printf "checking merging of the 'all' component depends ... " >& 2
60+
if [ -n "$libraryDepends" -a "$libraryDepends" = "$allDepends" ]; then
61+
echo "PASS" >& 2
62+
else
63+
echo "FAIL" >& 2
64+
echo "libraryDepends = $libraryDepends"
65+
echo "allDepends = $allDepends"
66+
exit 1
67+
fi
68+
5369
printf "checking that the 'all' component works... " >& 2
5470
echo ${package.components.all} >& 2
5571
@@ -62,7 +78,7 @@ in
6278
6379
printf "checking that components.library.env has the dependencies... " >& 2
6480
${library.env}/bin/runghc ${./Point.hs}
65-
# echo >& 2
81+
echo >& 2
6682
6783
touch $out
6884
'';

0 commit comments

Comments
 (0)