nixpkgs/pkgs/test
deliciouslytyped a71e906e3a trivial-builders: refactor writeTextFile to be overridable
This fixes #126344, specifically with the goal of enabling overriding the
checkPhase argument. See `design notes` at the end for details.

This allows among other things, enabling bash extension for the `checkPhase`.
Previously using such bash extensions was prohibited by the `writeShellScript`
code because there was no way to enable the extension in the checker.

As an example:

```nix
(writeShellScript "foo" ''
  shopt -s extglob
  echo @(foo|bar)
'').overrideAttrs (old: {
  checkPhase = ''
    # use subshell to preserve outer environment
    (
      export BASHOPTS
      shopt -s extglob
      ${old.checkPhase}
    )
  '';
})
```

This commit also adds tests for this feature to `pkgs/tests/default.nix`,
under `trivial-overriding`. The test code is located at
`pkgs/build-support/trivial-builders/test-overriding.nix`.

Design notes:
-------------

Per discussion with @sternenseemann, the original approach of just wrapping
`writeTextFile` in `makeOverridable` had the issue that combined with `callPackage`
in the following form, would shadow the `.override` attribute of the `writeTextFile`:

```nix
with import <nixpkgs>;
callPackage ({writeShellScript}: writeShellScript "foo" "echo foo")
```

A better approach can be seen in this commit, where `checkPhase` is moved
from an argument of `writeTextFile`, which is substituted into `buildCommand`,
into an `mkDerivation` argument, which is substituted from the environment
and `eval`-ed. (see the source)

This way we can simple use `.overideAttrs` as usual, and this also makes
`checkPhase` a bit more conformant to `mkDerivation` naming, with respect to
phases generally being overridable attrs.

Co-authored-by: sterni <sternenseemann@systemli.org>
Co-authored-by: Naïm Favier <n@monade.li>
2021-06-18 01:39:59 +02:00
..
cc-wrapper cc-wrapper: don't set rpath on static-pie executables 2021-05-23 17:38:17 +00:00
cross pkg-config-wrapper: Init 2020-05-16 00:21:21 +00:00
cuda cudatoolkit-{9,9_0,9_1,9_2}: remove 2021-04-18 11:55:10 +02:00
haskell tests.haskell-setBuildTarget: inline haskell package def to avoid IFD 2021-05-02 13:35:14 +09:00
install-shell-files treewide: remove stdenv where not needed 2021-01-25 18:31:47 +01:00
ld-library-path treewide: stdenv.lib -> lib 2021-01-24 01:49:49 +01:00
macos-sierra-shared treewide: remove redundant rec 2019-08-28 11:07:32 +00:00
mkOption
nixos-functions tests.nixos-functions: port test to python 2020-02-09 23:53:58 +01:00
patch-shebangs tests.patch-shebangs: add case for ignoring store paths 2021-02-09 13:07:49 +09:00
rust-sysroot treewide: fix cargoSha256/cargoHash 2021-05-08 00:36:37 -07:00
simple Remove cruft 2016-04-26 17:31:54 +02:00
stdenv-inputs treewide: stdenv.lib -> lib 2021-01-24 01:49:49 +01:00
texlive tests.texlive.dvipng: apply recurseIntoAttrs 2021-05-02 19:35:47 -04:00
vim neovim.tests: added more tests 2021-06-09 21:45:25 +02:00
default.nix trivial-builders: refactor writeTextFile to be overridable 2021-06-18 01:39:59 +02:00
kernel.nix kernel: fix config generation 2020-04-01 22:25:57 +02:00