doc/stdenv: don't use name in examples, highlight preferring pname

This commit is contained in:
gilice 2023-04-15 15:24:15 +02:00
parent ab82a89414
commit 5d20d9ff9f

View file

@ -16,7 +16,8 @@ stdenv.mkDerivation {
} }
``` ```
(`stdenv` needs to be in scope, so if you write this in a separate Nix expression from `pkgs/all-packages.nix`, you need to pass it as a function argument.) Specifying a `name` and a `src` is the absolute minimum Nix requires. For convenience, you can also use `pname` and `version` attributes and `mkDerivation` will automatically set `name` to `"${pname}-${version}"` by default. Since [RFC 0035](https://github.com/NixOS/rfcs/pull/35), this is preferred for packages in Nixpkgs, as it allows us to reuse the version easily: (`stdenv` needs to be in scope, so if you write this in a separate Nix expression from `pkgs/all-packages.nix`, you need to pass it as a function argument.) Specifying a `name` and a `src` is the absolute minimum Nix requires. For convenience, you can also use `pname` and `version` attributes and `mkDerivation` will automatically set `name` to `"${pname}-${version}"` by default.
**Since [RFC 0035](https://github.com/NixOS/rfcs/pull/35), this is preferred for packages in Nixpkgs**, as it allows us to reuse the version easily:
```nix ```nix
stdenv.mkDerivation rec { stdenv.mkDerivation rec {
@ -33,7 +34,8 @@ Many packages have dependencies that are not provided in the standard environmen
```nix ```nix
stdenv.mkDerivation { stdenv.mkDerivation {
name = "libfoo-1.2.3"; pname = "libfoo";
version = "1.2.3";
... ...
buildInputs = [libbar perl ncurses]; buildInputs = [libbar perl ncurses];
} }
@ -45,7 +47,8 @@ Often it is necessary to override or modify some aspect of the build. To make th
```nix ```nix
stdenv.mkDerivation { stdenv.mkDerivation {
name = "fnord-4.5"; pname = "fnord";
version = "4.5";
... ...
buildPhase = '' buildPhase = ''
gcc foo.c -o foo gcc foo.c -o foo
@ -65,7 +68,8 @@ While the standard environment provides a generic builder, you can still supply
```nix ```nix
stdenv.mkDerivation { stdenv.mkDerivation {
name = "libfoo-1.2.3"; pname = "libfoo";
version = "1.2.3";
... ...
builder = ./builder.sh; builder = ./builder.sh;
} }