From 4df10debe79feba975631347b25f8699b7cd3554 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Na=C3=AFm=20Favier?= Date: Tue, 6 Dec 2022 18:51:29 +0100 Subject: [PATCH] lib/customisation.overrideDerivation: propagate evaluation condition The new derivation should evaluate only if the old derivation does. Sadly this means that the old derivation cannot depend on the new one any more, which was used by xorgserver on Darwin. But this is not a problem as `overrideAttrs` can (and should) usually be used instead. This change allowed catching an invalid `meta.platforms` in the linux_rpi kernels, which use `overrideDerivation`. --- doc/using/overrides.chapter.md | 2 +- lib/customisation.nix | 10 +++++++++- pkgs/servers/x11/xorg/overrides.nix | 3 +-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/doc/using/overrides.chapter.md b/doc/using/overrides.chapter.md index 1c51d27eced..198b4504197 100644 --- a/doc/using/overrides.chapter.md +++ b/doc/using/overrides.chapter.md @@ -63,7 +63,7 @@ You should prefer `overrideAttrs` in almost all cases, see its documentation for ::: ::: {.warning} -Do not use this function in Nixpkgs as it evaluates a Derivation before modifying it, which breaks package abstraction and removes error-checking of function arguments. In addition, this evaluation-per-function application incurs a performance penalty, which can become a problem if many overrides are used. It is only intended for ad-hoc customisation, such as in `~/.config/nixpkgs/config.nix`. +Do not use this function in Nixpkgs as it evaluates a derivation before modifying it, which breaks package abstraction. In addition, this evaluation-per-function application incurs a performance penalty, which can become a problem if many overrides are used. It is only intended for ad-hoc customisation, such as in `~/.config/nixpkgs/config.nix`. ::: The function `overrideDerivation` creates a new derivation based on an existing one by overriding the original's attributes with the attribute set produced by the specified function. This function is available on all derivations defined using the `makeOverridable` function. Most standard derivation-producing functions, such as `stdenv.mkDerivation`, are defined using this function, which means most packages in the nixpkgs expression, `pkgs`, have this function. diff --git a/lib/customisation.nix b/lib/customisation.nix index bd7ee3c83b8..7ba8ed06180 100644 --- a/lib/customisation.nix +++ b/lib/customisation.nix @@ -27,11 +27,19 @@ rec { For another application, see build-support/vm, where this function is used to build arbitrary derivations inside a QEMU virtual machine. + + Note that in order to preserve evaluation errors, the new derivation's + outPath depends on the old one's, which means that this function cannot + be used in circular situations when the old derivation also depends on the + new one. + + You should in general prefer `drv.overrideAttrs` over this function; + see the nixpkgs manual for more information on overriding. */ overrideDerivation = drv: f: let newDrv = derivation (drv.drvAttrs // (f drv)); - in lib.flip (extendDerivation true) newDrv ( + in lib.flip (extendDerivation (builtins.seq drv.drvPath true)) newDrv ( { meta = drv.meta or {}; passthru = if drv ? passthru then drv.passthru else {}; } diff --git a/pkgs/servers/x11/xorg/overrides.nix b/pkgs/servers/x11/xorg/overrides.nix index ddd5acad7a1..8b3129f5ae2 100644 --- a/pkgs/servers/x11/xorg/overrides.nix +++ b/pkgs/servers/x11/xorg/overrides.nix @@ -11,7 +11,6 @@ let inherit (stdenv) isDarwin; - inherit (lib) overrideDerivation; malloc0ReturnsNullCrossFlag = lib.optional (stdenv.hostPlatform != stdenv.buildPlatform) @@ -761,7 +760,7 @@ self: super: ]; # XQuartz requires two compilations: the first to get X / XQuartz, # and the second to get Xvfb, Xnest, etc. - darwinOtherX = overrideDerivation xorgserver (oldAttrs: { + darwinOtherX = xorgserver.overrideAttrs (oldAttrs: { configureFlags = oldAttrs.configureFlags ++ [ "--disable-xquartz" "--enable-xorg"