Skip to content

Remove internal deps on default ghc and stackage #738

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 43 commits into from
Jul 8, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
904dd76
Remove internal deps on default ghc and stackage
hamishmack Jul 1, 2020
fe86dcf
Merge remote-tracking branch 'origin/master' into hkm/avoid-defaults
hamishmack Jul 1, 2020
ee0cbc4
ifdLevel 1
hamishmack Jul 1, 2020
e22fff7
Set `"builtin": false` in sources.json
hamishmack Jul 1, 2020
f0a1490
Use nixpkgs instead of nixpkgs-default for niv
hamishmack Jul 1, 2020
eeff15e
Use nixpkgs instead of nixpkgs-default for niv
hamishmack Jul 2, 2020
30df20a
ifdLevel 2
hamishmack Jul 2, 2020
482a1a1
ifdLevel 3
hamishmack Jul 2, 2020
b367bf2
Update tests to make compiler-nix-name explicit
hamishmack Jul 3, 2020
52793cf
Fix for cabal-install on ghc 8.10.1
hamishmack Jul 3, 2020
70f7775
Fix build.nix
hamishmack Jul 3, 2020
dd704bd
Fix test
hamishmack Jul 3, 2020
cf4eeff
Add missing compiler-nix-name in ci.nix
hamishmack Jul 3, 2020
46fd628
Better warnings
hamishmack Jul 6, 2020
275e162
Merge master into hkm/avoid-defaults
hamishmack Jul 6, 2020
caa940f
Better warnings
hamishmack Jul 6, 2020
ba4e38e
Remove redundant tests
hamishmack Jul 6, 2020
d41b1c8
Add default for ./test/test.sh on buildkite
hamishmack Jul 6, 2020
926766a
Add cabal-nix-name default for buildkite tests
hamishmack Jul 6, 2020
da181b4
Add compiler-nix-name to script functions
hamishmack Jul 6, 2020
b30a9a1
Fix extra-hackage buildkite test
hamishmack Jul 6, 2020
de8cbb7
Check the materialization
hamishmack Jul 6, 2020
10055a1
Fix materialization
hamishmack Jul 6, 2020
74935bc
Fix eval time warnings
hamishmack Jul 6, 2020
bc2e42c
Fix hydra eval (maybe)
hamishmack Jul 6, 2020
1903f33
Materialization fixes
hamishmack Jul 6, 2020
1ef36f3
Another materialization fix
hamishmack Jul 6, 2020
7461041
Switch checkMaterialization off (tests passed)
hamishmack Jul 6, 2020
0661b4e
Update getting-started
hamishmack Jul 6, 2020
757b9a4
Remove deprecated code
hamishmack Jul 7, 2020
dfc49e2
Remove ./nixpkgs
hamishmack Jul 7, 2020
855089e
Remove ./nixpkgs
hamishmack Jul 7, 2020
c1bf1a3
Reenable call-stack-to-nix ifdInput test
hamishmack Jul 7, 2020
18311c4
Merge remote-tracking branch 'origin/master' into hkm/avoid-defaults
hamishmack Jul 7, 2020
4ec19da
Documentation and explicit test compiler-nix-names
hamishmack Jul 8, 2020
c0b401b
Add missing \
hamishmack Jul 8, 2020
7c1453c
Add compiler-nix-name for maintainer scripts test
hamishmack Jul 8, 2020
cb3d1c0
Move compiler-nix-name to the right command
hamishmack Jul 8, 2020
1be5755
Merge remote-tracking branch 'origin/master' into hkm/avoid-defaults
hamishmack Jul 8, 2020
b9345d2
Fix test
hamishmack Jul 8, 2020
4cebce4
Expand comment
hamishmack Jul 8, 2020
21fb517
Fix docs for callCabalProjectToNix
hamishmack Jul 8, 2020
eba7f1e
Set date
hamishmack Jul 8, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
steps:
- label: 'Run tests'
command: "./test/tests.sh"
- label: 'Run tests with ghc883'
command: "./test/tests.sh ghc883"
agents:
system: x86_64-linux

Expand All @@ -14,7 +14,7 @@ steps:
agents:
system: x86_64-linux

- label: 'Check closure size'
- label: 'Check closure size with ghc883'
command:
- nix-build build.nix -A maintainer-scripts.check-closure-size -o check-closure-size.sh
- echo "+++ Closure size (MB)"
Expand All @@ -24,7 +24,7 @@ steps:

