Skip to content

Commit ce1a3fc

Browse files
committed
Use mkAliasDefinitions to copy package overrides
1 parent 3f721cf commit ce1a3fc

File tree

11 files changed

+31
-50
lines changed

11 files changed

+31
-50
lines changed

lib/default.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,4 +614,6 @@ in {
614614
}";
615615

616616
types = import ./types.nix { inherit lib; };
617+
618+
addPackageKeys = x: x // { package-keys = builtins.attrNames x.packages; };
617619
}

modules/component-driver.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{ config, pkgs, lib, haskellLib, buildModules, ... }:
1+
{ config, options, pkgs, lib, haskellLib, buildModules, ... }:
22
let
33
builder = haskellLib.weakCallPackage pkgs ../builder {
44
inherit haskellLib;
@@ -120,6 +120,6 @@ in
120120
pkgsBuildBuild = buildModules.config.hsPkgs;
121121
} //
122122
lib.mapAttrs
123-
(_name: pkg: if pkg == null then null else builder.build-package config pkg)
123+
(name: pkg: if !(options.packages.${name}.isDefined or true) || pkg == null then null else builder.build-package config pkg)
124124
(config.packages // lib.genAttrs (config.nonReinstallablePkgs ++ config.bootPkgs) (_: null));
125125
}

