Previously, setting environment variables in a Haskell package build required using `.overrideAttrs`, which (I think?) breaks later invocations of `haskell.lib.overrideCabal`. This patch adds an `env` argument to `haskellPackages.mkDerivation`, which can be used to set environment variables during Haskell package builds.
56 lines
1.0 KiB
Nix
56 lines
1.0 KiB
Nix
{
|
|
lib,
|
|
haskellPackages,
|
|
}:
|
|
|
|
let
|
|
withEnv =
|
|
env:
|
|
haskellPackages.mkDerivation {
|
|
pname = "puppy";
|
|
version = "1.0.0";
|
|
src = null;
|
|
license = null;
|
|
|
|
inherit env;
|
|
};
|
|
|
|
failures = lib.runTests {
|
|
testCanSetEnv = {
|
|
expr =
|
|
(withEnv {
|
|
PUPPY = "DOGGY";
|
|
}).drvAttrs.PUPPY;
|
|
expected = "DOGGY";
|
|
};
|
|
|
|
testCanSetEnvMultiple = {
|
|
expr =
|
|
let
|
|
env =
|
|
(withEnv {
|
|
PUPPY = "DOGGY";
|
|
SILLY = "GOOFY";
|
|
}).drvAttrs;
|
|
in
|
|
{
|
|
inherit (env) PUPPY SILLY;
|
|
};
|
|
expected = {
|
|
PUPPY = "DOGGY";
|
|
SILLY = "GOOFY";
|
|
};
|
|
};
|
|
|
|
testCanSetEnvPassthru = {
|
|
expr =
|
|
(withEnv {
|
|
PUPPY = "DOGGY";
|
|
}).passthru.env.PUPPY;
|
|
expected = "DOGGY";
|
|
};
|
|
};
|
|
in
|
|
# TODO: Use `lib.debug.throwTestFailures`: https://github.com/NixOS/nixpkgs/pull/416207
|
|
lib.optional (failures != [ ]) (throw "${lib.generators.toPretty { } failures}")
|