Skip to content

Commit 141187a

Browse files
committed
Merge remote-tracking branch 'origin/master' into hpc-patch
# Conflicts: # lib/cover-project.nix
2 parents 8eaceea + 2aca501 commit 141187a

File tree

534 files changed

+79988
-1812
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

534 files changed

+79988
-1812
lines changed

.buildkite/pipeline.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,15 @@ steps:
3838
command:
3939
- nix-build build.nix -A maintainer-scripts.check-path-support --argstr compiler-nix-name ghc8107 -o check-path-support.sh
4040
- ./check-path-support.sh
41+
42+
- label: 'Check that the haskell.nix roots do not require IFDs'
43+
command:
44+
- nix build .#roots.x86_64-linux --option allow-import-from-derivation false
45+
agents:
46+
system: x86_64-linux
47+
48+
- label: 'Check that evaluation of hydra jobs works without using remote builders'
49+
command:
50+
- nix-instantiate release.nix -A required-unstable-ghc8107-x86_64-darwin-native --show-trace --builders ''
51+
agents:
52+
system: x86_64-linux

.envrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use flake

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ docs/reference/modules.md
66
result*
77
/nt
88

9+
# https://github.com/nix-community/nix-direnv
10+
.direnv
11+
912
# Created by https://www.gitignore.io/api/haskell,emacs,vim
1013

1114
### Emacs ###