modules/configuration-nix.nix

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ let
1414
if builtins.compareVersions version v >= 0
1515
then patch
1616
else null;
17-
in {
17+
addPackageKeys = x: x // { package-keys = builtins.attrNames x.packages; };
18+
in addPackageKeys {
1819
# terminfo doesn't list libtinfo in its cabal file. We could ignore
1920
# this if we used the terminfo shipped with GHC, but this package is
2021
# reinstallable so we'd rather have it defined in the plan.

modules/plan.nix

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,22 @@ in
2929
# combined or replaced. We seed the package Options with an empty set forcing the
3030
# default values.
3131
options = {
32-
packages = mkOption {
33-
type = attrsOf package;
32+
use-package-keys = mkOption {
33+
type = bool;
34+
default = false;
3435
};
35-
36+
package-keys = mkOption {
37+
type = listOf str;
38+
default = [];
39+
};
40+
packages = if !config.use-package-keys
41+
then mkOption {
42+
type = attrsOf package;
43+
}
44+
else genAttrs config.package-keys (n:
45+
mkOption {
46+
type = package;
47+
});
3648
compiler = {
3749
version = mkOption {
3850
type = str;
@@ -61,7 +73,11 @@ in
6173
};
6274
};
6375

64-
config = let module = config.plan.pkg-def config.hackage.configs; in {
76+
config =
77+
let
78+
module = config.plan.pkg-def config.hackage.configs;
79+
addPackageKeys = x: x // { package-keys = builtins.attrNames x.packages; };
80+
in addPackageKeys {
6581
inherit (module) compiler;
6682
packages = lib.mapAttrs (name: { revision, ... }@revArgs: { system, compiler, flags, pkgs, hsPkgs, errorHandler, pkgconfPkgs, ... }@modArgs:
6783

overlays/haskell.nix

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -788,28 +788,12 @@ final: prev: {
788788
] ++ final.lib.optionals (builtins.compareVersions config.compiler.version "8.11" < 0) [
789789
"ghcjs-prim" "ghcjs-th"]);
790790
})
791-
({config, ...}: {
791+
({config, options, ...}: {
792+
use-package-keys = true;
793+
package-keys = map (p: p.pkg-name) plan-json.install-plan ++ map (p: to-key p) plan-json.install-plan;
792794
packages = final.lib.listToAttrs (map (p: {
793795
name = to-key p;
794-
value = {
795-
components = final.lib.optionalAttrs (config.packages ? ${p.pkg-name}) (
796-
let
797-
inherit (config.packages.${p.pkg-name}) components;
798-
mapOptions = c:
799-
builtins.mapAttrs (_: x: final.lib.mkOverride 990 x)
800-
(builtins.removeAttrs c ["buildable" "planned" "depends" "build-tools" "libs"]) //
801-
builtins.mapAttrs (_n: x: final.lib.mkOverride 90 x) (
802-
final.lib.filterAttrs (n: x: builtins.elem n ["depends" "build-tools" "libs"] && builtins.length x != 0) c);
803-
in
804-
final.lib.optionalAttrs (components.library or null != null) {
805-
library = mapOptions components.library;
806-
} // final.lib.optionalAttrs (components.setup or null != null) {
807-
setup = mapOptions components.setup;
808-
} // builtins.mapAttrs (_ctype: cs: builtins.mapAttrs (_cname: c: mapOptions c) cs) (builtins.removeAttrs components ["library" "setup"]));
809-
} // builtins.mapAttrs (n: _:
810-
final.lib.mkIf (config.packages ? ${p.pkg-name}) (final.lib.mkOverride (if n == "src" then (if config.packages.${p.pkg-name}.src != null then 90 else 10000) else 995) config.packages.${p.pkg-name}.${n}))
811-
((import ../modules/package-options.nix { inherit haskellLib; inherit (final) lib; }).options //
812-
(import ../modules/component-options.nix { inherit haskellLib; inherit (final) lib; }).options // { src = {}; });
796+
value = final.lib.modules.mkAliasDefinitions (options.packages.${p.pkg-name});
813797
}) (final.lib.filter (p: to-key p != p.pkg-name) plan-json.install-plan));
814798
})
815799
({lib, ...}: {

overlays/windows.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ final: prev:
5656
# Therefore let's enable doCrossCheck here!
5757
doCrossCheck = pkgs.stdenv.hostPlatform.isWindows;
5858
};
59-
in {
59+
in prev.haskell-nix.haskellLib.addPackageKeys {
6060
packages = {
6161

6262
# Apply https://github.com/haskell/cabal/pull/6055

test/coverage-no-libs/default.nix

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ let
66
projectArgs = {
77
inherit evalPackages;
88
src = testSrc "coverage-no-libs";
9-
modules = [{
10-
# Package has no exposed modules which causes
11-
# haddock: No input file(s)
12-
packages.bytestring-builder.doHaddock = false;
13-
}];
149
};
1510

1611
# We can easily select a different compiler when using cabal,

test/coverage/default.nix

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ let
88
src = testSrc "coverage";
99
cabalProjectLocal = builtins.readFile ../cabal.project.local;
1010
modules = [{
11-
# Package has no exposed modules which causes
12-
# haddock: No input file(s)
13-
packages.bytestring-builder.doHaddock = false;
14-
1511
# Coverage
1612
packages.pkga.components.library.doCoverage = true;
1713
packages.pkgb.components.library.doCoverage = true;

test/setup-deps/default.nix

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ let
88
inherit compiler-nix-name evalPackages;
99
src = evalPackages.haskell-nix.haskellLib.cleanGit { src = ../..; name = "setup-deps"; subDir = "test/setup-deps"; };
1010
cabalProjectLocal = builtins.readFile ../cabal.project.local;
11-
modules = [{
12-
# Package has no exposed modules which causes
13-
# haddock: No input file(s)
14-
packages.bytestring-builder.doHaddock = false;
15-
}];
1611
};
1712

1813
meta = {

test/shell-for-setup-deps/default.nix

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@ let
77
inherit compiler-nix-name evalPackages;
88
src = testSrc "shell-for-setup-deps";
99
cabalProjectLocal = builtins.readFile ../cabal.project.local;
10-
modules = [{
11-
# Package has no exposed modules which causes
12-
# haddock: No input file(s)
13-
packages.bytestring-builder.doHaddock = false;
14-
}];
1510
};
1611

1712
env = project.shellFor {

0 commit comments

Comments
 (0)