haskell.nix/test/shell-for/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

91 lines
3.0 KiB
Nix

{ stdenv, lib, cabal-install, mkCabalProjectPkgSet, recurseIntoAttrs, runCommand, testSrc, compiler-nix-name, evalPackages }:
with lib;
let
pkgSet = mkCabalProjectPkgSet {
plan-pkgs = import ./pkgs.nix;
pkg-def-extras = [{
pkga = ./.plan.nix/pkga.nix;
pkgb = ./.plan.nix/pkgb.nix;
}];
modules = [{
# Package has no exposed modules which causes
# haddock: No input file(s)
packages.bytestring-builder.doHaddock = false;
inherit evalPackages;
}];
};
env = pkgSet.config.hsPkgs.shellFor {
# Shell will provide the dependencies of pkga and pkgb, but not
# pkga and pkgb themselves.
packages = ps: with ps; [ pkga pkgb ];
# This adds cabal-install to the shell, which helps tests because
# they use a nix-shell --pure. Normally you would BYO cabal-install.
tools = { cabal = "3.2.0.0"; };
exactDeps = true;
# Avoid duplicate package issues when runghc looks for packages
packageSetupDeps = false;
};
envPkga = pkgSet.config.hsPkgs.shellFor {
# Shell will provide the dependencies of pkga
packages = ps: with ps; [ pkga ];
# This adds cabal-install to the shell, which helps tests because
# they use a nix-shell --pure. Normally you would BYO cabal-install.
tools = { cabal = "3.2.0.0"; };
exactDeps = true;
# Avoid duplicate package issues when runghc looks for packages
packageSetupDeps = false;
};
envDefault = pkgSet.config.hsPkgs.shellFor {
# The default implementation of packages should use isLocal and the
# result should be the same as:
# packages = ps: with ps; [ pkga pkgb ];
# This adds cabal-install to the shell, which helps tests because
# they use a nix-shell --pure. Normally you would BYO cabal-install.
tools = { cabal = "3.2.0.0"; };
# Avoid duplicate package issues when runghc looks for packages
packageSetupDeps = false;
};
in recurseIntoAttrs {
# Does not work on ghcjs because it needs zlib.
# Does not work on windows because it needs mintty.
meta.disabled = stdenv.hostPlatform.isMusl || stdenv.hostPlatform.isGhcjs || stdenv.hostPlatform.isWindows
|| compiler-nix-name != ((import ./pkgs.nix).pkgs null).compiler.nix-name;
inherit env envPkga envDefault;
run = stdenv.mkDerivation {
name = "shell-for-test";
buildCommand = ''
########################################################################
# test shell-for with an example program
cp ${./pkgb/src}/*.hs .
printf "checking that the shell env has the dependencies...\n" >& 2
${env.ghc}/bin/${env.ghc.targetPrefix}runghc conduit-test.hs
printf "checking that the shell envDefault has the dependencies...\n" >& 2
${envDefault.ghc}/bin/${env.ghc.targetPrefix}runghc conduit-test.hs
touch $out
'';
meta = {
platforms = platforms.unix;
};
passthru = {
# Used for debugging with nix repl
inherit pkgSet;
# Used for testing externally with nix-shell (../tests.sh).
inherit env envPkga envDefault;
};
};
}