haskell.nix/test/cabal-simple-prof/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

63 lines
1.7 KiB
Nix

# Test a package set
{ stdenv, lib, util, cabalProject', haskellLib, recurseIntoAttrs, testSrc, compiler-nix-name, evalPackages }:
with lib;
let
modules = [
{
# Package has no exposed modules which causes
# haddock: No input file(s)
packages.cabal-simple.doHaddock = false;
packages.cabal-simple.enableProfiling = true;
enableLibraryProfiling = true;
# executableProfiling = false;
}
];
project = cabalProject' {
inherit compiler-nix-name evalPackages;
src = testSrc "cabal-simple-prof";
inherit modules;
cabalProject = ''
packages: .
allow-newer: aeson:*
'';
};
in recurseIntoAttrs {
# This test seeems to be broken on 8.6 and 8.8 and ghcjs
meta.disabled = compiler-nix-name == "ghc865" || compiler-nix-name == "ghc884" || stdenv.hostPlatform.isGhcjs;
ifdInputs = {
inherit (project) plan-nix;
};
run = stdenv.mkDerivation {
name = "cabal-simple-prof-test";
buildCommand = ''
exe="${(project.getComponent "cabal-simple:exe:cabal-simple").exePath}"
size=$(command stat --format '%s' "$exe")
printf "size of executable $exe is $size. \n" >& 2
# fixme: run on target platform when cross-compiled
printf "checking whether executable runs with profiling... " >& 2
# Curiosity: cross compilers prodcing profiling with `+RTS -p -h` lead to the following cryptic message:
# cabal-simple: invalid heap profile option: -h*
# Hence we pass `-hc`.
${toString (project.getComponent "cabal-simple:exe:cabal-simple").config.testWrapper} $exe +RTS -p -hc
touch $out
'';
meta = {
platforms = platforms.all;
};
passthru = {
# Used for debugging with nix repl
inherit project;
};
};
}