diff options
author | Alyssa Ross <hi@alyssa.is> | 2023-06-16 06:56:35 +0000 |
---|---|---|
committer | Alyssa Ross <hi@alyssa.is> | 2023-06-16 06:56:35 +0000 |
commit | 99fcaeccb89621dd492203ce1f2d551c06f228ed (patch) | |
tree | 41cb730ae07383004789779b0f6e11cb3f4642a3 /nixpkgs/lib/customisation.nix | |
parent | 59c5f5ac8682acc13bb22bc29c7cf02f7d75f01f (diff) | |
parent | 75a5ebf473cd60148ba9aec0d219f72e5cf52519 (diff) | |
download | nixlib-99fcaeccb89621dd492203ce1f2d551c06f228ed.tar nixlib-99fcaeccb89621dd492203ce1f2d551c06f228ed.tar.gz nixlib-99fcaeccb89621dd492203ce1f2d551c06f228ed.tar.bz2 nixlib-99fcaeccb89621dd492203ce1f2d551c06f228ed.tar.lz nixlib-99fcaeccb89621dd492203ce1f2d551c06f228ed.tar.xz nixlib-99fcaeccb89621dd492203ce1f2d551c06f228ed.tar.zst nixlib-99fcaeccb89621dd492203ce1f2d551c06f228ed.zip |
Merge branch 'nixos-unstable' of https://github.com/NixOS/nixpkgs
Conflicts: nixpkgs/nixos/modules/config/console.nix nixpkgs/nixos/modules/services/mail/mailman.nix nixpkgs/nixos/modules/services/mail/public-inbox.nix nixpkgs/nixos/modules/services/mail/rss2email.nix nixpkgs/nixos/modules/services/networking/ssh/sshd.nix nixpkgs/pkgs/applications/networking/instant-messengers/dino/default.nix nixpkgs/pkgs/applications/networking/irc/weechat/default.nix nixpkgs/pkgs/applications/window-managers/sway/default.nix nixpkgs/pkgs/build-support/go/module.nix nixpkgs/pkgs/build-support/rust/build-rust-package/default.nix nixpkgs/pkgs/development/interpreters/python/default.nix nixpkgs/pkgs/development/node-packages/overrides.nix nixpkgs/pkgs/development/tools/b4/default.nix nixpkgs/pkgs/servers/dict/dictd-db.nix nixpkgs/pkgs/servers/mail/public-inbox/default.nix nixpkgs/pkgs/tools/security/pinentry/default.nix nixpkgs/pkgs/tools/text/unoconv/default.nix nixpkgs/pkgs/top-level/all-packages.nix
Diffstat (limited to 'nixpkgs/lib/customisation.nix')
-rw-r--r-- | nixpkgs/lib/customisation.nix | 61 |
1 files changed, 40 insertions, 21 deletions
diff --git a/nixpkgs/lib/customisation.nix b/nixpkgs/lib/customisation.nix index cc9a9b1c55d0..fe32e890f357 100644 --- a/nixpkgs/lib/customisation.nix +++ b/nixpkgs/lib/customisation.nix @@ -3,13 +3,13 @@ rec { - /* `overrideDerivation drv f' takes a derivation (i.e., the result - of a call to the builtin function `derivation') and returns a new + /* `overrideDerivation drv f` takes a derivation (i.e., the result + of a call to the builtin function `derivation`) and returns a new derivation in which the attributes of the original are overridden - according to the function `f'. The function `f' is called with + according to the function `f`. The function `f` is called with the original derivation attributes. - `overrideDerivation' allows certain "ad-hoc" customisation + `overrideDerivation` allows certain "ad-hoc" customisation scenarios (e.g. in ~/.config/nixpkgs/config.nix). For instance, if you want to "patch" the derivation returned by a package function in Nixpkgs to build another version than what the @@ -27,23 +27,34 @@ 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 {}; } // (drv.passthru or {}) // - (if (drv ? crossDrv && drv ? nativeDrv) - then { - crossDrv = overrideDerivation drv.crossDrv f; - nativeDrv = overrideDerivation drv.nativeDrv f; - } - else { })); + # TODO(@Artturin): remove before release 23.05 and only have __spliced. + (lib.optionalAttrs (drv ? crossDrv && drv ? nativeDrv) { + crossDrv = overrideDerivation drv.crossDrv f; + nativeDrv = overrideDerivation drv.nativeDrv f; + }) + // + lib.optionalAttrs (drv ? __spliced) { + __spliced = {} // (lib.mapAttrs (_: sDrv: overrideDerivation sDrv f) drv.__spliced); + }); /* `makeOverridable` takes a function from attribute set to attribute set and @@ -93,10 +104,10 @@ rec { else result; - /* Call the package function in the file `fn' with the required + /* Call the package function in the file `fn` with the required arguments automatically. The function is called with the - arguments `args', but any missing arguments are obtained from - `autoArgs'. This function is intended to be partially + arguments `args`, but any missing arguments are obtained from + `autoArgs`. This function is intended to be partially parameterised, e.g., callPackage = callPackageWith pkgs; @@ -105,9 +116,9 @@ rec { libbar = callPackage ./bar.nix { }; }; - If the `libbar' function expects an argument named `libfoo', it is + If the `libbar` function expects an argument named `libfoo`, it is automatically passed as an argument. Overrides or missing - arguments can be supplied in `args', e.g. + arguments can be supplied in `args`, e.g. libbar = callPackage ./bar.nix { libfoo = null; @@ -165,7 +176,7 @@ rec { # Only show the error for the first missing argument error = errorForArg (lib.head missingArgs); - in if missingArgs == [] then makeOverridable f allArgs else throw error; + in if missingArgs == [] then makeOverridable f allArgs else abort error; /* Like callPackage, but for a function that returns an attribute @@ -202,7 +213,14 @@ rec { outputSpecified = true; drvPath = assert condition; drv.${outputName}.drvPath; outPath = assert condition; drv.${outputName}.outPath; - }; + } // + # TODO: give the derivation control over the outputs. + # `overrideAttrs` may not be the only attribute that needs + # updating when switching outputs. + lib.optionalAttrs (passthru?overrideAttrs) { + # TODO: also add overrideAttrs when overrideAttrs is not custom, e.g. when not splicing. + overrideAttrs = f: (passthru.overrideAttrs f).${outputName}; + }; }; outputsList = map outputToAttrListElement outputs; @@ -241,16 +259,17 @@ rec { outputsList = map makeOutput outputs; drv' = (lib.head outputsList).value; - in lib.deepSeq drv' drv'; + in if drv == null then null else + lib.deepSeq drv' drv'; /* Make a set of packages with a common scope. All packages called - with the provided `callPackage' will be evaluated with the same + with the provided `callPackage` will be evaluated with the same arguments. Any package in the set may depend on any other. The `overrideScope'` function allows subsequent modification of the package set in a consistent way, i.e. all packages in the set will be called with the overridden packages. The package sets may be hierarchical: the packages in the set are called with the scope - provided by `newScope' and the set provides a `newScope' attribute + provided by `newScope` and the set provides a `newScope` attribute which can form the parent scope for later package sets. */ makeScope = newScope: f: let self = f self // { |