Skip to content

Commit 275e162

Browse files
committed
Merge master into hkm/avoid-defaults
# Conflicts: # lib/call-stack-to-nix.nix # lib/stack-cache-generator.nix # overlays/haskell.nix
2 parents 46fd628 + 4dbc429 commit 275e162

File tree

16 files changed

+134
-42
lines changed

16 files changed

+134
-42
lines changed

builder/haddock-builder.nix

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,23 +83,26 @@ let
8383
++ componentDrv.executableToolDepends;
8484

8585
configurePhase = ''
86+
runHook preConfigure
8687
echo Configure flags:
8788
printf "%q " ${finalConfigureFlags}
8889
echo
8990
$SETUP_HS configure ${finalConfigureFlags}
91+
runHook postConfigure
9092
'';
9193

9294
buildPhase = ''
9395
mkdir -p $out
9496
'' + lib.optionalString doHaddock' ''
9597
runHook preHaddock
96-
# If we don't have any source files, no need to run haddock
97-
[[ -n $(find . -name "*.hs" -o -name "*.lhs") ]] && {
98+
9899
docdir="${docdir "$doc"}"
99-
# This mkdir needed for packages like bytestring-builder which
100-
# is empty when `bytestring >= 0.10.4`
100+
# This mkdir needed for packages like base-noprelude and bytestring-builder
101+
# (which is also empty when `bytestring >= 0.10.4`)
101102
mkdir -p "$docdir"
102103
104+
# If we don't have any source files, no need to run haddock
105+
[[ -n $(find . -name "*.hs" -o -name "*.lhs") ]] && {
103106
$SETUP_HS haddock \
104107
"--html" \
105108
${lib.optionalString doHoogle "--hoogle"} \

builder/shell-for.nix

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,12 @@ let
3535
removeSelectedInputs = lib.filter
3636
(input: lib.all (cfg: input != cfg.components.library or null) selected);
3737

38-
packageInputs = removeSelected
39-
(lib.concatMap (cfg: cfg.depends) selectedConfigs
40-
++ additionalSelected
41-
++ lib.concatMap (cfg: cfg.setup.config.depends or []) selected
42-
);
38+
packageInputs =
39+
removeSelected
40+
(lib.concatMap (cfg: cfg.depends) selectedConfigs
41+
++ lib.concatMap (cfg: cfg.setup.config.depends or []) selected
42+
)
43+
++ additionalSelected;
4344

4445
# Add the system libraries and build tools of the selected haskell
4546
# packages to the shell.

docs/tutorials/development.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ your Haskell package dependencies, but also the required system
44
libraries and build tools.
55

66
Inside the development shell, you can run commands such as `ghc`,
7-
`ghci`, or `cabal new‑build`, and they will have all dependencies
8-
available.
7+
`ghci`, or `cabal new‑build` (`cabal build` on Cabal 3.0),
8+
and they will have all dependencies available.
99

1010
Every dependency will be cached in your Nix store. If you have set up
1111
Hydra CI, then your team can share pre-built dependencies.
@@ -21,7 +21,8 @@ it exists in a file called `default.nix`.
2121
rebuild all dependencies, even though they are available in the
2222
shell. However, if you have a Stack project, you can generate the
2323
package set with Haskell.nix, then use `cabal new‑build` to work
24-
on it.
24+
on it. Starting Cabal 3.0 `cabal build` will work out of the box, as
25+
new style builds are the default.
2526

2627
## How to get a development shell for a package
2728

hackage-src.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"url": "https://github.com/input-output-hk/hackage.nix",
3-
"rev": "b7a2bd2c740648e7bf96b9e2d0a57ca402daf2df",
4-
"date": "2020-07-01T01:15:16+00:00",
5-
"sha256": "0rj1xa7wbgix7nc3kmw9477k47skdw9skbsky6vjnyrybkgffljr",
3+
"rev": "2845992effbeb7adcd2389a264ecfdabbeea83ba",
4+
"date": "2020-07-06T01:15:12+00:00",
5+
"sha256": "0pdvh781qxqr0a62v0nwdp7agd8n6l6ilbd17zvlzblw1a5arzqv",
66
"fetchSubmodules": false
77
}

lib/call-stack-to-nix.nix

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,27 @@
55
*
66
* see also `call-cabal-project-to-nix`!
77
*/
8-
{ runCommand, pkgs, mkCacheFile, materialize }:
8+
{ runCommand, pkgs, mkCacheFile, materialize, haskellLib }:
99
{ name ? src.name or null # optional name for better error messages
1010
, src
11-
, stackYaml ? null
11+
, stackYaml ? "stack.yaml"
1212
, ignorePackageYaml ? false
1313
, cache ? null
1414
, stack-sha256 ? null
15+
, resolverSha256 ? null
1516
, materialized ? null # Location of a materialized copy of the nix files
1617
, checkMaterialization ? null # If true the nix files will be generated used to check plan-sha256 and material
1718
, nix-tools ? pkgs.haskell-nix.nix-tools.${pkgs.haskell-nix.defaultCompilerNixNameTODO}
1819
, ... }:
1920
let
21+
inherit (haskellLib.fetchResolver {
22+
inherit src stackYaml resolverSha256;
23+
}) resolver fetchedResolver;
24+
2025
subDir' = src.origSubDir or "";
2126
stackToNixArgs = builtins.concatStringsSep " " [
2227
"--full"
23-
"--stack-yaml=${src}/${if stackYaml == null then "stack.yaml" else stackYaml}"
28+
"--stack-yaml=$SRC/${stackYaml}"
2429
(if ignorePackageYaml then "--ignore-package-yaml" else "")
2530
"-o ."
2631
];
@@ -32,23 +37,40 @@ let
3237
} // pkgs.lib.optionalAttrs (checkMaterialization != null) {
3338
inherit checkMaterialization;
3439
}) (runCommand (if name == null then "stack-to-nix-pkgs" else name + "-stack-to-nix-pkgs") {
35-
nativeBuildInputs = [ nix-tools pkgs.nix-prefetch-git pkgs.cacert ];
40+
nativeBuildInputs = [ nix-tools pkgs.nix-prefetch-git pkgs.cacert pkgs.xorg.lndir ];
3641
# Needed or stack-to-nix will die on unicode inputs
3742
LOCALE_ARCHIVE = pkgs.lib.optionalString (pkgs.stdenv.hostPlatform.libc == "glibc") "${pkgs.glibcLocales}/lib/locale/locale-archive";
3843
LANG = "en_US.UTF-8";
3944
LC_ALL = "en_US.UTF-8";
4045
preferLocalBuild = false;
4146
} (''
4247
mkdir -p $out${subDir'}
43-
'' + pkgs.lib.optionalString (cache != null) ''
44-
cp ${mkCacheFile cache}/.stack-to-nix.cache* $out${subDir'}
45-
'' + ''
48+
${
49+
# If no resolver was fetched use the original stack.yaml
50+
if fetchedResolver == null
51+
then ''
52+
SRC=${src}
53+
''
54+
else
55+
# Replace the resolver path in the stack.yaml with the fetched version
56+
''
57+
SRC=$(mktemp -d)
58+
cd $SRC
59+
lndir -silent "${src}/." $SRC
60+
rm ${stackYaml}
61+
cp ${src}/${stackYaml} .
62+
chmod +w ${stackYaml}
63+
substituteInPlace ${stackYaml} --replace "${resolver}" "${fetchedResolver}"
64+
''}
65+
${pkgs.lib.optionalString (cache != null) ''
66+
cp ${mkCacheFile cache}/.stack-to-nix.cache* $out${subDir'}
67+
''}
4668
(cd $out${subDir'} && stack-to-nix ${stackToNixArgs})
4769
4870
# We need to strip out any references to $src, as those won't
4971
# be accessable in restricted mode.
5072
for nixf in $(find $out -name "*.nix" -type f); do
51-
substituteInPlace $nixf --replace "${src}" "."
73+
substituteInPlace $nixf --replace "$SRC" "."
5274
done
5375
5476
# move pkgs.nix to default.nix ensure we can just nix `import` the result.

lib/default.nix

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,4 +261,9 @@ in {
261261
if lib.isAttrs versionOrArgs
262262
then versionOrArgs
263263
else { version = versionOrArgs; };
264+
265+
# Find the resolver in the stack.yaml file and fetch it if a sha256 value is provided
266+
fetchResolver = import ./fetch-resolver.nix {
267+
inherit (pkgs.evalPackages) pkgs;
268+
};
264269
}

lib/fetch-resolver.nix

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Find the resolver in the stack.yaml file and fetch it if a sha256 value is provided
2+
{ pkgs }:
3+
{ src
4+
, stackYaml ? "stack.yaml"
5+
, resolverSha256 ? null
6+
}:
7+
let
8+
# Using origSrcSubDir bypasses any cleanSourceWith so that it will work when
9+
# access to the store is restricted. If origSrc was already in the store
10+
# you can pass the project in as a string.
11+
rawStackYaml = builtins.readFile ((src.origSrcSubDir or src) + ("/" + stackYaml));
12+
13+
# Determine the resolver as it may point to another file we need
14+
# to look at.
15+
resolver =
16+
let
17+
rs = pkgs.lib.lists.concatLists (
18+
pkgs.lib.lists.filter (l: l != null)
19+
(builtins.map (l: builtins.match "^resolver: *(.*)" l)
20+
(pkgs.lib.splitString "\n" rawStackYaml)));
21+
in
22+
pkgs.lib.lists.head (rs ++ [ null ]);
23+
24+
# If we found a resolver andwe have a resolverSha256 then we should download it.
25+
fetchedResolver =
26+
if resolver != null && resolverSha256 != null
27+
then pkgs.fetchurl {
28+
url = resolver;
29+
sha256 = resolverSha256;
30+
}
31+
else null;
32+
33+
in { inherit resolver fetchedResolver; }

lib/stack-cache-generator.nix

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
if sha256map != null
1414
then { location, tag, ...}: sha256map."${location}"."${tag}"
1515
else _: null
16+
, resolverSha256 ? null
1617
, checkMaterialization ? null
1718
, compiler-nix-name ? pkgs.haskell-nix.defaultCompilerNixNameTODO # We should get this from stack.yaml
1819
, nix-tools ? pkgs.haskell-nix.nix-tools-set {
@@ -25,21 +26,9 @@ let
2526
# we want to avoid recalculating the cache unless the stack.yaml file
2627
# changes.
2728

28-
# Using origSrcSubDir bypasses any cleanSourceWith so that it will work when
29-
# access to the store is restricted. If origSrc was already in the store
30-
# you can pass the project in as a string.
31-
rawStackYaml = builtins.readFile ((src.origSrcSubDir or src) + ("/" + stackYaml));
32-
33-
# Determine the resolver as it may point to another file we need
34-
# to look at.
35-
resolver =
36-
let
37-
rs = pkgs.lib.lists.concatLists (
38-
pkgs.lib.lists.filter (l: l != null)
39-
(builtins.map (l: builtins.match "^resolver: *(.*)" l)
40-
(pkgs.lib.splitString "\n" rawStackYaml)));
41-
in
42-
pkgs.lib.lists.head (rs ++ [ null ]);
29+
inherit (haskellLib.fetchResolver {
30+
inherit src stackYaml resolverSha256;
31+
}) resolver fetchedResolver;
4332

4433
# Filter just the stack yaml file and any reolver yaml file it points to.
4534
maybeCleanedSource =
@@ -63,6 +52,9 @@ let
6352
cp -r "${maybeCleanedSource}/." $TMP
6453
chmod -R +w $TMP
6554
substituteInPlace ${stackYaml} --replace "# nix-sha256:" "nix-sha256:"
55+
${pkgs.lib.optionalString (fetchedResolver != null) ''
56+
substituteInPlace ${stackYaml} --replace "${resolver}" "${fetchedResolver}"
57+
''}
6658
stack-repos --stack-yaml ${stackYaml}
6759
cp repos.json $out
6860
''));

overlays/haskell.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ final: prev: {
264264
callStackToNix = import ../lib/call-stack-to-nix.nix {
265265
pkgs = final.evalPackages.pkgs;
266266
inherit (final.evalPackages.pkgs) runCommand;
267-
inherit (final.evalPackages.haskell-nix) mkCacheFile materialize;
267+
inherit (final.evalPackages.haskell-nix) mkCacheFile materialize haskellLib;
268268
};
269269

270270
# given a source location call `cabal-to-nix` (from nix-tools) on it

stackage-src.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"url": "https://github.com/input-output-hk/stackage.nix",
3-
"rev": "66d07956ef302c9c5e9c1e6011dd275b862cd597",
4-
"date": "2020-06-29T01:02:37+00:00",
5-
"sha256": "1a803n2257mmaz98rhzxb1a8cbdhiaqls3gwxqnrw1zhc9f785pp",
3+
"rev": "2fc823c8e70858d0b41d8df2615bcab83d85a1bc",
4+
"date": "2020-07-06T01:02:55+00:00",
5+
"sha256": "1322iip8038f8fqh46gpk3r6jnd4v19hsnka1mkf3hpj0rvyffzz",
66
"fetchSubmodules": false
77
}

test/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ let
159159
builder-haddock = callTest ./builder-haddock {};
160160
stack-simple = callTest ./stack-simple {};
161161
stack-local-resolver = callTest ./stack-local-resolver {};
162+
stack-remote-resolver = callTest ./stack-remote-resolver {};
162163
snapshots = callTest ./snapshots {};
163164
shell-for = callTest ./shell-for {};
164165
shell-for-setup-deps = callTest ./shell-for-setup-deps { inherit compiler-nix-name; };

test/stack-remote-resolver/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/.stack-work/
2+
/*.cabal
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{ project', recurseIntoAttrs, testSrc }:
2+
3+
let
4+
project = project' {
5+
src = testSrc "stack-remote-resolver";
6+
resolverSha256 = "1rldkqqsxd8zxybrkqhc25bcxinhz212kz45jcz8jinfihc91jl7";
7+
};
8+
packages = project.hsPkgs;
9+
10+
in recurseIntoAttrs {
11+
ifdInputs = {
12+
inherit (project) stack-nix;
13+
};
14+
inherit (packages.stack-remote-resolver.components) library;
15+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
name: stack-remote-resolver
2+
3+
dependencies:
4+
- base
5+
6+
library:
7+
source-dirs: src

test/stack-remote-resolver/src/Lib.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module Lib
2+
( someFunc
3+
) where
4+
5+
someFunc :: IO ()
6+
someFunc = putStrLn "someFunc"

test/stack-remote-resolver/stack.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
resolver: https://raw.githubusercontent.com/input-output-hk/haskell.nix/master/test/stack-local-resolver/snapshot.yaml
2+
3+
packages:
4+
- .

0 commit comments

Comments
 (0)