From a71e906e3a0bec9c5fece94262e96de83e58c1f3 Mon Sep 17 00:00:00 2001 From: deliciouslytyped <47436522+deliciouslytyped@users.noreply.github.com> Date: Mon, 14 Jun 2021 15:06:23 +0200 Subject: trivial-builders: refactor writeTextFile to be overridable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 ; 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 Co-authored-by: Naïm Favier --- pkgs/test/default.nix | 1 + 1 file changed, 1 insertion(+) (limited to 'pkgs/test') diff --git a/pkgs/test/default.nix b/pkgs/test/default.nix index 8c9e7b6f281..ebf732839ce 100644 --- a/pkgs/test/default.nix +++ b/pkgs/test/default.nix @@ -52,6 +52,7 @@ with pkgs; cuda = callPackage ./cuda { }; trivial = callPackage ../build-support/trivial-builders/test.nix {}; + trivial-overriding = callPackage ../build-support/trivial-builders/test-overriding.nix {}; writers = callPackage ../build-support/writers/test.nix {}; } -- cgit 1.4.1