- label: 'Update docs'
command:
- nix-build build.nix -A maintainer-scripts.update-docs -o update-docs.sh
- nix-build build.nix -A maintainer-scripts.update-docs --argstr compiler-nix-name ghc883 -o update-docs.sh
- ./update-docs.sh
agents:
system: x86_64-linux
Expand All @@ -36,5 +36,5 @@ steps:

- label: 'Make sure non store paths like can be used as src'
command:
- nix-build build.nix -A maintainer-scripts.check-path-support -o check-path-support.sh
- nix-build build.nix -A maintainer-scripts.check-path-support --argstr compiler-nix-name ghc883 -o check-path-support.sh
- ./check-path-support.sh
19 changes: 16 additions & 3 deletions build.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ in
, nixpkgsArgs ? haskellNix.nixpkgsArgs
, pkgs ? import nixpkgs nixpkgsArgs
, ifdLevel ? 1000
, compiler-nix-name ? "ghc865"
, compiler-nix-name ? throw "No `compiler-nix-name` passed to build.nix"
}:

let
Expand All @@ -33,8 +33,21 @@ in rec {
# as not all of them can work in restricted eval mode (as they
# are not pure).
maintainer-scripts = pkgs.dontRecurseIntoAttrs {
update-hackage = haskell.callPackage ./scripts/update-hackage.nix {};
update-stackage = haskell.callPackage ./scripts/update-stackage.nix {};
update-hackage = import ./scripts/update-hackage.nix {
inherit (pkgs) stdenv writeScript coreutils glibc git
openssh nix-prefetch-git gawk bash curl findutils;
# Update scripts use the internal nix-tools and cabal-install (compiled with a fixed GHC version)
nix-tools = haskell.internal-nix-tools;
cabal-install = haskell.internal-cabal-install;
inherit (haskell) update-index-state-hashes;
};
update-stackage = haskell.callPackage ./scripts/update-stackage.nix {
inherit (pkgs) stdenv writeScript coreutils glibc git
openssh nix-prefetch-git gawk bash curl findutils;
# Update scripts use the internal nix-tools and cabal-install (compiled with a fixed GHC version)
nix-tools = haskell.internal-nix-tools;
cabal-install = haskell.internal-cabal-install;
};
update-pins = haskell.callPackage ./scripts/update-pins.nix {};
update-docs = pkgs.buildPackages.callPackage ./scripts/update-docs.nix {
generatedOptions = pkgs.callPackage ./scripts/options-doc.nix { };
Expand Down
4 changes: 2 additions & 2 deletions lib/call-cabal-project-to-nix.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ in
, compiler-nix-name
, ghc ? null # Deprecated in favour of `compiler-nix-name`
, ghcOverride ? null # Used when we need to set ghc explicitly during bootstrapping
, nix-tools ? evalPackages.haskell-nix.nix-tools.${compiler-nix-name}
, cabal-install ? evalPackages.haskell-nix.cabal-install.${compiler-nix-name}
, nix-tools ? evalPackages.haskell-nix.nix-tools.${compiler-nix-name} # When building cabal projects we use the nix-tools
, cabal-install ? evalPackages.haskell-nix.cabal-install.${compiler-nix-name} # and cabal-install compiled with matching ghc version
, configureArgs ? "" # Extra arguments to pass to `cabal v2-configure`.
# `--enable-tests --enable-benchmarks` are included by default.
# If the tests and benchmarks are not needed and they
Expand Down
2 changes: 1 addition & 1 deletion lib/call-stack-to-nix.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
, resolverSha256 ? null
, materialized ? null # Location of a materialized copy of the nix files
, checkMaterialization ? null # If true the nix files will be generated used to check plan-sha256 and material
, nix-tools ? pkgs.haskell-nix.internal-nix-tools
, nix-tools ? pkgs.haskell-nix.internal-nix-tools # When building stack projects we use the internal nix-tools (compiled with a fixed GHC version)
, ... }:
let
inherit (haskellLib.fetchResolver {
Expand Down
2 changes: 1 addition & 1 deletion lib/stack-cache-generator.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
then { location, tag, ...}: sha256map."${location}"."${tag}"
else _: null
, resolverSha256 ? null
, nix-tools ? pkgs.haskell-nix.internal-nix-tools
, nix-tools ? pkgs.haskell-nix.internal-nix-tools # When building stack projects we use the internal nix-tools (compiled with a fixed GHC version)
, ...
}:
let
Expand Down
33 changes: 26 additions & 7 deletions overlays/bootstrap.nix
Original file line number Diff line number Diff line change
Expand Up @@ -394,12 +394,6 @@ in {
nix-tools = final.evalPackages.haskell-nix.nix-tools-unchecked.${compiler-nix-name};
materialized = ../materialized + "/${compiler-nix-name}/cabal-install";
} // args)).components.exes.cabal;
cabal-install = final.lib.mapAttrs (compiler-nix-name: _:
final.haskell-nix.cabal-install-tool { inherit compiler-nix-name; }) final.haskell-nix.compiler;
cabal-install-unchecked = final.lib.mapAttrs (compiler-nix-name: _:
final.haskell-nix.cabal-install-tool { inherit compiler-nix-name; checkMaterialization = false; }) final.haskell-nix.compiler;
# Use this where we still have not good way to choose GHC version
internal-cabal-install = final.haskell-nix.cabal-install.ghc883;
nix-tools-set = { compiler-nix-name, ... }@args:
let
project =
Expand Down Expand Up @@ -453,11 +447,36 @@ in {
done
'';
};

# Memoize the cabal-install and nix-tools derivations by adding:
# haskell-nix.cabal-install.ghcXXX
# haskell-nix.cabal-install-unchecked.ghcXXX
# haskell-nix.nix-tools.ghcXXX
# haskell-nix.nix-tools-unchecked.ghcXXX
# Using these avoids unecessary calls to mkDerivation.
# For cabal projects we match the versions used to the compiler
# selected for the project to avoid the chance of a dependency
# another GHC version (particularly useful on macOS where
# executables are dynamically linked to GHC itself).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... which means that if you use a tool built with a different GHC you will get that GHC itself in your closure.

cabal-install = final.lib.mapAttrs (compiler-nix-name: _:
final.haskell-nix.cabal-install-tool { inherit compiler-nix-name; }) final.haskell-nix.compiler;
cabal-install-unchecked = final.lib.mapAttrs (compiler-nix-name: _:
final.haskell-nix.cabal-install-tool { inherit compiler-nix-name; checkMaterialization = false; }) final.haskell-nix.compiler;
nix-tools = final.lib.mapAttrs (compiler-nix-name: _:
final.haskell-nix.nix-tools-set { inherit compiler-nix-name; }) final.haskell-nix.compiler;
nix-tools-unchecked = final.lib.mapAttrs (compiler-nix-name: _:
final.haskell-nix.nix-tools-set { inherit compiler-nix-name; checkMaterialization = false; }) final.haskell-nix.compiler;
# Use this where we still have not good way to choose GHC version

# These `internal` versions are used for:
# * `nix-tools` for stack projects (since we use `nix-tools` to process
# the `stack.yaml` file we cannot match the ghc of the project the
# way we do for cabal projects).
# * Scripts are used to update stackage and hackage
# Updating the version of GHC selected here should be fairly safe as
# there should be no difference in the behaviour of these tools.
# (stack projects on macOS may see a significant change in the
# closure size of their build dependencies due to dynamic linking).
internal-cabal-install = final.haskell-nix.cabal-install.ghc883;
internal-nix-tools = final.haskell-nix.nix-tools.ghc883;

# WARN: The `import ../. {}` will prevent
Expand Down
6 changes: 5 additions & 1 deletion overlays/haskell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,10 @@ final: prev: {
};

update-index-state-hashes = import ../scripts/update-index-state-hashes.nix {
inherit (final.haskell-nix) indexStateHashesPath internal-nix-tools;
inherit (final.haskell-nix) indexStateHashesPath;
inherit (final) coreutils nix writeShellScriptBin stdenv curl;
# Update scripts use the internal nix-tools and cabal-install (compiled with a fixed GHC version)
nix-tools = final.haskell-nix.internal-nix-tools;
};

# Function to call stackToNix
Expand All @@ -267,6 +269,8 @@ final: prev: {
# to produce the nix representation of it.
callCabalToNix = { name, src, cabal-file ? "${name}.cabal" }:
final.buildPackages.pkgs.runCommand "${name}.nix" {
# This function is only used when building stack projects (via mkCacheLine and mkCacheFile)
# When building stack projects we use the internal nix-tools and cabal-install (compiled with a fixed GHC version)
nativeBuildInputs = [ final.buildPackages.haskell-nix.internal-nix-tools ];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth a note about why we're using the internal one here.


LOCALE_ARCHIVE = final.lib.optionalString (final.stdenv.buildPlatform.libc == "glibc") "${final.buildPackages.glibcLocales}/lib/locale/locale-archive";
Expand Down
4 changes: 2 additions & 2 deletions scripts/update-external.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{ stdenv, writeScript, glibc, coreutils, git, openssh
, internal-nix-tools, internal-cabal-install, nix-prefetch-git
, nix-tools, cabal-install, nix-prefetch-git
, bash, curl, findutils, gawk }:

{ name, script }:
Expand All @@ -16,7 +16,7 @@ in

set -euo pipefail

export PATH="${makeBinPath ([ coreutils curl findutils gawk bash git openssh internal-nix-tools internal-cabal-install nix-prefetch-git ] ++ optional stdenv.isLinux glibc)}"
export PATH="${makeBinPath ([ coreutils curl findutils gawk bash git openssh nix-tools cabal-install nix-prefetch-git ] ++ optional stdenv.isLinux glibc)}"

${script}

Expand Down
2 changes: 1 addition & 1 deletion scripts/update-hackage.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{ stdenv, writeScript, coreutils, glibc, git, openssh
, internal-nix-tools, internal-cabal-install, nix-prefetch-git
, nix-tools, cabal-install, nix-prefetch-git
, gawk, bash, curl, findutils
, update-index-state-hashes }@args:

Expand Down
4 changes: 2 additions & 2 deletions scripts/update-index-state-hashes.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{ indexStateHashesPath, internal-nix-tools, coreutils, nix, writeShellScriptBin, stdenv, curl }:
{ indexStateHashesPath, nix-tools, coreutils, nix, writeShellScriptBin, stdenv, curl }:
with builtins;
with stdenv.lib;
writeShellScriptBin "update-index-state-hashes" ''
export PATH="${makeBinPath [ coreutils internal-nix-tools nix curl ]}"
export PATH="${makeBinPath [ coreutils nix-tools nix curl ]}"

# We'll take the last element from the indexStatesHashes file via nix and get the name.
# This is the last timestamp recorded in the file (implicit assumption: the file is
Expand Down
2 changes: 1 addition & 1 deletion scripts/update-stackage.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{ stdenv, writeScript, coreutils, glibc, git, openssh
, internal-nix-tools, internal-cabal-install, nix-prefetch-git
, nix-tools, cabal-install, nix-prefetch-git
, gawk, bash, curl, findutils }@args:

import ./update-external.nix args {
Expand Down
2 changes: 1 addition & 1 deletion test/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
, nixpkgs ? haskellNix.sources.nixpkgs
, nixpkgsArgs ? haskellNix.nixpkgsArgs
, ifdLevel ? 1000
, compiler-nix-name ? "ghc865"
, compiler-nix-name
, checkMaterialization ? false
}:

Expand Down
28 changes: 22 additions & 6 deletions test/tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ NIX_BUILD_ARGS="${NIX_BUILD_ARGS:-}"

cd $(dirname $0)

if [ "$#" != "1" ]; then
echo "Please pass a compiler-nix-name to use. For example: ./test/test.sh ghc883"
exit 1
fi

GHC=$1

printf "*** Cleaning package build directories..." >& 2
rm -rvf */cabal.project.local */.ghc.environment* */dist */dist-newstyle */.stack-work
echo >& 2
Expand All @@ -16,11 +23,12 @@ nix build $NIX_BUILD_ARGS \
-I . -I .. \
--option restrict-eval true \
--option allowed-uris "https://github.com/NixOS https://github.com/input-output-hk" \
--no-link --keep-going -f default.nix
--no-link --keep-going -f default.nix \
--argstr compiler-nix-name $GHC
echo >& 2

printf "*** Running the unit tests... " >& 2
res=$(nix-instantiate --eval --json --strict ./default.nix -A unit.tests)
res=$(nix-instantiate --eval --json --strict ./default.nix --argstr compiler-nix-name $GHC -A unit.tests)
num_failed=$(jq length <<< "$res")
if [ $num_failed -eq 0 ]; then
printf "PASSED\n" >& 2
Expand All @@ -33,20 +41,23 @@ fi
printf "*** Checking that a nix-shell works for runghc...\n" >& 2
nix-shell $NIX_BUILD_ARGS \
--pure ./default.nix \
--argstr compiler-nix-name $GHC \
-A with-packages.test-shell \
--run 'runghc with-packages/Point.hs'
echo >& 2

printf "*** Checking that a nix-shell works for cabal...\n" >& 2
nix-shell $NIX_BUILD_ARGS \
--pure ./default.nix \
--argstr compiler-nix-name $GHC \
-A with-packages.test-shell \
--run 'echo CABAL_CONFIG=$CABAL_CONFIG && type -p ghc && cd with-packages && cabal new-build'
echo >& 2

printf "*** Checking that a nix-shell works for cabal (doExactConfig component)...\n" >& 2
nix-shell $NIX_BUILD_ARGS \
--pure ./default.nix \
--argstr compiler-nix-name $GHC \
-A with-packages.test-shell-dec \
--run 'echo CABAL_CONFIG=$CABAL_CONFIG && echo GHC_ENVIRONMENT=$GHC_ENVIRONMENT && cd with-packages && cabal new-build'
echo >& 2
Expand All @@ -55,6 +66,7 @@ printf "*** Checking that a nix-shell works for a project with test-suite build-
printf "!!! This is expected to fail until https://github.com/input-output-hk/haskell.nix/issues/231 is resolved! \n" >& 2
nix-shell $NIX_BUILD_ARGS \
--pure ./default.nix \
--argstr compiler-nix-name $GHC \
-A cabal-22.shell \
--run 'cd cabal-22 && cabal new-build all --enable-tests --enable-benchmarks' \
|| true
Expand All @@ -63,35 +75,39 @@ echo >& 2
printf "*** Checking that a nix-shell works for a multi-target project...\n" >& 2
nix-shell $NIX_BUILD_ARGS \
--pure ./default.nix \
--argstr compiler-nix-name $GHC \
-A cabal-simple.test-shell \
--run 'cd cabal-simple && cabal new-build'
echo >& 2

printf "*** Checking shellFor works for a cabal project, multiple packages...\n" >& 2
nix-shell $NIX_BUILD_ARGS \
--pure ./default.nix \
--argstr compiler-nix-name $GHC
-A shell-for.env \
--run 'cd shell-for && cabal new-build all'
echo >& 2

printf "*** Checking shellFor works for a cabal project, single package...\n" >& 2
nix-shell $NIX_BUILD_ARGS \
--pure ./default.nix \
--argstr compiler-nix-name $GHC \
-A shell-for.envPkga \
--run 'cd shell-for && cabal new-build --project=single.project all'
echo >& 2

printf "*** Checking shellFor has a working hoogle index...\n" >& 2
nix-shell $NIX_BUILD_ARGS \
--pure ./default.nix \
--argstr compiler-nix-name $GHC
-A shell-for.env \
--run 'hoogle ConduitT | grep Data.Conduit'
echo >& 2

printf "*** Checking shellFor does not depend on given packages...\n" >& 2
drva=$(nix-instantiate ./default.nix -A shell-for.env)
drva=$(nix-instantiate ./default.nix --argstr compiler-nix-name $GHC -A shell-for.env)
echo "-- hello" >> shell-for/pkga/PkgA.hs
drvb=$(nix-instantiate ./default.nix -A shell-for.env)
drvb=$(nix-instantiate ./default.nix --argstr compiler-nix-name $GHC -A shell-for.env)
sed -i -e '/-- hello/d' shell-for/pkga/PkgA.hs
if [ "$drva" != "$drvb" ]; then
printf "FAIL\nShell derivations\n$drva\n$drvb\n are not identical.\n" >& 2
Expand All @@ -106,13 +122,13 @@ echo >& 2

printf "*** Checking that plan construction works with extra Hackages...\n" >& 2
nix build $NIX_BUILD_ARGS --no-link \
-f ./default.nix \
-f ./default.nix --argstr compiler-nix-name $GHC \
extra-hackage.run.project.plan-nix
echo >& 2

printf "*** Checking that package with extra Hackages can be build...\n" >& 2
nix build $NIX_BUILD_ARGS --no-link \
-f ./default.nix \
-f ./default.nix --argstr compiler-nix-name $GHC \
extra-hackage.run.project.hsPkgs.external-package-user.components.all
echo >& 2

Expand Down