haskell.nix/test/ca-derivations-include/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

58 lines
1.5 KiB
Nix

# Build a project enabling content addressed derivations for
# only a subset of the components
{ stdenv, pkgs, lib, mkCabalProjectPkgSet, project', haskellLib, recurseIntoAttrs, testSrc, compiler-nix-name, evalPackages, CADerivationsEnabled }:
with lib;
let
cabalProject = ''
packages: .
allow-newer: aeson:*
'';
src = testSrc "cabal-simple";
# each derivation is content addressed
projectA = project' {
inherit compiler-nix-name evalPackages src cabalProject;
modules = [{ contentAddressed = true; }];
};
# each derivation but one (the executable) is content addressed
projectB = project' {
inherit compiler-nix-name evalPackages src cabalProject;
modules = [{
contentAddressed = true;
packages.cabal-simple.components.exes.cabal-simple.contentAddressed = false;
}];
};
exeA = projectA.hsPkgs.cabal-simple.components.exes.cabal-simple.exePath;
exeB = projectB.hsPkgs.cabal-simple.components.exes.cabal-simple.exePath;
in
recurseIntoAttrs {
meta.disabled = !CADerivationsEnabled;
# check if the built executables are different (one is content addressed)
# the other components are all content addressed (same output paths then)
run = stdenv.mkDerivation {
name = "ca-derivations-include-test";
buildCommand = ''
[ "${exeA}" == "${exeB}" ] && exit 1
touch $out
'';
meta.platforms = platforms.all;
passthru = {
# Used for debugging with nix repl
inherit projectB projectA;
};
};
}