summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorPol Dellaiera <pol.dellaiera@protonmail.com>2025-04-19 22:09:31 +0200
committerPol Dellaiera <pol.dellaiera@protonmail.com>2025-04-21 07:02:49 +0200
commitb4515ff6c24516b4a19262239a5002d9553ca750 (patch)
treeb9dfd647ae0abf64661dac97838999a222cbbc06 /doc
parentdoc: add missing phase hooks (diff)
downloadnixpkgs-b4515ff6c24516b4a19262239a5002d9553ca750.tar.gz
doc: use `finalAttrs` pattern
Diffstat (limited to 'doc')
-rw-r--r--doc/hooks/tauri.section.md10
-rw-r--r--doc/languages-frameworks/go.section.md6
-rw-r--r--doc/languages-frameworks/javascript.section.md6
-rw-r--r--doc/languages-frameworks/maven.section.md24
-rw-r--r--doc/languages-frameworks/rust.section.md39
-rw-r--r--doc/languages-frameworks/swift.section.md10
-rw-r--r--doc/languages-frameworks/texlive.section.md6
-rw-r--r--doc/stdenv/stdenv.chapter.md11
8 files changed, 57 insertions, 55 deletions
diff --git a/doc/hooks/tauri.section.md b/doc/hooks/tauri.section.md
index 400e493d7fee..b46b738d5c88 100644
--- a/doc/hooks/tauri.section.md
+++ b/doc/hooks/tauri.section.md
@@ -23,15 +23,15 @@ In Nixpkgs, `cargo-tauri.hook` overrides the default build and install phases.
wrapGAppsHook4,
}:
-rustPlatform.buildRustPackage rec {
- # . . .
+rustPlatform.buildRustPackage (finalAttrs: {
+ # ...
useFetchCargoVendor = true;
cargoHash = "...";
# Assuming our app's frontend uses `npm` as a package manager
npmDeps = fetchNpmDeps {
- name = "${pname}-npm-deps-${version}";
+ name = "${finalAttrs.pname}-npm-deps-${finalAttrs.version}";
inherit src;
hash = "...";
};
@@ -61,8 +61,8 @@ rustPlatform.buildRustPackage rec {
# And make sure we build there too
buildAndTestSubdir = cargoRoot;
- # . . .
-}
+ # ...
+})
```
## Variables controlling cargo-tauri {#tauri-hook-variables-controlling}
diff --git a/doc/languages-frameworks/go.section.md b/doc/languages-frameworks/go.section.md
index 34bf913ef1e8..a4f9de176f70 100644
--- a/doc/languages-frameworks/go.section.md
+++ b/doc/languages-frameworks/go.section.md
@@ -13,14 +13,14 @@ The following is an example expression using `buildGoModule`:
```nix
{
- pet = buildGoModule rec {
+ pet = buildGoModule (finalAttrs: {
pname = "pet";
version = "0.3.4";
src = fetchFromGitHub {
owner = "knqyf263";
repo = "pet";
- rev = "v${version}";
+ rev = "v${finalAttrs.version}";
hash = "sha256-Gjw1dRrgM8D3G7v6WIM2+50r4HmTXvx0Xxme2fH9TlQ=";
};
@@ -32,7 +32,7 @@ The following is an example expression using `buildGoModule`:
license = lib.licenses.mit;
maintainers = with lib.maintainers; [ kalbasit ];
};
- };
+ });
}
```
diff --git a/doc/languages-frameworks/javascript.section.md b/doc/languages-frameworks/javascript.section.md
index ef603fca9096..f976f02a5457 100644
--- a/doc/languages-frameworks/javascript.section.md
+++ b/doc/languages-frameworks/javascript.section.md
@@ -198,14 +198,14 @@ Here's an example:
fetchFromGitHub,
}:
-buildNpmPackage rec {
+buildNpmPackage (finalAttrs: {
pname = "flood";
version = "4.7.0";
src = fetchFromGitHub {
owner = "jesec";
repo = pname;
- rev = "v${version}";
+ rev = "v${finalAttrs.version}";
hash = "sha256-BR+ZGkBBfd0dSQqAvujsbgsEPFYw/ThrylxUbOksYxM=";
};
@@ -222,7 +222,7 @@ buildNpmPackage rec {
license = lib.licenses.gpl3Only;
maintainers = with lib.maintainers; [ winter ];
};
-}
+})
```
In the default `installPhase` set by `buildNpmPackage`, it uses `npm pack --json --dry-run` to decide what files to install in `$out/lib/node_modules/$name/`, where `$name` is the `name` string defined in the package's `package.json`.
diff --git a/doc/languages-frameworks/maven.section.md b/doc/languages-frameworks/maven.section.md
index 989e645f110e..ee0fecbcc893 100644
--- a/doc/languages-frameworks/maven.section.md
+++ b/doc/languages-frameworks/maven.section.md
@@ -370,7 +370,7 @@ let
# pick a repository derivation, here we will use buildMaven
repository = callPackage ./build-maven-repository.nix { };
in
-stdenv.mkDerivation rec {
+stdenv.mkDerivation (finalAttrs: {
pname = "maven-demo";
version = "1.0";
@@ -393,7 +393,7 @@ stdenv.mkDerivation rec {
runHook postInstall
'';
-}
+})
```
::: {.tip}
@@ -441,7 +441,7 @@ We make sure to provide this classpath to the `makeWrapper`.
let
repository = callPackage ./build-maven-repository.nix { };
in
-stdenv.mkDerivation rec {
+stdenv.mkDerivation (finalAttrs: {
pname = "maven-demo";
version = "1.0";
@@ -464,16 +464,16 @@ stdenv.mkDerivation rec {
mkdir -p $out/bin
classpath=$(find ${repository} -name "*.jar" -printf ':%h/%f');
- install -Dm644 target/${pname}-${version}.jar $out/share/java
+ install -Dm644 target/maven-demo-${finalAttrs.version}.jar $out/share/java
# create a wrapper that will automatically set the classpath
# this should be the paths from the dependency derivation
- makeWrapper ${jre}/bin/java $out/bin/${pname} \
- --add-flags "-classpath $out/share/java/${pname}-${version}.jar:''${classpath#:}" \
+ makeWrapper ${jre}/bin/java $out/bin/maven-demo \
+ --add-flags "-classpath $out/share/java/maven-demo-${finalAttrs.version}.jar:''${classpath#:}" \
--add-flags "Main"
runHook postInstall
'';
-}
+})
```
#### MANIFEST file via Maven Plugin {#manifest-file-via-maven-plugin}
@@ -534,7 +534,7 @@ let
# pick a repository derivation, here we will use buildMaven
repository = callPackage ./build-maven-repository.nix { };
in
-stdenv.mkDerivation rec {
+stdenv.mkDerivation (finalAttrs: {
pname = "maven-demo";
version = "1.0";
@@ -559,15 +559,15 @@ stdenv.mkDerivation rec {
# create a symbolic link for the repository directory
ln -s ${repository} $out/repository
- install -Dm644 target/${pname}-${version}.jar $out/share/java
+ install -Dm644 target/maven-demo-${finalAttrs.version}.jar $out/share/java
# create a wrapper that will automatically set the classpath
# this should be the paths from the dependency derivation
- makeWrapper ${jre}/bin/java $out/bin/${pname} \
- --add-flags "-jar $out/share/java/${pname}-${version}.jar"
+ makeWrapper ${jre}/bin/java $out/bin/maven-demo \
+ --add-flags "-jar $out/share/java/maven-demo-${finalAttrs.version}.jar"
runHook postInstall
'';
-}
+})
```
::: {.note}
Our script produces a dependency on `jre` rather than `jdk` to restrict the runtime closure necessary to run the application.
diff --git a/doc/languages-frameworks/rust.section.md b/doc/languages-frameworks/rust.section.md
index 20d8b4824620..988add74a0ca 100644
--- a/doc/languages-frameworks/rust.section.md
+++ b/doc/languages-frameworks/rust.section.md
@@ -28,14 +28,14 @@ Rust applications are packaged by using the `buildRustPackage` helper from `rust
rustPlatform,
}:
-rustPlatform.buildRustPackage rec {
+rustPlatform.buildRustPackage (finalAttrs: {
pname = "ripgrep";
version = "14.1.1";
src = fetchFromGitHub {
owner = "BurntSushi";
- repo = pname;
- rev = version;
+ repo = "ripgrep";
+ tag = finalAttrs.version;
hash = "sha256-gyWnahj1A+iXUQlQ1O1H1u7K5euYQOld9qWm99Vjaeg=";
};
@@ -48,7 +48,7 @@ rustPlatform.buildRustPackage rec {
license = lib.licenses.unlicense;
maintainers = [ ];
};
-}
+})
```
`buildRustPackage` requires a `cargoHash` attribute, computed over all crate sources of this package.
@@ -104,21 +104,21 @@ be made invariant to the version by setting `cargoDepsName` to
`pname`:
```nix
-rustPlatform.buildRustPackage rec {
+rustPlatform.buildRustPackage (finalAttrs: {
pname = "broot";
version = "1.2.0";
src = fetchCrate {
- inherit pname version;
+ inherit (finalAttrs) pname version;
hash = "sha256-aDQA4A5mScX9or3Lyiv/5GyAehidnpKKE0grhbP1Ctc=";
};
useFetchCargoVendor = true;
cargoHash = "sha256-iDYh52rj1M5Uupvbx2WeDd/jvQZ+2A50V5rp5e2t7q4=";
- cargoDepsName = pname;
+ cargoDepsName = finalAttrs.pname;
# ...
-}
+})
```
### Importing a `Cargo.lock` file {#importing-a-cargo.lock-file}
@@ -184,7 +184,7 @@ The output hash of each dependency that uses a git source must be
specified in the `outputHashes` attribute. For example:
```nix
-rustPlatform.buildRustPackage rec {
+rustPlatform.buildRustPackage {
pname = "myproject";
version = "1.0.0";
@@ -209,7 +209,7 @@ For usage outside nixpkgs, `allowBuiltinFetchGit` could be used to
avoid having to specify `outputHashes`. For example:
```nix
-rustPlatform.buildRustPackage rec {
+rustPlatform.buildRustPackage {
pname = "myproject";
version = "1.0.0";
@@ -235,7 +235,7 @@ If you want to use different features for check phase, you can use
For example:
```nix
-rustPlatform.buildRustPackage rec {
+rustPlatform.buildRustPackage {
pname = "myproject";
version = "1.0.0";
@@ -427,7 +427,7 @@ source code in a reproducible way. If it is missing or out-of-date one can use
the `cargoPatches` attribute to update or add it.
```nix
-rustPlatform.buildRustPackage rec {
+rustPlatform.buildRustPackage {
# ...
cargoPatches = [
# a patch file to add/update Cargo.lock in the source code
@@ -705,7 +705,7 @@ Some projects, especially GNOME applications, are built with the Meson Build Sys
tinysparql,
}:
-stdenv.mkDerivation rec {
+stdenv.mkDerivation (finalAttrs: {
pname = "health";
version = "0.95.0";
@@ -713,12 +713,12 @@ stdenv.mkDerivation rec {
domain = "gitlab.gnome.org";
owner = "World";
repo = "health";
- rev = version;
+ tag = finalAttrs.version;
hash = "sha256-PrNPprSS98yN8b8yw2G6hzTSaoE65VbsM3q7FVB4mds=";
};
cargoDeps = rustPlatform.fetchCargoVendor {
- inherit pname version src;
+ inherit (finalAttrs) pname version src;
hash = "sha256-eR1ZGtTZQNhofFUEjI7IX16sMKPJmAl7aIFfPJukecg=";
};
@@ -740,7 +740,7 @@ stdenv.mkDerivation rec {
];
# ...
-}
+})
```
## `buildRustCrate`: Compiling Rust crates using Nix instead of Cargo {#compiling-rust-crates-using-nix-instead-of-cargo}
@@ -1000,20 +1000,21 @@ let
};
in
-rustPlatform.buildRustPackage rec {
+rustPlatform.buildRustPackage (finalAttrs: {
pname = "ripgrep";
version = "14.1.1";
src = fetchFromGitHub {
owner = "BurntSushi";
repo = "ripgrep";
- rev = version;
+ tag = finalAttrs.version;
hash = "sha256-gyWnahj1A+iXUQlQ1O1H1u7K5euYQOld9qWm99Vjaeg=";
};
useFetchCargoVendor = true;
cargoHash = "sha256-9atn5qyBDy4P6iUoHFhg+TV6Ur71fiah4oTJbBMeEy4=";
+ # Tests require network access. Skipping.
doCheck = false;
meta = {
@@ -1025,7 +1026,7 @@ rustPlatform.buildRustPackage rec {
];
maintainers = with lib.maintainers; [ ];
};
-}
+})
```
Follow the below steps to try that snippet.
diff --git a/doc/languages-frameworks/swift.section.md b/doc/languages-frameworks/swift.section.md
index 8e2e5ebae0b9..b9d4b5a7cba8 100644
--- a/doc/languages-frameworks/swift.section.md
+++ b/doc/languages-frameworks/swift.section.md
@@ -82,15 +82,15 @@ let
generated = swiftpm2nix.helpers ./nix;
in
-stdenv.mkDerivation rec {
+stdenv.mkDerivation (finalAttrs: {
pname = "myproject";
version = "0.0.0";
src = fetchFromGitHub {
owner = "nixos";
- repo = pname;
- rev = version;
- hash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
+ repo = "myproject";
+ tag = finalAttrs.version;
+ hash = "";
};
# Including SwiftPM as a nativeBuildInput provides a buildPhase for you.
@@ -117,7 +117,7 @@ stdenv.mkDerivation rec {
runHook postInstall
'';
-}
+})
```
### Custom build flags {#ssec-swiftpm-custom-build-flags}
diff --git a/doc/languages-frameworks/texlive.section.md b/doc/languages-frameworks/texlive.section.md
index 2a945827a487..b3a13dc8b8d2 100644
--- a/doc/languages-frameworks/texlive.section.md
+++ b/doc/languages-frameworks/texlive.section.md
@@ -94,18 +94,18 @@ Release 23.11 ships with a new interface that will eventually replace `texlive.c
- TeX Live packages are also available under `texlive.pkgs` as derivations with outputs `out`, `tex`, `texdoc`, `texsource`, `tlpkg`, `man`, `info`. They cannot be installed outside of `texlive.combine` but are available for other uses. To repackage a font, for instance, use
```nix
- stdenvNoCC.mkDerivation rec {
+ stdenvNoCC.mkDerivation (finalAttrs: {
src = texlive.pkgs.iwona;
dontUnpack = true;
- inherit (src) pname version;
+ inherit (finalAttrs.src) pname version;
installPhase = ''
runHook preInstall
install -Dm644 $src/fonts/opentype/nowacki/iwona/*.otf -t $out/share/fonts/opentype
runHook postInstall
'';
- }
+ })
```
See `biber`, `iwona` for complete examples.
diff --git a/doc/stdenv/stdenv.chapter.md b/doc/stdenv/stdenv.chapter.md
index 3ff1ea08e2e9..c7c907da44bc 100644
--- a/doc/stdenv/stdenv.chapter.md
+++ b/doc/stdenv/stdenv.chapter.md
@@ -20,14 +20,14 @@ stdenv.mkDerivation {
**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
-stdenv.mkDerivation rec {
+stdenv.mkDerivation (finalAttrs: {
pname = "libfoo";
version = "1.2.3";
src = fetchurl {
- url = "http://example.org/libfoo-source-${version}.tar.bz2";
+ url = "http://example.org/libfoo-source-${finalAttrs.version}.tar.bz2";
hash = "sha256-tWxU/LANbQE32my+9AXyt3nCT7NBVfJ45CX757EMT3Q=";
};
-}
+})
```
Many packages have dependencies that are not provided in the standard environment. It’s usually sufficient to specify those dependencies in the `buildInputs` attribute:
@@ -63,6 +63,7 @@ stdenv.mkDerivation {
runHook postBuild
'';
+
installPhase = ''
runHook preInstall
@@ -222,12 +223,12 @@ These dependencies are only injected when [`doCheck`](#var-stdenv-doCheck) is se
Consider for example this simplified derivation for `solo5`, a sandboxing tool:
```nix
-stdenv.mkDerivation rec {
+stdenv.mkDerivation (finalAttrs: {
pname = "solo5";
version = "0.7.5";
src = fetchurl {
- url = "https://github.com/Solo5/solo5/releases/download/v${version}/solo5-v${version}.tar.gz";
+ url = "https://github.com/Solo5/solo5/releases/download/v${finalAttrs.version}/solo5-v${finalAttrs.version}.tar.gz";
hash = "sha256-viwrS9lnaU8sTGuzK/+L/PlMM/xRRtgVuK5pixVeDEw=";
};