Commit Graph

93 Commits

Author SHA1 Message Date
Kazuki Okamoto
55eedcc6dc
just fix markup 2024-08-17 16:47:58 +09:00
Johannes Kirschbauer
3dfd61965e
doc: migrate lib.customisation to use doc-comments 2024-03-22 10:02:09 +01:00
Valentin Gagarin
41298a0dff
doc: actually document lib.customisation.makeScope (#294194)
* doc: actually document `lib.customisation.makeScope`
2024-03-09 19:29:13 +01:00
Andrew Childs
741377b300 lib/customization: propagate function arguments in callPackagesWith
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-02-28 15:29:08 +02:00
Silvan Mosberger
56df668386 lib.callPackageWith: Use abort, not throw
This reverts f8ea911f7c, see also https://github.com/NixOS/nixpkgs/pull/271123#discussion_r1442134594
2024-01-07 23:31:11 +01:00
Robert Hensing
016993237f lib.callPackageWith: Optimize levenshtein sort
Probably not significant because of the limits already applied.
This is mostly cleanup.
2023-12-08 22:15:29 +01:00
Someone Serge
a3006991c3
lib/customisation: fix eval error (attribute "levenshtein" missing) 2023-12-03 03:49:22 +00:00
K900
37445f3c5c lib/customisation: fix callPackage error messages 2023-12-03 01:28:17 +03:00
Adam Joseph
f8ea911f7c lib.customisation.callPackageWith: use throw, not abort 2023-11-30 07:43:16 +01:00
adisbladis
8d162ec7b8 lib.customisation: Don't allocate intermediate list for missing args 2023-11-27 21:06:42 +13:00
adisbladis
7903613b0b lib.customisation: Inherit lib/builtins into scope
It makes the code more readable if we have less nested attrsets being accessed.
2023-11-27 21:06:41 +13:00
Yueh-Shun Li
6a8b6b8f72 lib.makeOverridable: simplify function arguments preservation
Rename temporary variable copyArgs -> mirrorArgs.
Use lib.mirrorFunctionArgs to define `mirrorArgs`.
Apply mirrorArgs also to the returned function.
2023-11-07 01:58:48 +00:00
Artturin
dd48cb0b34 lib.makeScopeWithSplicing': add comments
I didn't add these arguments, so these comments are from my understading of the arguments.
2023-11-02 17:47:02 +02:00
Yueh-Shun Li
0695d3e8fe lib.overrideDerivation: inter-link the documentation
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
2023-10-21 16:39:12 +08:00
Yueh-Shun Li
93b8f14a2d doc: lib.customization: add Type and Example tags
Add the "Type:" blocks.
Move the examples below the descriptions whenever possibles
Add "Example:" tags before the examples moved below the descriptions.
2023-10-21 16:39:12 +08:00
Robert Hensing
0a10279342 lib.makeOverridable: fix functionArgs on returned function 2023-10-11 22:56:53 +02:00
nicoo
fe138d36c9 doc: Replace sha256 with hash where appropriate 2023-09-13 17:24:49 +00:00
Artturin
724cc0cba3 makeScopeWithSplicing: fix makeScopeWithSplicing' call
makeScopeWithSplicing: fix comment
2023-08-21 19:57:34 +03:00
Artturi
bde196dde9
Merge pull request #245957 from amjoseph-nixpkgs/pr/lib/customization/makeScopeWithSplicing2 2023-08-20 18:57:05 +03:00
Artturin
3c1f82f99e lib.customisation.makeScope: Make overrideScope consistent with 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 b9dce11712 and there should be no users left after 5 years.
2023-08-14 18:46:47 +03:00
Adam Joseph
a1fdbae706 lib.customisation: add uncurried form of makeScopeWithSplicing
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-08-14 02:50:32 +03:00
Silvan Mosberger
a0b8caf3bc
Revert "lib.customisation: uncurry makeScopeWithSplicing" 2023-07-28 23:04:09 +02:00
Artturin
3716ef19d8 lib.makeScopeWithSplicing: provide default for keep,extra
These are often unneeded by the user.
2023-07-28 17:41:01 +03:00
Adam Joseph
cb13669b00 lib.customisation: uncurry makeScopeWithSplicing
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-07-27 21:31:59 -07:00
Artturin
ec7d5c518c splice.nix: finish nativeDrv,crossDrv removal 2023-06-22 23:11:08 +03:00
Cole Helbling
d9f767600f lib/customisation: callPackageWith should abort with errors
ofborg relies on the behavior that existed prior to
1c00bf3948, 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-03-24 14:22:11 -07:00
Artturi
dcc7df7fe6
Merge pull request #211685 from Artturin/splicingstuff1-split 2023-02-03 12:49:08 +02:00
Robert Hensing
473ac9692e lib.hydraJob: Tolerate null
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-30 00:35:34 +01:00
Robert Hensing
5b2f597b11 lib.extendDerivation: Fix interaction between output selection and overrideAttrs 2023-01-20 02:45:34 +02:00
YoshiRulz
7fba83890c
lib: Fix mismatched quotes in lib.* doc comments
caused problems for automated rich text generation such as
https://teu5us.github.io/nix-lib.html#customisation-functions
2023-01-02 08:25:17 +10:00
Naïm Favier
4df10debe7
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`.
2023-01-01 14:10:42 +01:00
Artturin
341e6fd558 splice.nix: start deprecating nativeDrv and crossDrv 2022-11-19 00:04:54 +02:00
Artturin
7022556622 lib.overrideDerivation: override attrs in __spliced 2022-11-18 18:44:12 +02:00
Silvan Mosberger
1c00bf3948 lib/customization: Improve callPackage error message for missing args
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
2022-04-01 22:03:05 +02:00
pennae
dc895fb281 lib: make extendDerivation lighter on eval
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-10-15 16:39:10 +02:00
pennae
9b3b8f74bb fix nested calls to extendDerivation
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-09-30 17:34:07 +02:00
John Ericson
470640e7fe treewide: Do a number of no-op cleanups for cross and darwin
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.
2021-05-06 11:17:26 -04:00
John Ericson
a6218c058b lib: Create makeScopeWithSplicing
It's ugly as hell, but I suppose it is needed to codify how to make
spliced package sets.
2020-11-19 00:07:14 -05:00
Vladimír Čunát
b63f684b3d
lib.callPackages(With): guard against a repeated mistake
For example see the parent commit.
2020-03-12 09:40:15 +01:00
Silvan Mosberger
1230fc8674
Merge pull request #67809 from Infinisil/propagate-override-args
lib.makeOverridable: Propagate function arguments
2019-10-22 14:37:40 +02:00
Silvan Mosberger
a4896cb4aa
lib/makeOverridable: Refactor
- Rename ff to result because that's what it is
- Better indentation
- Less parens
- Comment what overrideWith does
2019-09-05 00:57:55 +02:00
Silvan Mosberger
23e72eff41
lib/makeOverridable: Remove unimplemented overrideDerivation for functions
- Apparently nobody ever needed this
- We already have enough ways to override things
- Using overrideDerivation is discouraged
2019-09-05 00:57:22 +02:00
Silvan Mosberger
c638dac226
lib/makeOverridable: Propagate function args of the callPackage'd function
This allows querying function arguments of things like fetchFromGitHub:

  nix-repl> lib.functionArgs pkgs.fetchFromGitHub
  { fetchSubmodules = true; githubBase = true; ... }
2019-09-05 00:57:04 +02:00
Silvan Mosberger
d54bdf5504
lib/makeOverridable: Propagate function arguments to override functions
This allows querying the arguments you can .override:

  nix-repl> lib.functionArgs pkgs.hello.override
  { fetchurl = false; stdenv = false; }
2019-09-05 00:56:39 +02:00
Silvan Mosberger
e140d709c4
lib/makeOverridable: Abstract result overriding 2019-09-05 00:56:11 +02:00
Silvan Mosberger
a75080f58c
lib/makeOverridable: Deduplicate override definition
And call it overrideArgs in the let binding because that's what it does
2019-09-05 00:54:03 +02:00
Gabriel Féron
4b5afe54de
Fix typo in customisation.nix 2019-09-02 13:39:40 +02:00
Jan Malakhovski
51687d9a7f lib: tiny cleanup 2019-02-03 15:30:15 +00:00
Bas van Dijk
fceab3ec62 lib: fix wording of the overrideScope warning 2018-10-11 17:23:47 +02:00
John Ericson
b9dce11712 lib: Make overrideScope' which takes arguments in the conventional order
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 3cf43547f4, 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-09-24 17:50:11 -04:00