Files
haskell.nix/test/with-packages/default.nix
Hamish Mackenzie a443611ecf Add evalSystem and evalPackages project args (#1546)
This adds a way to specify the `evalSystem` or `evalPackages` explicitly when calling the `project` functions.

Currently if we want to make a `flake` that supports multiple systems we have few options:

* Require builders for all the supported systems (even just for `nix flake show`).

* Pass `--impure` so that haskell.nix can see `builtins.currentSystem` to set up `pkgs.evalPackages` to use that.  Unfortunately this prevents nix from caching some of the work it does and often results in it recalculating for each supported system when it would otherwise be cached and take no time at all.

* Add an overlay to replace `evalPackages`.  This works, but it is not straight forward.

* Materialize the nix files for the project.

This change allows `evalSystem = "x86_64-linux";` to be passed telling `haskell.nix` to run `cabal` and `nix-tools` on that system.  The user will have to have a builder for that system, but does not need to have builders for the others (unless building outputs for them).
2022-07-28 20:03:05 +12:00

110 lines
3.4 KiB
Nix

{ stdenv, lib, util, mkPkgSet, recurseIntoAttrs, testSrc, compiler-nix-name, evalPackages }:
with lib;
with util;
let
pkgs = import ./pkgs.nix;
pkgSet = doExactConfig: mkPkgSet {
# generated with:
# cabal new-build
# plan-to-nix -o .
pkg-def = pkgs.pkgs;
pkg-def-extras = [ pkgs.extras ];
modules = pkgs.modules ++ [
# overrides to fix the build
{
packages.transformers-compat.components.library.doExactConfig = true;
}
# vary component config for tests
{
packages.test-with-packages.components.library.doExactConfig = doExactConfig;
}
{ inherit evalPackages; }
];
};
packages = doExactConfig: (pkgSet doExactConfig).config.hsPkgs;
package = doExactConfig: (packages doExactConfig).test-with-packages;
decLibrary = (package true).components.library;
library = (package false).components.library;
pkgId = p: "${p.identifier.name}-${p.identifier.version}";
showDepends = component: concatMapStringsSep " " pkgId (component.depends or []);
extraFlags = "";
in recurseIntoAttrs {
meta.disabled = compiler-nix-name != "ghc865";
# Used for testing externally with nix-shell (../tests.sh).
# This just adds cabal-install to the existing shells.
test-shell = addCabalInstall library;
# A variant of test-shell with the component option doExactConfig enabled
test-shell-dec = addCabalInstall decLibrary;
run = stdenv.mkDerivation {
name = "with-packages-test";
decLibraryDepends = showDepends (pkgSet true).config.packages.test-with-packages.components.library;
libraryDepends = showDepends (pkgSet false).config.packages.test-with-packages.components.library;
src = ./.;
buildPhase = ''
########################################################################
# test with-packages
printf "checking component depends ... " >& 2
if [ -n "$decLibraryDepends" -a "$decLibraryDepends" = "$libraryDepends" ]; then
echo "PASS" >& 2
else
echo "FAIL" >& 2
echo "decLibraryDepends = $decLibraryDepends"
echo "libraryDepends = $libraryDepends"
exit 1
fi
printf "checking that the 'library' without doExactConfig works... " >& 2
echo ${library} >& 2
printf "checking that the 'library' with doExactConfig works... " >& 2
echo ${decLibrary} >& 2
'' + (if stdenv.hostPlatform.isWindows || stdenv.hostPlatform.isGhcjs
then ''
printf "runghc tests are not working yet for windows or ghcjs. skipping. " >& 2
''
else ''
echo "checking that non doExactConfig library.env has the dependencies... "
echo "with runghc"
${library.env}/bin/${library.env.targetPrefix}runghc ./Point.hs
echo "with ghc"
${library.env}/bin/${library.env.targetPrefix}ghc ${toString extraFlags} Point.hs 1> /dev/null
./Point
echo "checking that doExactConfig library.env has the dependencies... "
echo "with runghc"
${decLibrary.env}/bin/${decLibrary.env.targetPrefix}runghc ./Point.hs
echo "with ghc"
${decLibrary.env}/bin/${decLibrary.env.targetPrefix}ghc ${extraFlags} Point.hs 1> /dev/null
./Point
'') + ''
touch $out
'';
dontInstall = true;
meta = {
platforms = platforms.all;
disabled = stdenv.hostPlatform.isMusl;
};
passthru = {
# Used for debugging with nix repl
inherit packages pkgSet;
};
};
}