build.nix

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ in
88
{ nixpkgs ? haskellNix.sources.nixpkgs-2111
99
, nixpkgsArgs ? haskellNix.nixpkgsArgs
1010
, pkgs ? import nixpkgs nixpkgsArgs
11+
, evalPackages ? import nixpkgs nixpkgsArgs
1112
, nixpkgsForHydra ? haskellNix.sources.nixpkgs-2105
12-
, pkgsForHydra ? import nixpkgsForHydra nixpkgsArgs
13+
, pkgsForHydra ? import nixpkgsForHydra (nixpkgsArgs // { inherit (pkgs) system; })
1314
, ifdLevel ? 1000
1415
, compiler-nix-name ? throw "No `compiler-nix-name` passed to build.nix"
1516
}:
@@ -19,14 +20,21 @@ let
1920
buildHaskell = pkgs.buildPackages.haskell-nix;
2021
tool = buildHaskell.tool;
2122
in rec {
22-
tests = import ./test/default.nix { inherit pkgs ifdLevel compiler-nix-name; };
23+
tests = import ./test/default.nix { inherit pkgs evalPackages ifdLevel compiler-nix-name; };
2324

2425
tools = pkgs.lib.optionalAttrs (ifdLevel >= 3) (
2526
pkgs.recurseIntoAttrs ({
26-
cabal-latest = tool compiler-nix-name "cabal" "latest";
27-
} // pkgs.lib.optionalAttrs (!__elem compiler-nix-name ["ghc901" "ghc902" "ghc921" "ghc922"]) {
28-
hls-latest = tool compiler-nix-name "haskell-language-server" "latest";
29-
hlint-latest = tool compiler-nix-name "hlint" (if compiler-nix-name == "ghc865" then "3.2.7" else "latest");
27+
cabal-latest = tool compiler-nix-name "cabal" { inherit evalPackages; };
28+
hlint-latest = tool compiler-nix-name "hlint" {
29+
inherit evalPackages;
30+
version = {
31+
"ghc865" = "3.2.8";
32+
"ghc882" = "3.3.6";
33+
"ghc883" = "3.3.6";
34+
"ghc884" = "3.3.6";
35+
}.compiler-nix-name or "latest";
36+
};
37+
hls-latest = tool compiler-nix-name "haskell-language-server" { inherit evalPackages; };
3038
})
3139
);
3240

@@ -78,7 +86,7 @@ in rec {
7886
# These are pure parts of maintainer-script so they can be built by hydra
7987
# and added to the cache to speed up buildkite.
8088
maintainer-script-cache = pkgs.recurseIntoAttrs (
81-
(pkgs.lib.optionalAttrs pkgs.stdenv.hostPlatform.isLinux {
89+
(pkgs.lib.optionalAttrs (pkgsForHydra.system == "x86_64-linux") {
8290
inherit (maintainer-scripts) check-hydra;
8391
})
8492
// (pkgs.lib.optionalAttrs (ifdLevel > 2) {

builder/comp-builder.nix

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ let self =
5050
, writeHieFiles ? component.writeHieFiles
5151

5252
, ghcOptions ? component.ghcOptions
53+
, contentAddressed ? component.contentAddressed
5354

5455
# Options for Haddock generation
5556
, doHaddock ? component.doHaddock # Enable haddock and hoogle generation
@@ -99,9 +100,10 @@ let
99100
&& !stdenv.hostPlatform.isMusl
100101
&& builtins.compareVersions defaults.ghc.version "8.10.2" >= 0;
101102

102-
ghc = if enableDWARF then defaults.ghc.dwarf else
103-
if smallAddressSpace then defaults.ghc.smallAddressSpace else defaults.ghc;
104-
setup = if enableDWARF then drvArgs.setup.dwarf else drvArgs.setup;
103+
ghc = (if enableDWARF then (x: x.dwarf) else (x: x)) (
104+
(if smallAddressSpace then (x: x.smallAddressSpace) else (x: x)) defaults.ghc);
105+
setup = (if enableDWARF then (x: x.dwarf) else (x: x)) (
106+
(if smallAddressSpace then (x: x.smallAddressSpace) else (x: x)) drvArgs.setup);
105107

106108
# TODO fix cabal wildcard support so hpack wildcards can be mapped to cabal wildcards
107109
canCleanSource = !(cabal-generator == "hpack" && !(package.cleanHpack or false));
@@ -315,7 +317,13 @@ let
315317
componentDrv = drv;
316318
};
317319

318-
drv = stdenv.mkDerivation (commonAttrs // {
320+
contentAddressedAttrs = lib.optionalAttrs contentAddressed {
321+
__contentAddressed = true;
322+
outputHashMode = "recursive";
323+
outputHashAlgo = "sha256";
324+
};
325+
326+
drv = stdenv.mkDerivation (commonAttrs // contentAddressedAttrs // {
319327
pname = nameOnly;
320328
inherit (package.identifier) version;
321329

@@ -348,6 +356,14 @@ let
348356
description = package.synopsis or "";
349357
license = haskellLib.cabalToNixpkgsLicense package.license;
350358
platforms = if platforms == null then lib.platforms.all else platforms;
359+
} // lib.optionalAttrs (haskellLib.isExecutableType componentId) {
360+
# Set main executable name for executable components, so that `nix run` in
361+
# nix flakes will work correctly. When not set, `nix run` would (typically
362+
# erroneously) deduce the executable name from the derivation name and
363+
# attempt to run, for example,
364+
# `/nix/store/...-project-exe-app-0.1.0.0/bin/project-exe-app` instead of
365+
# `/nix/store/...-project-exe-app-0.1.0.0/bin/app`.
366+
mainProgram = exeName;
351367
};
352368

353369
propagatedBuildInputs =
@@ -404,7 +420,17 @@ let
404420
(lib.optionalString stdenv.hostPlatform.isWindows ''
405421
export pkgsHostTargetAsString="''${pkgsHostTarget[@]}"
406422
'') +
407-
(if stdenv.hostPlatform.isGhcjs then ''
423+
# The following could be refactored but would lead to many rebuilds
424+
425+
# In case of content addressed components we need avoid parallel building (passing -j1)
426+
# in order to have a deterministic output and therefore avoid potential situations
427+
# where the binary cache becomes useless
428+
# See also https://gitlab.haskell.org/ghc/ghc/-/issues/12935
429+
(if contentAddressed then ''
430+
runHook preBuild
431+
$SETUP_HS build ${haskellLib.componentTarget componentId} -j1 ${lib.concatStringsSep " " setupBuildFlags}
432+
runHook postBuild
433+
'' else if stdenv.hostPlatform.isGhcjs then ''
408434
runHook preBuild
409435
# https://gitlab.haskell.org/ghc/ghc/issues/9221
410436
$SETUP_HS build ${haskellLib.componentTarget componentId} ${lib.concatStringsSep " " setupBuildFlags}

builder/default.nix

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{ pkgs, buildPackages, stdenv, lib, haskellLib, ghc, compiler-nix-name, fetchurl, pkgconfig, nonReinstallablePkgs, hsPkgs, compiler }:
1+
{ pkgs, buildPackages, evalPackages, stdenv, lib, haskellLib, ghc, compiler-nix-name, fetchurl, pkgconfig, nonReinstallablePkgs, hsPkgs, compiler }:
22

33
let
44
# Builds a single component of a package.
@@ -46,6 +46,7 @@ let
4646
hoogleLocal = let
4747
nixpkgsHoogle = import (pkgs.path + /pkgs/development/haskell-modules/hoogle.nix);
4848
in { packages ? [], hoogle ? pkgs.buildPackages.haskell-nix.tool "ghc8107" "hoogle" {
49+
inherit evalPackages;
4950
version = "5.0.18.3";
5051
index-state = pkgs.haskell-nix.internalHackageIndexState;
5152
}
@@ -66,7 +67,7 @@ let
6667

6768
# Same as haskellPackages.shellFor in nixpkgs.
6869
shellFor = haskellLib.weakCallPackage pkgs ./shell-for.nix {
69-
inherit hsPkgs ghcForComponent makeConfigFiles hoogleLocal haskellLib buildPackages compiler;
70+
inherit hsPkgs ghcForComponent makeConfigFiles hoogleLocal haskellLib buildPackages evalPackages compiler;
7071
inherit (buildPackages) glibcLocales;
7172
};
7273

builder/hspkg-builder.nix

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -39,41 +39,28 @@ let
3939

4040
defaultSetupSrc = if stdenv.hostPlatform.isGhcjs then ./Setup.ghcjs.hs else ./Setup.hs;
4141

42-
# Get the Cabal lib used to build `cabal-install`.
43-
# To avoid infinite recursion we have to leave this out for packages
44-
# needed to build `cabal-install`.
45-
# We always do this for ghcjs as the patched version of Cabal is needed.
46-
cabalLibDepends = lib.optional (
47-
stdenv.hostPlatform.isGhcjs || (
48-
builtins.elem compiler-nix-name["ghc865" "ghc884"]
49-
&&
50-
!builtins.elem package.identifier.name
51-
["nix-tools" "alex" "happy" "hscolour" "Cabal" "bytestring" "aeson" "time"
52-
"filepath" "base-compat-batteries" "base-compat" "unix" "directory" "transformers"
53-
"containers" "binary" "mtl" "text" "process" "parsec"]
54-
)
55-
)
56-
buildPackages.haskell-nix.cabal-install-unchecked.${compiler-nix-name}.project.hsPkgs.Cabal.components.library;
42+
# This is the `Cabal` library that was built for `cabal-install` to use.
43+
# It makes sense to use this version (when possible) because it will match the behavior of
44+
# building with `cabal-install` (including fixes that may not be in the
45+
# version of Cabal bundled with GHC).
46+
cabalFromCabalInstall = buildPackages.haskell-nix.cabal-install-unchecked.${compiler-nix-name}.project.hsPkgs.Cabal.components.library;
5747

58-
# This logic is needed so that we don't get duplicate packages if we
59-
# add a custom Cabal package to the dependencies. That way custom
60-
# setups won't complain about e.g. binary from the Cabal dependencies
61-
# and binary from the global package-db.
62-
nonReinstallablePkgs = if (
63-
stdenv.hostPlatform.isGhcjs || (
64-
builtins.elem compiler-nix-name["ghc865" "ghc884"]
65-
&&
48+
# Check there is no chance we are building `cabalFromCabalInstall`. Using `cabalFromCabalInstall`
49+
# to build itseld would cause infinite recursion.
50+
useCabalFromCabalInstall =
51+
# `cabalFromCabalInstall` is not cross compiled
52+
stdenv.buildPlatform != stdenv.hostPlatform
53+
||
54+
# These are the dependencies of `Cabal`
6655
!builtins.elem package.identifier.name
6756
["nix-tools" "alex" "happy" "hscolour" "Cabal" "bytestring" "aeson" "time"
6857
"filepath" "base-compat-batteries" "base-compat" "unix" "directory" "transformers"
69-
"containers" "binary" "mtl" "text" "process" "parsec"]
70-
)
71-
) then [] else null;
58+
"containers" "binary" "mtl" "text" "process" "parsec"];
7259

7360
defaultSetup = setup-builder ({
7461
name = "${ghc.targetPrefix}default-Setup";
7562
component = {
76-
depends = config.setup-depends ++ cabalLibDepends;
63+
depends = config.setup-depends ++ lib.optional useCabalFromCabalInstall cabalFromCabalInstall;
7764
libs = [];
7865
frameworks = [];
7966
doExactConfig = false;
@@ -107,7 +94,13 @@ let
10794
cat ${defaultSetupSrc} > $out/Setup.hs
10895
'';
10996
inherit defaultSetupSrc;
110-
} // (if nonReinstallablePkgs == null then {} else { inherit nonReinstallablePkgs; }));
97+
} // lib.optionalAttrs useCabalFromCabalInstall {
98+
# This is needed so that we don't get duplicate packages when we
99+
# add a custom Cabal package to the dependencies. That way custom
100+
# setups won't complain about e.g. binary from the Cabal dependencies
101+
# and binary from the global package-db.
102+
nonReinstallablePkgs = [];
103+
});
111104

112105
# buildPackages.runCommand "default-Setup" { nativeBuildInputs = [(ghc.passthru.buildGHC or ghc)]; } ''
113106
# cat ${defaultSetupSrc} > Setup.hs
@@ -138,7 +131,7 @@ in rec {
138131
checks = pkgs.recurseIntoAttrs (builtins.mapAttrs
139132
(_: d: haskellLib.check d)
140133
(lib.filterAttrs (_: d: d.config.doCheck) components.tests));
141-
inherit (package) identifier detailLevel isLocal isProject;
134+
inherit (package) identifier detailLevel isLocal isProject buildType;
142135
inherit setup cabalFile;
143136
isHaskell = true;
144137
inherit src;

builder/make-config-files.nix

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ let
1111

1212
flagsAndConfig = field: xs: lib.optionalString (xs != []) ''
1313
echo ${lib.concatStringsSep " " (map (x: "--${field}=${x}") xs)} >> $out/configure-flags
14-
echo "${field}: ${lib.concatStringsSep " " xs}" >> $out/cabal.config
14+
${lib.concatStrings (map (x: ''
15+
echo "${field}: ${x}" >> $out/cabal.config
16+
'') xs)}
1517
'';
1618

1719
target-pkg = "${ghc.targetPrefix}ghc-pkg";
@@ -91,7 +93,8 @@ let
9193
(map (p: "${lib.getBin p}/bin")
9294
(lib.flatten component.libs ++ lib.concatLists component.pkgconfig));
9395
"extra-include-dirs" = map (p: "${lib.getDev p}/include") (lib.flatten component.libs);
94-
"extra-framework-dirs" = map (p: "${p}/Library/Frameworks") component.frameworks;
96+
"extra-framework-dirs" = lib.optionals (stdenv.hostPlatform.isDarwin)
97+
(map (p: "${p}/Library/Frameworks") component.frameworks);
9598
})}
9699
97100
ghc=${ghc}
@@ -126,8 +129,11 @@ let
126129
done
127130
128131
${ # Note: we pass `clear` first to ensure that we never consult the implicit global package db.
129-
flagsAndConfig "package-db" ["clear" "$out/${packageCfgDir}"]
132+
# However in `cabal.config` `cabal` requires `global` to be first.
133+
flagsAndConfig "package-db" ["clear"]
130134
}
135+
echo "package-db: global" >> $out/cabal.config
136+
${ flagsAndConfig "package-db" ["$out/${packageCfgDir}"] }
131137
132138
echo ${lib.concatStringsSep " " (lib.mapAttrsToList (fname: val: "--flags=${lib.optionalString (!val) "-" + fname}") flags)} >> $out/configure-flags
133139

builder/setup-builder.nix

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@ let self =
88
, preInstall ? component.preInstall , postInstall ? component.postInstall
99
, cleanSrc ? haskellLib.cleanCabalComponent package component "setup" src
1010
, nonReinstallablePkgs ? defaults.nonReinstallablePkgs
11+
, smallAddressSpace ? false
1112
}@drvArgs:
1213

1314
let
15+
ghc = (if enableDWARF then (x: x.dwarf) else (x: x)) (
16+
(if smallAddressSpace then (x: x.smallAddressSpace) else (x: x)) defaults.ghc);
17+
1418
cleanSrc' = haskellLib.rootAndSubDir cleanSrc;
1519

1620
fullName = "${name}-setup";
@@ -53,6 +57,7 @@ let
5357
cleanSrc = cleanSrc';
5458
inherit configFiles;
5559
dwarf = self (drvArgs // { enableDWARF = true; });
60+
smallAddressSpace = self (drvArgs // { smallAddressSpace = true; });
5661
};
5762

5863
meta = {
@@ -71,13 +76,12 @@ let
7176
for f in Setup.hs Setup.lhs; do
7277
if [ -f $f ]; then
7378
echo Compiling package $f
74-
ghc $f -threaded '' + (if includeGhcPackage then "-package ghc " else "")
75-
+ ''-package-db ${configFiles}/${configFiles.packageCfgDir} --make -o ./Setup
76-
setup=$(pwd)/Setup
79+
ghc $f -threaded ${if includeGhcPackage then "-package ghc " else ""
80+
}-package-db ${configFiles}/${configFiles.packageCfgDir} --make -o ./Setup
7781
fi
7882
done
7983
[ -f ./Setup ] || (echo Failed to build Setup && exit 1)
80-
runHook preBuild
84+
runHook postBuild
8185
'';
8286

8387
installPhase = ''

builder/shell-for.nix

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{ lib, stdenv, mkShell, glibcLocales, pkgconfig, ghcForComponent, makeConfigFiles, hsPkgs, hoogleLocal, haskellLib, buildPackages, compiler }:
1+
{ lib, stdenv, mkShell, glibcLocales, pkgconfig, ghcForComponent, makeConfigFiles, hsPkgs, hoogleLocal, haskellLib, buildPackages, evalPackages, compiler }:
22

33
{ # `packages` function selects packages that will be worked on in the shell itself.
44
# These packages will not be built by `shellFor`, but their
@@ -71,14 +71,19 @@ let
7171
removeSelectedInputs =
7272
lib.filter (input: !(isSelectedComponent input));
7373

74-
# The configs of all the selected components
74+
# The configs of all the selected components.
75+
# This excludes the `setup` dependencies of `Simple` packages, because
76+
# `cabal-install` does not build a `Setup` executable for `Simple` packages.
7577
selectedConfigs = map (c: c.config) selectedComponents
76-
++ lib.optionals packageSetupDeps (map (p: p.setup.config) selectedPackages);
78+
++ lib.optionals packageSetupDeps (map (p: p.setup.config)
79+
(lib.filter (p: p.buildType != "Simple") selectedPackages));
7780

78-
name = if lib.length selectedPackages == 1
81+
identifierName = if lib.length selectedPackages == 1
7982
then "ghc-shell-for-${(lib.head selectedPackages).identifier.name}"
8083
else "ghc-shell-for-packages";
8184

85+
name = if (mkDrvArgs.name or null) == null then identifierName else mkDrvArgs.name;
86+
8287
# We need to remove any dependencies which would bring in selected components (see above).
8388
packageInputs = removeSelectedInputs (lib.concatMap (cfg: cfg.depends) selectedConfigs)
8489
++ additionalPackages;
@@ -101,14 +106,14 @@ let
101106
doExactConfig = false;
102107
};
103108
configFiles = makeConfigFiles {
104-
fullName = args.name or name;
105-
identifier.name = name;
109+
fullName = name;
110+
identifier.name = identifierName;
106111
inherit component enableDWARF;
107112
chooseDrv = p: if withHaddock && p ? haddock then p.haddock else p;
108113
};
109114
ghcEnv = ghcForComponent {
110115
inherit configFiles;
111-
componentName = name;
116+
componentName = identifierName;
112117
postInstall = lib.optionalString withHoogle' ''
113118
ln -s ${hoogleIndex}/bin/hoogle $out/bin
114119
'';
@@ -130,21 +135,26 @@ let
130135
# inherit (hsPkgs) hoogle;
131136
} // (
132137
lib.optionalAttrs (args ? tools && args.tools ? hoogle) {
133-
hoogle = buildPackages.haskell-nix.tool compiler.nix-name "hoogle" args.tools.hoogle;
138+
hoogle = buildPackages.haskell-nix.hackage-tool (
139+
haskellLib.versionOrModToMods args.tools.hoogle ++ [{
140+
name = "hoogle";
141+
compiler-nix-name = compiler.nix-name;
142+
inherit evalPackages;
143+
}]);
134144
}
135145
));
136146

137147
mkDrvArgs = builtins.removeAttrs args ["packages" "components" "additional" "withHoogle" "tools"];
138148
in
139149
mkShell (mkDrvArgs // {
140-
name = mkDrvArgs.name or name;
150+
inherit name;
141151

142152
buildInputs = systemInputs
143153
++ mkDrvArgs.buildInputs or [];
144154
nativeBuildInputs = [ ghcEnv ]
145155
++ nativeBuildInputs
146156
++ mkDrvArgs.nativeBuildInputs or []
147-
++ lib.attrValues (buildPackages.haskell-nix.tools compiler.nix-name tools)
157+
++ lib.attrValues (buildPackages.haskell-nix.tools' evalPackages compiler.nix-name tools)
148158
# If this shell is a cross compilation shell include
149159
# wrapper script for running cabal build with appropriate args.
150160
# Includes `--with-compiler` in case the `cabal.project` file has `with-compiler:` in it.

0 commit comments

Comments
 (0)