1
0
Fork 0
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:
Domen Kožar 2021-04-10 22:38:03 +02:00 committed by GitHub
commit ff94610fc1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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>`_
A better way is to use a variable:
Here are some better alternatives:
.. code:: nix
# instead of:
with (import <nixpkgs> {});
# try this instead:
let
pkgs = import <nixpkgs> {};
inherit (pkgs) curl jq;
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
---------------------