Home Explore Blog Models CI



nixpkgs

doc/hooks/redis-test-hook.section.md
3623f569f46276966652328e6cfd5029afdfe96c23ec35d2000000030000037c

# `redisTestHook` {#sec-redisTestHook}

This hook starts a Redis server during `checkPhase`. Example:

```nix
{
  stdenv,
  redis,
  redisTestHook,
}:
stdenv.mkDerivation {

  # ...

  nativeCheckInputs = [ redisTestHook ];
}
```

If you use a custom `checkPhase`, remember to add the `runHook` calls:
```nix
{
  checkPhase = ''
    runHook preCheck

    # ... your tests

    runHook postCheck
  '';
}
```

## Variables {#sec-redisTestHook-variables}

The hook logic will read the following variables and set them to a default value if unset or empty.

Exported variables:

- `REDIS_SOCKET`: UNIX domain socket path

Bash-only variables:

- `redisTestPort`: Port to use by Redis. Defaults to `6379`

Example usage:

```nix
{
  stdenv,
  redis,
  redisTestHook,
}:
stdenv.mkDerivation {

  # ...

  nativeCheckInputs = [ redisTestHook ];

  preCheck = ''
    redisTestPort=6390;
  '';
}
```

Chunks
8542b7f3 (1st chunk of `doc/hooks/redis-test-hook.section.md`)
Title: `redisTestHook` for Nix Builds
Summary
The `redisTestHook` is a Nix build hook designed to launch a Redis server during the `checkPhase` of a derivation. It is included by adding it to `nativeCheckInputs`. If a custom `checkPhase` is used, explicit `runHook preCheck` and `runHook postCheck` calls are necessary. The hook makes several variables available for configuration, including `REDIS_SOCKET` for the UNIX domain socket path and `redisTestPort` to specify the Redis server's port, which defaults to `6379` and can be overridden in `preCheck`.