diff options
author | Robert Hensing <robert@roberthensing.nl> | 2021-04-20 13:46:53 +0200 |
---|---|---|
committer | Robert Hensing <robert@roberthensing.nl> | 2022-05-02 08:49:26 +0200 |
commit | a4e708522768a30cd5120a65c979c87abd525336 (patch) | |
tree | 02384ca5cd556ca91f2207056a5174d32a69812b /doc/stdenv/meta.chapter.md | |
parent | b27e64c703ab5e53498e43ee1e34c61212b01e50 (diff) | |
download | nixpkgs-a4e708522768a30cd5120a65c979c87abd525336.tar nixpkgs-a4e708522768a30cd5120a65c979c87abd525336.tar.gz nixpkgs-a4e708522768a30cd5120a65c979c87abd525336.tar.bz2 nixpkgs-a4e708522768a30cd5120a65c979c87abd525336.tar.lz nixpkgs-a4e708522768a30cd5120a65c979c87abd525336.tar.xz nixpkgs-a4e708522768a30cd5120a65c979c87abd525336.tar.zst nixpkgs-a4e708522768a30cd5120a65c979c87abd525336.zip |
stdenv.mkDerivation: Allow overriding of recursive definitions
See updated manual for further explanation.
Diffstat (limited to 'doc/stdenv/meta.chapter.md')
-rw-r--r-- | doc/stdenv/meta.chapter.md | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/doc/stdenv/meta.chapter.md b/doc/stdenv/meta.chapter.md index d3e1dd5b27d..5f3e12ba004 100644 --- a/doc/stdenv/meta.chapter.md +++ b/doc/stdenv/meta.chapter.md @@ -175,6 +175,36 @@ The NixOS tests are available as `nixosTests` in parameters of derivations. For NixOS tests run in a VM, so they are slower than regular package tests. For more information see [NixOS module tests](https://nixos.org/manual/nixos/stable/#sec-nixos-tests). +Alternatively, you can specify other derivations as tests. You can make use of +the optional parameter (here: `self`) to inject the correct package without +relying on non-local definitions, even in the presence of `overrideAttrs`. This +definition of `tests` does not rely on the original `mypkg` or overrides it in +all places. + +```nix +# my-package/default.nix +{ stdenv, callPackage }: +stdenv.mkDerivation (self: { + # ... + passthru.tests.example = callPackage ./example.nix { my-package = self; }; +}) +``` + +```nix +# my-package/example.nix +{ runCommand, lib, my-package, ... }: +runCommand "my-package-test" { + nativeBuildInputs = [ my-package ]; + src = lib.sources.sourcesByRegex ./. [ ".*.in" ".*.expected" ]; +} '' + my-package --help + my-package <example.in >example.actual + diff -U3 --color=auto example.expected example.actual + mkdir $out +'' +``` + + ### `timeout` {#var-meta-timeout} A timeout (in seconds) for building the derivation. If the derivation takes longer than this time to build, it can fail due to breaking the timeout. However, all computers do not have the same computing power, hence some builders may decide to apply a multiplicative factor to this value. When filling this value in, try to keep it approximately consistent with other values already present in `nixpkgs`. |