diff options
| author | Pol Dellaiera <pol.dellaiera@protonmail.com> | 2025-04-19 22:09:31 +0200 |
|---|---|---|
| committer | Pol Dellaiera <pol.dellaiera@protonmail.com> | 2025-04-21 08:18:03 +0200 |
| commit | 9761d7f89fb73feef3849fca6c0bcd16b1bc0a01 (patch) | |
| tree | 787412b188bf61b22a70f581b4b26fc6a28edcef | |
| parent | doc: add missing phase hooks (diff) | |
| download | nixpkgs-9761d7f89fb73feef3849fca6c0bcd16b1bc0a01.tar.gz | |
doc: use `finalAttrs` pattern
(cherry picked from commit b4515ff6c24516b4a19262239a5002d9553ca750)
| -rw-r--r-- | doc/hooks/tauri.section.md | 10 | ||||
| -rw-r--r-- | doc/languages-frameworks/go.section.md | 6 | ||||
| -rw-r--r-- | doc/languages-frameworks/javascript.section.md | 6 | ||||
| -rw-r--r-- | doc/languages-frameworks/maven.section.md | 24 | ||||
| -rw-r--r-- | doc/languages-frameworks/rust.section.md | 43 | ||||
| -rw-r--r-- | doc/languages-frameworks/swift.section.md | 10 | ||||
| -rw-r--r-- | doc/languages-frameworks/texlive.section.md | 6 | ||||
| -rw-r--r-- | doc/stdenv/stdenv.chapter.md | 11 |
8 files changed, 59 insertions, 57 deletions
diff --git a/doc/hooks/tauri.section.md b/doc/hooks/tauri.section.md index 3fad872e4306..8382d8c27316 100644 --- a/doc/hooks/tauri.section.md +++ b/doc/hooks/tauri.section.md @@ -23,14 +23,14 @@ In Nixpkgs, `cargo-tauri.hook` overrides the default build and install phases. wrapGAppsHook4, }: -rustPlatform.buildRustPackage rec { - # . . . +rustPlatform.buildRustPackage (finalAttrs: { + # ... 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 = "..."; }; @@ -60,8 +60,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 7ec4d656b678..66c347c17bf5 100644 --- a/doc/languages-frameworks/go.section.md +++ b/doc/languages-frameworks/go.section.md @@ -39,14 +39,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="; }; @@ -58,7 +58,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 aca9c6dd6e01..9a42d624cfa5 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 92bdd90732a4..509c34c949d3 100644 --- a/doc/languages-frameworks/maven.section.md +++ b/doc/languages-frameworks/maven.section.md @@ -286,7 +286,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"; @@ -309,7 +309,7 @@ stdenv.mkDerivation rec { runHook postInstall ''; -} +}) ``` ::: {.tip} @@ -357,7 +357,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"; @@ -380,16 +380,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} @@ -450,7 +450,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"; @@ -475,15 +475,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 d30276fcf533..4b92e491ca65 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 = "12.1.1"; src = fetchFromGitHub { owner = "BurntSushi"; - repo = pname; - rev = version; + repo = "ripgrep"; + tag = finalAttrs.version; hash = "sha256-+s5RBC3XSgb8omTbUNLywZnP6jSxZBKSS1BmXOjRF8M="; }; @@ -47,7 +47,7 @@ rustPlatform.buildRustPackage rec { license = lib.licenses.unlicense; maintainers = [ ]; }; -} +}) ``` `buildRustPackage` requires a `cargoHash` attribute, computed over all crate sources of this package. @@ -114,20 +114,20 @@ 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="; }; - cargoHash = "sha256-tbrTbutUs5aPSV+yE0IBUZAAytgmZV7Eqxia7g+9zRs="; - cargoDepsName = pname; + cargoHash = "sha256-iDYh52rj1M5Uupvbx2WeDd/jvQZ+2A50V5rp5e2t7q4="; + cargoDepsName = finalAttrs.pname; # ... -} +}) ``` ### Importing a `Cargo.lock` file {#importing-a-cargo.lock-file} @@ -193,7 +193,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"; @@ -218,7 +218,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"; @@ -244,7 +244,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"; @@ -436,7 +436,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 @@ -724,7 +724,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"; @@ -732,12 +732,12 @@ stdenv.mkDerivation rec { domain = "gitlab.gnome.org"; owner = "World"; repo = "health"; - rev = version; + tag = finalAttrs.version; hash = "sha256-PrNPprSS98yN8b8yw2G6hzTSaoE65VbsM3q7FVB4mds="; }; - cargoDeps = rustPlatform.fetchCargoTarball { - inherit pname version src; + cargoDeps = rustPlatform.fetchCargoVendor { + inherit (finalAttrs) pname version src; hash = "sha256-8fa3fa+sFi5H+49B5sr2vYPkp9C9s6CcE0zv4xB8gww="; }; @@ -759,7 +759,7 @@ stdenv.mkDerivation rec { ]; # ... -} +}) ``` ## `buildRustCrate`: Compiling Rust crates using Nix instead of Cargo {#compiling-rust-crates-using-nix-instead-of-cargo} @@ -1019,19 +1019,20 @@ let }; in -rustPlatform.buildRustPackage rec { +rustPlatform.buildRustPackage (finalAttrs: { pname = "ripgrep"; version = "12.1.1"; src = fetchFromGitHub { owner = "BurntSushi"; repo = "ripgrep"; - rev = version; + tag = finalAttrs.version; hash = "sha256-+s5RBC3XSgb8omTbUNLywZnP6jSxZBKSS1BmXOjRF8M="; }; cargoHash = "sha256-l1vL2ZdtDRxSGvP0X/l3nMw8+6WF67KPutJEzUROjg8="; + # Tests require network access. Skipping. doCheck = false; meta = { @@ -1043,7 +1044,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 d7dca3b9de15..bad8e1aaeb2a 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 @@ -230,12 +231,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="; }; |
