about summary refs log tree commit diff
path: root/lib/customisation.nix
AgeCommit message (Collapse)AuthorFilesLines
2024-03-22doc: migrate lib.customisation to use doc-commentsJohannes Kirschbauer1-88/+229
2024-03-09doc: actually document `lib.customisation.makeScope` (#294194)Valentin Gagarin1-11/+122
* doc: actually document `lib.customisation.makeScope`
2024-02-28lib/customization: propagate function arguments in callPackagesWithAndrew Childs1-1/+2
makeOverridable is very careful to ensure the arguments to the overridden function are the same as the input function. As a result, the arguments of hello.override are exactly the same as the original arguments of the hello function that produced the derivation. However, callPackagesWith calls makeOverridable with a lambda that does not propagate the arguments. The override function for a package instantiated with callPackagesWith will not have the original arguments. For example: nix-repl> lib.functionArgs hello.override { callPackage = false; fetchurl = false; hello = false; lib = false; nixos = false; stdenv = false; testers = false; } nix-repl> lib.functionArgs openssl.override { } By copying the arguments onto the inner lambda before passing it to makeOverridable, we can make callPackage and callPackages behave the same. nix-repl> lib.functionArgs openssl.override { buildPackages = false; coreutils = false; cryptodev = false; enableSSL2 = true; enableSSL3 = true; fetchurl = false; lib = false; perl = false; removeReferencesTo = false; static = true; stdenv = false; withCryptodev = true; withPerl = true; }
2024-01-07lib.callPackageWith: Use abort, not throwSilvan Mosberger1-1/+5
This reverts f8ea911f7c4e44b167d4b1b51f6d00ebd93e1ed1, see also https://github.com/NixOS/nixpkgs/pull/271123#discussion_r1442134594
2023-12-08lib.callPackageWith: Optimize levenshtein sortRobert Hensing1-2/+2
Probably not significant because of the limits already applied. This is mostly cleanup.
2023-12-03lib/customisation: fix eval error (attribute "levenshtein" missing)Someone Serge1-2/+2
2023-12-03lib/customisation: fix callPackage error messagesK9001-2/+3
2023-11-30lib.customisation.callPackageWith: use throw, not abortAdam Joseph1-1/+3
2023-11-27lib.customisation: Don't allocate intermediate list for missing argsadisbladis1-3/+3
2023-11-27lib.customisation: Inherit lib/builtins into scopeadisbladis1-39/+50
It makes the code more readable if we have less nested attrsets being accessed.
2023-11-07lib.makeOverridable: simplify function arguments preservationYueh-Shun Li1-8/+10
Rename temporary variable copyArgs -> mirrorArgs. Use lib.mirrorFunctionArgs to define `mirrorArgs`. Apply mirrorArgs also to the returned function.
2023-11-02lib.makeScopeWithSplicing': add commentsArtturin1-0/+17
I didn't add these arguments, so these comments are from my understading of the arguments.
2023-10-21lib.overrideDerivation: inter-link the documentationYueh-Shun Li1-2/+1
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
2023-10-21doc: lib.customization: add Type and Example tagsYueh-Shun Li1-19/+70
Add the "Type:" blocks. Move the examples below the descriptions whenever possibles Add "Example:" tags before the examples moved below the descriptions.
2023-10-11lib.makeOverridable: fix functionArgs on returned functionRobert Hensing1-3/+4
2023-09-13doc: Replace `sha256` with `hash` where appropriatenicoo1-1/+1
2023-08-21makeScopeWithSplicing: fix `makeScopeWithSplicing'` callArtturin1-4/+4
makeScopeWithSplicing: fix comment
2023-08-20Merge pull request #245957 from ↵Artturi1-8/+21
amjoseph-nixpkgs/pr/lib/customization/makeScopeWithSplicing2
2023-08-14lib.customisation.makeScope: Make `overrideScope` consistent with ↵Artturin1-4/+5
`makeScopeWithSplicing` Right now converting `makeScope` to `makeScopeWithSplicing` is not transparent to users and requires adding a warning for `overrideScope'` in the set itself. Warning and `overrideScope'` were added in 2018 b9dce11712d2bfc8cd367df5a7f737a5cec1e252 and there should be no users left after 5 years.
2023-08-14lib.customisation: add uncurried form of makeScopeWithSplicingAdam Joseph1-8/+21
Deeply-curried functions are pretty error-prone in untyped languages like Nix. This is a particularly bad case because `top-level/splice.nix` *also* declares a makeScopeWithSplicing, but it takes *two fewer arguments*. Let's add a version that uses attrset-passing form, to provide some minimal level of sanity-checking. This also provides defaults for keep and extra (these are often unneeded by the user).
2023-07-28Revert "lib.customisation: uncurry makeScopeWithSplicing"Silvan Mosberger1-14/+8
2023-07-28lib.makeScopeWithSplicing: provide default for keep,extraArtturin1-1/+9
These are often unneeded by the user.
2023-07-27lib.customisation: uncurry makeScopeWithSplicingAdam Joseph1-8/+6
Deeply-curried functions are pretty error-prone in untyped languages like Nix. This is a particularly bad case because `top-level/splice.nix` *also* declares a makeScopeWithSplicing, but it takes *two fewer arguments*. Let's switch to attrset-passing form, to provide some minimal level of sanity-checking.
2023-06-22splice.nix: finish nativeDrv,crossDrv removalArtturin1-6/+0
2023-03-24lib/customisation: callPackageWith should abort with errorsCole Helbling1-1/+1
ofborg relies on the behavior that existed prior to 1c00bf394867b07ed7a908408d8bc1d0afd9fa49, where evaluation would immediately abort due to a missing argument (whether it be an aliased package when `allowAliases = false;` or a typo'd or otherwise nonexistent package). If `callPackageWith` `throw`s instead of `abort`s, the following `nix-env` invocation does not fail fast but instead silently skips the attribute (assuming there is a package that has an aliased package in its `autoArgs`): $ nix-env -qa --json --file . --arg config '{ allowAliases = false; }' &>/dev/null $ echo $? 0 This does change the error output when there is a missing package (for any of the reasons mentioned above), though. Before this change, the errors looked like this: $ nix-build -A hello --arg config '{ allowAliases = false; }' error: … while calling the 'throw' builtin at /home/vin/workspace/vcs/nixpkgs/master/lib/customisation.nix:179:65: 178| 179| in if missingArgs == [] then makeOverridable f allArgs else throw error; | ^ 180| error: Function called without required argument "bash_5" at /home/vin/workspace/vcs/nixpkgs/master/pkgs/applications/misc/hello/default.nix:8, did you mean "bash" or "bashdb"? And the errors now look like this: $ nix-build -A hello --arg config '{ allowAliases = false; }' error: … while calling the 'abort' builtin at /home/vin/workspace/vcs/nixpkgs/master/lib/customisation.nix:179:65: 178| 179| in if missingArgs == [] then makeOverridable f allArgs else abort error; | ^ 180| error: evaluation aborted with the following error message: 'Function called without required argument "bash_5" at /home/vin/workspace/vcs/nixpkgs/master/pkgs/applications/misc/hello/default.nix:8, did you mean "bash" or "bashdb"?'
2023-02-03Merge pull request #211685 from Artturin/splicingstuff1-splitArtturi1-1/+8
2023-01-30lib.hydraJob: Tolerate nullRobert Hensing1-1/+2
By allowing null, we allow code to avoid filterAttrs, improving laziness in real world use cases. Specifically, this strategy prevents infinite recursion errors, performance issues and possibly other errors that are unrelated to the user's code.
2023-01-20lib.extendDerivation: Fix interaction between output selection and overrideAttrsRobert Hensing1-1/+8
2023-01-02lib: Fix mismatched quotes in `lib.*` doc commentsYoshiRulz1-11/+11
caused problems for automated rich text generation such as https://teu5us.github.io/nix-lib.html#customisation-functions
2023-01-01lib/customisation.overrideDerivation: propagate evaluation conditionNaïm Favier1-1/+9
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`.
2022-11-19splice.nix: start deprecating nativeDrv and crossDrvArtturin1-0/+1
2022-11-18lib.overrideDerivation: override attrs in __splicedArtturin1-6/+8
2022-04-01lib/customization: Improve callPackage error message for missing argsSilvan Mosberger1-2/+49
This uses the levenshtein distance to look through all possible arguments to find ones that are close to what was requested: error: Function in /home/infinisil/src/nixpkgs/pkgs/tools/text/ripgrep/default.nix called without required argument "fetchFromGithub", did you mean "fetchFromGitHub" or "fetchFromGitLab"? With https://github.com/NixOS/nix/pull/3468 (in current nixUnstable) the error message becomes even better, adding line location info
2021-10-15lib: make extendDerivation lighter on evalpennae1-3/+2
the fix to extendDerivation in #140051 unwittingly worsened eval performance by quite a bit. set elements alone needed over 1GB extra after the change, which seems disproportionate to how small it was. if we flip the logic used to determine which outputs to install around and keep a "this one exactly" flag in the specific outputs instead of a "all of them" in the root we can avoid most of that cost.
2021-09-30fix nested calls to extendDerivationpennae1-1/+2
if extendDerivation is called on something that already had extendDerivation called on it (eg a mkDerivation result) the second call will set outputUnspecified=true on every output by way of propagating attributes of the full derivation to the individual outputs. this in turn causes buildEnv--and thus nix-shell and environment.systemPackages--to install every output of such a derivation even when only a specific output was requested, which renders the point of multiple outputs moot. this happens in python modules (see #139756), though it seems that tcl and possibly others should also be affected.
2021-05-06treewide: Do a number of no-op cleanups for cross and darwinJohn Ericson1-3/+5
I am taking the non-invasive parts of #110914 to hopefully help out with #111988. In particular: - Use `lib.makeScopeWithSplicing` to make the `darwin` package set have a proper `callPackage`. - Adjust Darwin `stdenv`'s overlays keeping things from the previous stage to not stick around too much. - Expose `binutilsNoLibc` / `darwin.binutilsNoLibc` to hopefully get us closer to a unified LLVM and GCC bootstrap.
2020-11-19lib: Create `makeScopeWithSplicing`John Ericson1-0/+27
It's ugly as hell, but I suppose it is needed to codify how to make spliced package sets.
2020-03-12lib.callPackages(With): guard against a repeated mistakeVladimír Čunát1-1/+6
For example see the parent commit.
2019-10-22Merge pull request #67809 from Infinisil/propagate-override-argsSilvan Mosberger1-14/+23
lib.makeOverridable: Propagate function arguments
2019-09-05lib/makeOverridable: RefactorSilvan Mosberger1-11/+14
- Rename ff to result because that's what it is - Better indentation - Less parens - Comment what overrideWith does
2019-09-05lib/makeOverridable: Remove unimplemented overrideDerivation for functionsSilvan Mosberger1-1/+0
- Apparently nobody ever needed this - We already have enough ways to override things - Using overrideDerivation is discouraged
2019-09-05lib/makeOverridable: Propagate function args of the callPackage'd functionSilvan Mosberger1-5/+6
This allows querying function arguments of things like fetchFromGitHub: nix-repl> lib.functionArgs pkgs.fetchFromGitHub { fetchSubmodules = true; githubBase = true; ... }
2019-09-05lib/makeOverridable: Propagate function arguments to override functionsSilvan Mosberger1-2/+4
This allows querying the arguments you can .override: nix-repl> lib.functionArgs pkgs.hello.override { fetchurl = false; stdenv = false; }
2019-09-05lib/makeOverridable: Abstract result overridingSilvan Mosberger1-3/+4
2019-09-05lib/makeOverridable: Deduplicate override definitionSilvan Mosberger1-2/+5
And call it overrideArgs in the let binding because that's what it does
2019-09-02Fix typo in customisation.nixGabriel Féron1-1/+1
2019-02-03lib: tiny cleanupJan Malakhovski1-1/+1
2018-10-11lib: fix wording of the `overrideScope` warningBas van Dijk1-1/+1
2018-09-24lib: Make `overrideScope'` which takes arguments in the conventional orderJohn Ericson1-5/+5
The `overrideScope` bound by `makeScope` (via special `callPackage`) took an override in the form `super: self { … }`. But this is dangerously close to the `self: super { … }` form used by *everything* else, even other definitions of `overrideScope`! Since that implementation did not even share any code either until I changed it recently in 3cf43547f4be03d1d6eb0bbfc557e2dbc13b4095, this inconsistency is almost certainly an oversight and not intentional. Unfortunately, just as the inconstency is hard to debug if one just assumes the conventional order, any sudden fix would break existing overrides in the same hard-to-debug way. So instead of changing the definition a new `overrideScope'` with the conventional order is added, and old `overrideScope` deprecated with a warning saying to use `overrideScope'` instead. That will hopefully get people to stop using `overrideScope`, freeing our hand to change or remove it in the future.
2018-08-20lib: Use lib.fixed-points.extends to avoid repetitionJohn Ericson1-1/+2
Another attempt after my sloppy https://github.com/NixOS/nixpkgs/commit/48ccdf322d9e7a68d0caf5833511ee3e53ec7d3a. @Infinisil, thanks again, reverted in https://github.com/NixOS/nixpkgs/commit/4794aa5de233b5bf2d1c3245946379699d023467 and explained my mistakes in https://github.com/NixOS/nixpkgs/commit/48ccdf322d9e7a68d0caf5833511ee3e53ec7d3a#commitcomment-29678643. I start with their work and provide this proof of this commit's correctness: ```nix (lib.fixedPoints.extends (lib.flip g) f) # now ((f: rattrs: self: let super = rattrs self; in super // f self super) (lib.flip g) f) # inline extends (self: let super = f self; in super // (lib.flip g) self super) # beta reduce (self: let super = f self; in super // g super self) # beta reduce (self_: let super = f self_; in super // g super self_) # alpha rename (self_: let super = f self_; in super // g super self_) # original, same ``` Eventually we might harmonize `overrideScope`'s `g` parameter with the general pattern, but I leave that breaking change as a separate step. Best not to refactor and break at once, and at least the abstractions make the oddity clearer.