mirror of
https://github.com/NixOS/nix.dev.git
synced 2024-10-18 14:32:43 -04:00
Merge pull request #127 from ldesgoui/patch-1
Showcase `inherit` as an alternative to `with`
This commit is contained in:
commit
ff94610fc1
|
@ -71,14 +71,31 @@ There are a number of problems with such approach:
|
||||||
|
|
||||||
- Scoping rules around ``with`` are not intuitive, see `Nix issue for details <https://github.com/NixOS/nix/issues/490>`_
|
- Scoping rules around ``with`` are not intuitive, see `Nix issue for details <https://github.com/NixOS/nix/issues/490>`_
|
||||||
|
|
||||||
A better way is to use a variable:
|
Here are some better alternatives:
|
||||||
|
|
||||||
.. code:: nix
|
.. code:: nix
|
||||||
|
|
||||||
|
# instead of:
|
||||||
|
with (import <nixpkgs> {});
|
||||||
|
|
||||||
|
# try this instead:
|
||||||
let
|
let
|
||||||
pkgs = import <nixpkgs> {};
|
pkgs = import <nixpkgs> {};
|
||||||
|
inherit (pkgs) curl jq;
|
||||||
in ...
|
in ...
|
||||||
|
|
||||||
|
.. code:: nix
|
||||||
|
|
||||||
|
# instead of:
|
||||||
|
buildInputs = with pkgs; [ curl jq ];
|
||||||
|
|
||||||
|
# try this instead:
|
||||||
|
buildInputs = builtins.attrValues {
|
||||||
|
inherit (pkgs) curl jq;
|
||||||
|
};
|
||||||
|
|
||||||
|
# or this:
|
||||||
|
buildInputs = lib.attrVals ["curl" "jq"] pkgs
|
||||||
|
|
||||||
``<...>`` search path
|
``<...>`` search path
|
||||||
---------------------
|
---------------------
|
||||||
|
|
Loading…
Reference in a new issue