From 2ab19787ce2ac77f7b33e85247b9b28159b4bb95 Mon Sep 17 00:00:00 2001 From: Mauro Bieg Date: Mon, 26 Aug 2019 14:38:18 +0200 Subject: Docs: clarify Rust overlay on non-NixOS --- doc/languages-frameworks/rust.section.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'doc/languages-frameworks/rust.section.md') diff --git a/doc/languages-frameworks/rust.section.md b/doc/languages-frameworks/rust.section.md index 2d9338f2e89..fe2a71c35ef 100644 --- a/doc/languages-frameworks/rust.section.md +++ b/doc/languages-frameworks/rust.section.md @@ -384,12 +384,13 @@ in the `~/.config/nixpkgs/overlays` directory. The latest version can be installed with the following command: - $ nix-env -Ai nixos.latest.rustChannels.stable.rust + $ nix-env -Ai nixpkgs.latest.rustChannels.stable.rust Or using the attribute with nix-shell: - $ nix-shell -p nixos.latest.rustChannels.stable.rust + $ nix-shell -p nixpkgs.latest.rustChannels.stable.rust +Substitute the `nixpkgs` prefix with `nixos` on NixOS. To install the beta or nightly channel, "stable" should be substituted by "nightly" or "beta", or use the function provided by this overlay to pull a version based on a -- cgit 1.4.1 From 0cad09a68a6959ab5d304d23a54a3a4f29b22fab Mon Sep 17 00:00:00 2001 From: Alexandre Esteves <2335822+alexfmpe@users.noreply.github.com> Date: Tue, 8 Sep 2020 18:50:59 +0100 Subject: docs/rust: fix typo Co-authored-by: Drew --- doc/languages-frameworks/rust.section.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'doc/languages-frameworks/rust.section.md') diff --git a/doc/languages-frameworks/rust.section.md b/doc/languages-frameworks/rust.section.md index 6c51da87cab..7f9d93216ed 100644 --- a/doc/languages-frameworks/rust.section.md +++ b/doc/languages-frameworks/rust.section.md @@ -50,7 +50,7 @@ rustPlatform.buildRustPackage rec { `buildRustPackage` requires a `cargoSha256` attribute which is computed over all crate sources of this package. Currently it is obtained by inserting a fake checksum into the expression and building the package once. The correct -checksum can be then take from the failed build. +checksum can then be taken from the failed build. Per the instructions in the [Cargo Book](https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html) best practices guide, Rust applications should always commit the `Cargo.lock` -- cgit 1.4.1 From e4c71e6c6c7612f8e0d40ba5b79322f0883fa500 Mon Sep 17 00:00:00 2001 From: zowoq <59103226+zowoq@users.noreply.github.com> Date: Wed, 9 Sep 2020 21:39:23 +1000 Subject: buildRustPackage: support setting test-threads --- doc/languages-frameworks/rust.section.md | 12 ++++++++++++ pkgs/build-support/rust/default.nix | 5 ++++- 2 files changed, 16 insertions(+), 1 deletion(-) (limited to 'doc/languages-frameworks/rust.section.md') diff --git a/doc/languages-frameworks/rust.section.md b/doc/languages-frameworks/rust.section.md index 7f9d93216ed..0e1d59e1a95 100644 --- a/doc/languages-frameworks/rust.section.md +++ b/doc/languages-frameworks/rust.section.md @@ -119,6 +119,18 @@ The above are just guidelines, and exceptions may be granted on a case-by-case b However, please check if it's possible to disable a problematic subset of the test suite and leave a comment explaining your reasoning. +#### Setting `test-threads` + +`buildRustPackage` will use parallel test threads by default, +sometimes it may be necessary to disable this so the tests run consecutively. + +```nix +rustPlatform.buildRustPackage { + /* ... */ + cargoParallelTestThreads = false; +} +``` + ### Building a package in `debug` mode By default, `buildRustPackage` will use `release` mode for builds. If a package diff --git a/pkgs/build-support/rust/default.nix b/pkgs/build-support/rust/default.nix index 0103e064828..f6177ce198d 100644 --- a/pkgs/build-support/rust/default.nix +++ b/pkgs/build-support/rust/default.nix @@ -30,6 +30,8 @@ , cargoVendorDir ? null , checkType ? buildType , depsExtraArgs ? {} +, cargoParallelTestThreads ? true + # Needed to `pushd`/`popd` into a subdir of a tarball if this subdir # contains a Cargo.toml, but isn't part of a workspace (which is e.g. the # case for `rustfmt`/etc from the `rust-sources). @@ -204,11 +206,12 @@ stdenv.mkDerivation ((removeAttrs args ["depsExtraArgs"]) // { checkPhase = args.checkPhase or (let argstr = "${stdenv.lib.optionalString (checkType == "release") "--release"} --target ${rustTarget} --frozen"; + threads = if cargoParallelTestThreads then "$NIX_BUILD_CORES" else "1"; in '' ${stdenv.lib.optionalString (buildAndTestSubdir != null) "pushd ${buildAndTestSubdir}"} runHook preCheck echo "Running cargo test ${argstr} -- ''${checkFlags} ''${checkFlagsArray+''${checkFlagsArray[@]}}" - cargo test -j $NIX_BUILD_CORES ${argstr} -- --test-threads=$NIX_BUILD_CORES ''${checkFlags} ''${checkFlagsArray+"''${checkFlagsArray[@]}"} + cargo test -j $NIX_BUILD_CORES ${argstr} -- --test-threads=${threads} ''${checkFlags} ''${checkFlagsArray+"''${checkFlagsArray[@]}"} runHook postCheck ${stdenv.lib.optionalString (buildAndTestSubdir != null) "popd"} ''); -- cgit 1.4.1 From cd2dab91d69aa4987b1d9d5c06f811e7fcd588dc Mon Sep 17 00:00:00 2001 From: Manuel Bärenz Date: Tue, 11 Aug 2020 12:21:25 +0200 Subject: Doc -> Languages & Frameworks -> Rust: Update Add information on declarative overlay usage --- doc/languages-frameworks/rust.section.md | 46 +++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 6 deletions(-) (limited to 'doc/languages-frameworks/rust.section.md') diff --git a/doc/languages-frameworks/rust.section.md b/doc/languages-frameworks/rust.section.md index 0e1d59e1a95..400f39c345c 100644 --- a/doc/languages-frameworks/rust.section.md +++ b/doc/languages-frameworks/rust.section.md @@ -16,9 +16,9 @@ cargo into the `environment.systemPackages` or bring them into scope with `nix-shell -p rustc cargo`. -For daily builds (beta and nightly) use either rustup from -nixpkgs or use the [Rust nightlies -overlay](#using-the-rust-nightlies-overlay). +For other versions such as daily builds (beta and nightly), +use either `rustup` from nixpkgs (which will manage the rust installation in your home directory), +or use Mozilla's [Rust nightlies overlay](#using-the-rust-nightlies-overlay). ## Compiling Rust applications with Cargo @@ -478,8 +478,15 @@ Mozilla provides an overlay for nixpkgs to bring a nightly version of Rust into This overlay can _also_ be used to install recent unstable or stable versions of Rust, if desired. -To use this overlay, clone -[nixpkgs-mozilla](https://github.com/mozilla/nixpkgs-mozilla), +### Rust overlay installation + +You can use this overlay by either changing your local nixpkgs configuration, +or by adding the overlay declaratively in a nix expression, e.g. in `configuration.nix`. +For more information see [#sec-overlays-install](the manual on installing overlays). + +#### Imperative rust overlay installation + +Clone [nixpkgs-mozilla](https://github.com/mozilla/nixpkgs-mozilla), and create a symbolic link to the file [rust-overlay.nix](https://github.com/mozilla/nixpkgs-mozilla/blob/master/rust-overlay.nix) in the `~/.config/nixpkgs/overlays` directory. @@ -488,7 +495,34 @@ in the `~/.config/nixpkgs/overlays` directory. $ mkdir -p ~/.config/nixpkgs/overlays $ ln -s $(pwd)/nixpkgs-mozilla/rust-overlay.nix ~/.config/nixpkgs/overlays/rust-overlay.nix -The latest version can be installed with the following command: +### Declarative rust overlay installation + +Add the following to your `configuration.nix`, `home-configuration.nix`, `shell.nix`, or similar: + +``` + nixpkgs = { + overlays = [ + (import (builtins.fetchTarball https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz)) + # Further overlays go here + ]; + }; +``` + +Note that this will fetch the latest overlay version when rebuilding your system. + +### Rust overlay usage + +The overlay contains attribute sets corresponding to different versions of the rust toolchain, such as: + +* `latest.rustChannels.stable` +* `latest.rustChannels.nightly` +* a function `rustChannelOf`, called as `(rustChannelOf { date = "2018-04-11"; channel = "nightly"; })`, or... +* `(nixpkgs.rustChannelOf { rustToolchain = ./rust-toolchain; })` if you have a local `rust-toolchain` file (see https://github.com/mozilla/nixpkgs-mozilla#using-in-nix-expressions for an example) + +Each of these contain packages such as `rust`, which contains your usual rust development tools with the respective toolchain chosen. +For example, you might want to add `latest.rustChannels.stable.rust` to the list of packages in your configuration. + +Imperatively, the latest stable version can be installed with the following command: $ nix-env -Ai nixos.latest.rustChannels.stable.rust -- cgit 1.4.1 From c0df12de5d938e1c263c992ebd648c4100e8c0a2 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Wed, 14 Oct 2020 03:37:29 +0000 Subject: rust: Add support for managing target JSON in Nix --- doc/languages-frameworks/rust.section.md | 55 ++++++++++++++++++++-- .../rust/build-rust-crate/build-crate.nix | 2 +- .../rust/build-rust-crate/configure-crate.nix | 4 +- pkgs/build-support/rust/default.nix | 2 +- pkgs/build-support/rust/sysroot/default.nix | 4 +- pkgs/development/compilers/rust/default.nix | 10 +++- pkgs/development/compilers/rust/rustc.nix | 6 +-- pkgs/development/libraries/relibc/default.nix | 3 +- 8 files changed, 72 insertions(+), 14 deletions(-) (limited to 'doc/languages-frameworks/rust.section.md') diff --git a/doc/languages-frameworks/rust.section.md b/doc/languages-frameworks/rust.section.md index 0e1d59e1a95..0f3cc5d8efb 100644 --- a/doc/languages-frameworks/rust.section.md +++ b/doc/languages-frameworks/rust.section.md @@ -63,9 +63,52 @@ The fetcher will verify that the `Cargo.lock` file is in sync with the `src` attribute, and fail the build if not. It will also will compress the vendor directory into a tar.gz archive. -### Building a crate for a different target - -To build your crate with a different cargo `--target` simply specify the `target` attribute: +### Cross compilation + +By default, Rust packages are compiled for the host platform, just like any +other package is. The `--target` passed to rust tools is computed from this. +By default, it takes the `stdenv.hostPlatform.config` and replaces components +where they are known to differ. But there are ways to customize the argument: + + - To choose a different target by name, define + `stdenv.hostPlatform.rustc.arch.config` as that name (a string), and that + name will be used instead. + + For example: + ```nix + import { + crossSystem = (import ).systems.examples.armhf-embedded // { + rustc.arch.config = "thumbv7em-none-eabi"; + }; + } + ``` + will result in: + ```shell + --target thumbv7em-none-eabi + ``` + + - To pass a completely custom target, define + `stdenv.hostPlatform.rustc.arch.config` with its name, and + `stdenv.hostPlatform.rustc.arch.custom` with the value. The value will be + serialized to JSON in a file called + `${stdenv.hostPlatform.rustc.arch.config}.json`, and the path of that file + will be used instead. + + For example: + ```nix + import { + crossSystem = (import ).systems.examples.armhf-embedded // { + rustc.arch.config = "thumb-crazy"; + rustc.arch.custom = { foo = ""; bar = ""; }; + }; + } + will result in: + ```shell + --target /nix/store/asdfasdfsadf-thumb-crazy.json # contains {"foo":"","bar":""} + ``` + +Finally, as an ad-hoc escape hatch, a computed target (string or JSON file +path) can be passed directly to `buildRustPackage`: ```nix pkgs.rustPlatform.buildRustPackage { @@ -74,6 +117,12 @@ pkgs.rustPlatform.buildRustPackage { } ``` +This is useful to avoid rebuilding Rust tools, since they are actually target +agnostic and don't need to be rebuilt. But in the future, we should always +build the Rust tools and standard library crates separately so there is no +reason not to take the `stdenv.hostPlatform.rustc`-modifying approach, and the +ad-hoc escape hatch to `buildRustPackage` can be removed. + ### Running package tests When using `buildRustPackage`, the `checkPhase` is enabled by default and runs diff --git a/pkgs/build-support/rust/build-rust-crate/build-crate.nix b/pkgs/build-support/rust/build-rust-crate/build-crate.nix index 142109cef49..84d1b2300f1 100644 --- a/pkgs/build-support/rust/build-rust-crate/build-crate.nix +++ b/pkgs/build-support/rust/build-rust-crate/build-crate.nix @@ -15,7 +15,7 @@ ++ [(mkRustcDepArgs dependencies crateRenames)] ++ [(mkRustcFeatureArgs crateFeatures)] ++ extraRustcOpts - ++ lib.optional (stdenv.hostPlatform != stdenv.buildPlatform) "--target ${rust.toRustTarget stdenv.hostPlatform} -C linker=${stdenv.hostPlatform.config}-gcc" + ++ lib.optional (stdenv.hostPlatform != stdenv.buildPlatform) "--target ${rust.toRustTargetSpec stdenv.hostPlatform} -C linker=${stdenv.hostPlatform.config}-gcc" # since rustc 1.42 the "proc_macro" crate is part of the default crate prelude # https://github.com/rust-lang/cargo/commit/4d64eb99a4#diff-7f98585dbf9d30aa100c8318e2c77e79R1021-R1022 ++ lib.optional (lib.elem "proc-macro" crateType) "--extern proc_macro" diff --git a/pkgs/build-support/rust/build-rust-crate/configure-crate.nix b/pkgs/build-support/rust/build-rust-crate/configure-crate.nix index 18587f7047c..5ada40b3b9b 100644 --- a/pkgs/build-support/rust/build-rust-crate/configure-crate.nix +++ b/pkgs/build-support/rust/build-rust-crate/configure-crate.nix @@ -135,8 +135,8 @@ in '' export CARGO_MANIFEST_DIR=$(pwd) export DEBUG="${toString (!release)}" export OPT_LEVEL="${toString optLevel}" - export TARGET="${rust.toRustTarget stdenv.hostPlatform}" - export HOST="${rust.toRustTarget stdenv.buildPlatform}" + export TARGET="${rust.toRustTargetSpec stdenv.hostPlatform}" + export HOST="${rust.toRustTargetSpec stdenv.buildPlatform}" export PROFILE=${if release then "release" else "debug"} export OUT_DIR=$(pwd)/target/build/${crateName}.out export CARGO_PKG_VERSION_MAJOR=${lib.elemAt version 0} diff --git a/pkgs/build-support/rust/default.nix b/pkgs/build-support/rust/default.nix index 0f3ff2b70e6..3f6a84b8aed 100644 --- a/pkgs/build-support/rust/default.nix +++ b/pkgs/build-support/rust/default.nix @@ -30,7 +30,7 @@ , cargoBuildFlags ? [] , buildType ? "release" , meta ? {} -, target ? rust.toRustTarget stdenv.hostPlatform +, target ? rust.toRustTargetSpec stdenv.hostPlatform , cargoVendorDir ? null , checkType ? buildType , depsExtraArgs ? {} diff --git a/pkgs/build-support/rust/sysroot/default.nix b/pkgs/build-support/rust/sysroot/default.nix index 8cfe2d55152..2625306b246 100644 --- a/pkgs/build-support/rust/sysroot/default.nix +++ b/pkgs/build-support/rust/sysroot/default.nix @@ -41,7 +41,7 @@ in rustPlatform.buildRustPackage { done export RUST_SYSROOT=$(rustc --print=sysroot) - export HOST=${rust.toRustTarget stdenv.buildPlatform} - cp -r $RUST_SYSROOT/lib/rustlib/$HOST $out + host=${rust.toRustTarget stdenv.buildPlatform} + cp -r $RUST_SYSROOT/lib/rustlib/$host $out ''; } diff --git a/pkgs/development/compilers/rust/default.nix b/pkgs/development/compilers/rust/default.nix index 0fbe5b8c0ed..fc1af5a3f94 100644 --- a/pkgs/development/compilers/rust/default.nix +++ b/pkgs/development/compilers/rust/default.nix @@ -24,7 +24,8 @@ if platform.isDarwin then "macos" else platform.parsed.kernel.name; - # Target triple. Rust has slightly different naming conventions than we use. + # Returns the name of the rust target, even if it is custom. Adjustments are + # because rust has slightly different naming conventions than we do. toRustTarget = platform: with platform.parsed; let cpu_ = platform.rustc.arch or { "armv7a" = "armv7"; @@ -34,6 +35,13 @@ in platform.rustc.config or "${cpu_}-${vendor.name}-${kernel.name}${lib.optionalString (abi.name != "unknown") "-${abi.name}"}"; + # Returns the name of the rust target if it is standard, or the json file + # containing the custom target spec. + toRustTargetSpec = platform: + if (platform.rustc.arch or {}) ? custom + then builtins.toFile (platform.rustc.config + ".json") (builtins.toJSON platform.rustc.arch.custom) + else toRustTarget platform; + # This just contains tools for now. But it would conceivably contain # libraries too, say if we picked some default/recommended versions from # `cratesIO` to build by Hydra and/or try to prefer/bias in Cargo.lock for diff --git a/pkgs/development/compilers/rust/rustc.nix b/pkgs/development/compilers/rust/rustc.nix index 65d8920c4a4..a5a49f8c3c0 100644 --- a/pkgs/development/compilers/rust/rustc.nix +++ b/pkgs/development/compilers/rust/rustc.nix @@ -70,9 +70,9 @@ in stdenv.mkDerivation rec { "--set=build.cargo=${rustPlatform.rust.cargo}/bin/cargo" "--enable-rpath" "--enable-vendor" - "--build=${rust.toRustTarget stdenv.buildPlatform}" - "--host=${rust.toRustTarget stdenv.hostPlatform}" - "--target=${rust.toRustTarget stdenv.targetPlatform}" + "--build=${rust.toRustTargetSpec stdenv.buildPlatform}" + "--host=${rust.toRustTargetSpec stdenv.hostPlatform}" + "--target=${rust.toRustTargetSpec stdenv.targetPlatform}" "${setBuild}.cc=${ccForBuild}" "${setHost}.cc=${ccForHost}" diff --git a/pkgs/development/libraries/relibc/default.nix b/pkgs/development/libraries/relibc/default.nix index 43e02fc8758..24d434bf715 100644 --- a/pkgs/development/libraries/relibc/default.nix +++ b/pkgs/development/libraries/relibc/default.nix @@ -63,7 +63,8 @@ redoxRustPlatform.buildRustPackage rec { DESTDIR=$out make install ''; - TARGET = buildPackages.rust.toRustTarget stdenvNoCC.targetPlatform; + # TODO: should be hostPlatform + TARGET = buildPackages.rust.toRustTargetSpec stdenvNoCC.targetPlatform; cargoSha256 = "1fzz7ba3ga57x1cbdrcfrdwwjr70nh4skrpxp4j2gak2c3scj6rz"; -- cgit 1.4.1 From 2bccf2e554d8fdb630f44181cf1ef787df6fb6b6 Mon Sep 17 00:00:00 2001 From: Aaron Janse Date: Sat, 17 Oct 2020 00:48:07 -0700 Subject: add documentation --- doc/languages-frameworks/rust.section.md | 3 +++ 1 file changed, 3 insertions(+) (limited to 'doc/languages-frameworks/rust.section.md') diff --git a/doc/languages-frameworks/rust.section.md b/doc/languages-frameworks/rust.section.md index 0f3cc5d8efb..784a4603098 100644 --- a/doc/languages-frameworks/rust.section.md +++ b/doc/languages-frameworks/rust.section.md @@ -123,6 +123,9 @@ build the Rust tools and standard library crates separately so there is no reason not to take the `stdenv.hostPlatform.rustc`-modifying approach, and the ad-hoc escape hatch to `buildRustPackage` can be removed. +Note that currently custom targets aren't compiled with `std`, so `cargo test` +will fail. This can be ignored by adding `doCheck = false;` to your derivation. + ### Running package tests When using `buildRustPackage`, the `checkPhase` is enabled by default and runs -- cgit 1.4.1 From b7650aaa77634e42d62ed6fc1a9081b10139618b Mon Sep 17 00:00:00 2001 From: John Ericson Date: Sat, 28 Nov 2020 19:32:43 +0000 Subject: rust: Clean up target configs and test some more See the new docs for details. The difference is vis-a-vis older versions of this PR, not master. --- doc/languages-frameworks/rust.section.md | 14 +++---- pkgs/development/compilers/rust/default.nix | 6 +-- pkgs/test/rust-sysroot/default.nix | 60 ++++++++++++++++++----------- 3 files changed, 47 insertions(+), 33 deletions(-) (limited to 'doc/languages-frameworks/rust.section.md') diff --git a/doc/languages-frameworks/rust.section.md b/doc/languages-frameworks/rust.section.md index 28e488fe8a6..0230993d3f0 100644 --- a/doc/languages-frameworks/rust.section.md +++ b/doc/languages-frameworks/rust.section.md @@ -71,14 +71,14 @@ By default, it takes the `stdenv.hostPlatform.config` and replaces components where they are known to differ. But there are ways to customize the argument: - To choose a different target by name, define - `stdenv.hostPlatform.rustc.arch.config` as that name (a string), and that + `stdenv.hostPlatform.rustc.config` as that name (a string), and that name will be used instead. For example: ```nix import { crossSystem = (import ).systems.examples.armhf-embedded // { - rustc.arch.config = "thumbv7em-none-eabi"; + rustc.config = "thumbv7em-none-eabi"; }; } ``` @@ -88,18 +88,18 @@ where they are known to differ. But there are ways to customize the argument: ``` - To pass a completely custom target, define - `stdenv.hostPlatform.rustc.arch.config` with its name, and - `stdenv.hostPlatform.rustc.arch.custom` with the value. The value will be + `stdenv.hostPlatform.rustc.config` with its name, and + `stdenv.hostPlatform.rustc.platform` with the value. The value will be serialized to JSON in a file called - `${stdenv.hostPlatform.rustc.arch.config}.json`, and the path of that file + `${stdenv.hostPlatform.rustc.config}.json`, and the path of that file will be used instead. For example: ```nix import { crossSystem = (import ).systems.examples.armhf-embedded // { - rustc.arch.config = "thumb-crazy"; - rustc.arch.custom = { foo = ""; bar = ""; }; + rustc.config = "thumb-crazy"; + rustc.platform = { foo = ""; bar = ""; }; }; } will result in: diff --git a/pkgs/development/compilers/rust/default.nix b/pkgs/development/compilers/rust/default.nix index 95febd8945d..25876cc6380 100644 --- a/pkgs/development/compilers/rust/default.nix +++ b/pkgs/development/compilers/rust/default.nix @@ -27,7 +27,7 @@ # Returns the name of the rust target, even if it is custom. Adjustments are # because rust has slightly different naming conventions than we do. toRustTarget = platform: with platform.parsed; let - cpu_ = platform.rustc.arch or { + cpu_ = platform.rustc.platform.arch or { "armv7a" = "armv7"; "armv7l" = "armv7"; "armv6l" = "arm"; @@ -38,8 +38,8 @@ # Returns the name of the rust target if it is standard, or the json file # containing the custom target spec. toRustTargetSpec = platform: - if (platform.rustc.arch or {}) ? custom - then builtins.toFile (platform.rustc.config + ".json") (builtins.toJSON platform.rustc.arch.custom) + if (platform.rustc or {}) ? platform + then builtins.toFile (toRustTarget platform + ".json") (builtins.toJSON platform.rustc.platform) else toRustTarget platform; # This just contains tools for now. But it would conceivably contain diff --git a/pkgs/test/rust-sysroot/default.nix b/pkgs/test/rust-sysroot/default.nix index cd07ef53c32..3a786ad6f00 100644 --- a/pkgs/test/rust-sysroot/default.nix +++ b/pkgs/test/rust-sysroot/default.nix @@ -1,6 +1,7 @@ -{ lib, rustPlatform, fetchFromGitHub, writeText }: +{ lib, rust, rustPlatform, fetchFromGitHub }: -rustPlatform.buildRustPackage rec { +let + mkBlogOsTest = target: rustPlatform.buildRustPackage rec { name = "blog_os-sysroot-test"; src = fetchFromGitHub { @@ -12,27 +13,7 @@ rustPlatform.buildRustPackage rec { cargoSha256 = "1cbcplgz28yxshyrp2krp1jphbrcqdw6wxx3rry91p7hiqyibd30"; - # The book uses rust-lld for linking, but rust-lld is not currently packaged for NixOS. - # The justification in the book for using rust-lld suggests that gcc can still be used for testing: - # > Instead of using the platform's default linker (which might not support Linux targets), - # > we use the cross platform LLD linker that is shipped with Rust for linking our kernel. - # https://github.com/phil-opp/blog_os/blame/7212ffaa8383122b1eb07fe1854814f99d2e1af4/blog/content/second-edition/posts/02-minimal-rust-kernel/index.md#L157 - target = writeText "x86_64-blog_os.json" '' - { - "llvm-target": "x86_64-unknown-none", - "data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128", - "arch": "x86_64", - "target-endian": "little", - "target-pointer-width": "64", - "target-c-int-width": "32", - "os": "none", - "executables": true, - "linker-flavor": "gcc", - "panic-strategy": "abort", - "disable-redzone": true, - "features": "-mmx,-sse,+soft-float" - } - ''; + inherit target; RUSTFLAGS = "-C link-arg=-nostartfiles"; @@ -42,5 +23,38 @@ rustPlatform.buildRustPackage rec { meta = with lib; { description = "Test for using custom sysroots with buildRustPackage"; maintainers = with maintainers; [ aaronjanse ]; + platforms = lib.platforms.x86_64; }; + }; + + # The book uses rust-lld for linking, but rust-lld is not currently packaged for NixOS. + # The justification in the book for using rust-lld suggests that gcc can still be used for testing: + # > Instead of using the platform's default linker (which might not support Linux targets), + # > we use the cross platform LLD linker that is shipped with Rust for linking our kernel. + # https://github.com/phil-opp/blog_os/blame/7212ffaa8383122b1eb07fe1854814f99d2e1af4/blog/content/second-edition/posts/02-minimal-rust-kernel/index.md#L157 + targetContents = { + "llvm-target" = "x86_64-unknown-none"; + "data-layout" = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"; + "arch" = "x86_64"; + "target-endian" = "little"; + "target-pointer-width" = "64"; + "target-c-int-width" = "32"; + "os" = "none"; + "executables" = true; + "linker-flavor" = "gcc"; + "panic-strategy" = "abort"; + "disable-redzone" = true; + "features" = "-mmx,-sse,+soft-float"; + }; + +in { + blogOS-targetByFile = mkBlogOsTest (builtins.toFile "x86_64-blog_os.json" (builtins.toJSON targetContents)); + blogOS-targetByNix = let + plat = lib.systems.elaborate { config = "x86_64-none"; } // { + rustc = { + config = "x86_64-blog_os"; + platform = targetContents; + }; + }; + in mkBlogOsTest (rust.toRustTargetSpec plat); } -- cgit 1.4.1 From b6728fa15c540b02fb6a336e1f6f6bb9d287f298 Mon Sep 17 00:00:00 2001 From: Daniël de Kok Date: Thu, 3 Dec 2020 09:39:39 +0100 Subject: docs/rust: describe cargoHash --- doc/languages-frameworks/rust.section.md | 35 +++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) (limited to 'doc/languages-frameworks/rust.section.md') diff --git a/doc/languages-frameworks/rust.section.md b/doc/languages-frameworks/rust.section.md index 0230993d3f0..fe394b662bb 100644 --- a/doc/languages-frameworks/rust.section.md +++ b/doc/languages-frameworks/rust.section.md @@ -27,16 +27,16 @@ Rust applications are packaged by using the `buildRustPackage` helper from `rust ``` rustPlatform.buildRustPackage rec { pname = "ripgrep"; - version = "11.0.2"; + version = "12.1.1"; src = fetchFromGitHub { owner = "BurntSushi"; repo = pname; rev = version; - sha256 = "1iga3320mgi7m853la55xip514a3chqsdi1a1rwv25lr9b1p7vd3"; + sha256 = "1hqps7l5qrjh9f914r5i6kmcz6f1yb951nv4lby0cjnp5l253kps"; }; - cargoSha256 = "17ldqr3asrdcsh4l29m3b5r37r5d0b3npq1lrgjmxb6vlx6a36qh"; + cargoSha256 = "03wf9r2csi6jpa7v5sw5lpxkrk4wfzwmzx7k3991q3bdjzcwnnwp"; meta = with stdenv.lib; { description = "A fast line-oriented regex search tool, similar to ag and ack"; @@ -47,10 +47,31 @@ rustPlatform.buildRustPackage rec { } ``` -`buildRustPackage` requires a `cargoSha256` attribute which is computed over -all crate sources of this package. Currently it is obtained by inserting a -fake checksum into the expression and building the package once. The correct -checksum can then be taken from the failed build. +`buildRustPackage` requires either the `cargoSha256` or the +`cargoHash` attribute which is computed over all crate sources of this +package. `cargoHash256` is used for traditional Nix SHA-256 hashes, +such as the one in the example above. `cargoHash` should instead be +used for [SRI](https://www.w3.org/TR/SRI/) hashes. For example: + +``` + cargoHash = "sha256-l1vL2ZdtDRxSGvP0X/l3nMw8+6WF67KPutJEzUROjg8="; +``` + +Both types of hashes are permitted when contributing to nixpkgs. The +Cargo hash is obtained by inserting a fake checksum into the +expression and building the package once. The correct checksum can +then be taken from the failed build. A fake hash can be used for +`cargoSha256` as follows: + +``` + cargoSha256 = stdenv.lib.fakeSha256; +``` + +For `cargoHash` you can use: + +``` + cargoHash = stdenv.lib.fakeHash; +``` Per the instructions in the [Cargo Book](https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html) best practices guide, Rust applications should always commit the `Cargo.lock` -- cgit 1.4.1 From b8344f9e5cd2dcd21e31d1c077393bdc7b19e860 Mon Sep 17 00:00:00 2001 From: Ryan Mulligan Date: Fri, 1 Jan 2021 09:45:43 -0800 Subject: doc: explicit Markdown anchors for top-level headings; remove metadata I used the existing anchors generated by Docbook, so the anchor part should be a no-op. This could be useful depending on the infrastructure we choose to use, and it is better to be explicit than rely on Docbook's id generating algorithms. I got rid of the metadata segments of the Markdown files, because they are outdated, inaccurate, and could make people less willing to change them without speaking with the author. --- doc/builders/packages/cataclysm-dda.section.md | 2 +- doc/builders/trivial-builders.chapter.md | 2 +- doc/languages-frameworks/agda.section.md | 7 +------ doc/languages-frameworks/android.section.md | 7 +------ doc/languages-frameworks/crystal.section.md | 2 +- doc/languages-frameworks/emscripten.section.md | 2 +- doc/languages-frameworks/haskell.section.md | 8 +------- doc/languages-frameworks/idris.section.md | 2 +- doc/languages-frameworks/ios.section.md | 7 +------ doc/languages-frameworks/lua.section.md | 8 +------- doc/languages-frameworks/maven.section.md | 8 +------- doc/languages-frameworks/node.section.md | 4 ++-- doc/languages-frameworks/python.section.md | 2 +- doc/languages-frameworks/r.section.md | 3 +-- doc/languages-frameworks/rust.section.md | 8 +------- doc/languages-frameworks/texlive.section.md | 1 - doc/languages-frameworks/titanium.section.md | 7 +------ doc/languages-frameworks/vim.section.md | 7 +------ doc/preface.chapter.md | 8 +------- 19 files changed, 19 insertions(+), 76 deletions(-) (limited to 'doc/languages-frameworks/rust.section.md') diff --git a/doc/builders/packages/cataclysm-dda.section.md b/doc/builders/packages/cataclysm-dda.section.md index ae2ee56a010..1173fe32ada 100644 --- a/doc/builders/packages/cataclysm-dda.section.md +++ b/doc/builders/packages/cataclysm-dda.section.md @@ -1,4 +1,4 @@ -# Cataclysm: Dark Days Ahead +# Cataclysm: Dark Days Ahead {#cataclysm-dark-days-ahead} ## How to install Cataclysm DDA diff --git a/doc/builders/trivial-builders.chapter.md b/doc/builders/trivial-builders.chapter.md index c39803fbe33..32944567c05 100644 --- a/doc/builders/trivial-builders.chapter.md +++ b/doc/builders/trivial-builders.chapter.md @@ -37,7 +37,7 @@ This works just like `runCommand`. The only difference is that it also provides Variant of `runCommand` that forces the derivation to be built locally, it is not substituted. This is intended for very cheap commands (<1s execution time). It saves on the network roundrip and can speed up a build. -::: {.note} +::: note This sets [`allowSubstitutes` to `false`](https://nixos.org/nix/manual/#adv-attr-allowSubstitutes), so only use `runCommandLocal` if you are certain the user will always have a builder for the `system` of the derivation. This should be true for most trivial use cases (e.g. just copying some files to a different location or adding symlinks), because there the `system` is usually the same as `builtins.currentSystem`. ::: diff --git a/doc/languages-frameworks/agda.section.md b/doc/languages-frameworks/agda.section.md index 5ba4e285f42..66b4a208302 100644 --- a/doc/languages-frameworks/agda.section.md +++ b/doc/languages-frameworks/agda.section.md @@ -1,9 +1,4 @@ ---- -title: Agda -author: Alex Rice (alexarice) -date: 2020-01-06 ---- -# Agda +# Agda {#agda} ## How to use Agda diff --git a/doc/languages-frameworks/android.section.md b/doc/languages-frameworks/android.section.md index f4f6c086a80..cfbacf1bccd 100644 --- a/doc/languages-frameworks/android.section.md +++ b/doc/languages-frameworks/android.section.md @@ -1,9 +1,4 @@ ---- -title: Android -author: Sander van der Burg -date: 2018-11-18 ---- -# Android +# Android {#android} The Android build environment provides three major features and a number of supporting features. diff --git a/doc/languages-frameworks/crystal.section.md b/doc/languages-frameworks/crystal.section.md index af0853dbf75..74790132974 100644 --- a/doc/languages-frameworks/crystal.section.md +++ b/doc/languages-frameworks/crystal.section.md @@ -1,4 +1,4 @@ -# Crystal +# Crystal {#crystal} ## Building a Crystal package diff --git a/doc/languages-frameworks/emscripten.section.md b/doc/languages-frameworks/emscripten.section.md index 3663f962d5f..8a47a7b320a 100644 --- a/doc/languages-frameworks/emscripten.section.md +++ b/doc/languages-frameworks/emscripten.section.md @@ -1,4 +1,4 @@ -# Emscripten +# Emscripten {#emscripten} [Emscripten](https://github.com/kripken/emscripten): An LLVM-to-JavaScript Compiler diff --git a/doc/languages-frameworks/haskell.section.md b/doc/languages-frameworks/haskell.section.md index 67318a5b746..1fda505a225 100644 --- a/doc/languages-frameworks/haskell.section.md +++ b/doc/languages-frameworks/haskell.section.md @@ -1,10 +1,4 @@ ---- -title: User's Guide for Haskell in Nixpkgs -author: Peter Simons -date: 2015-06-01 ---- - -# Haskell +# Haskell {#haskell} The documentation for the Haskell infrastructure is published at . The source code for that diff --git a/doc/languages-frameworks/idris.section.md b/doc/languages-frameworks/idris.section.md index f071b9ce178..2d06c4a19de 100644 --- a/doc/languages-frameworks/idris.section.md +++ b/doc/languages-frameworks/idris.section.md @@ -1,4 +1,4 @@ -# Idris +# Idris {#idris} ## Installing Idris diff --git a/doc/languages-frameworks/ios.section.md b/doc/languages-frameworks/ios.section.md index 768e0690b96..a162e8d19fd 100644 --- a/doc/languages-frameworks/ios.section.md +++ b/doc/languages-frameworks/ios.section.md @@ -1,9 +1,4 @@ ---- -title: iOS -author: Sander van der Burg -date: 2019-11-10 ---- -# iOS +# iOS {#ios} This component is basically a wrapper/workaround that makes it possible to expose an Xcode installation as a Nix package by means of symlinking to the diff --git a/doc/languages-frameworks/lua.section.md b/doc/languages-frameworks/lua.section.md index a0e9917b8ec..248e5971818 100644 --- a/doc/languages-frameworks/lua.section.md +++ b/doc/languages-frameworks/lua.section.md @@ -1,10 +1,4 @@ ---- -title: Lua -author: Matthieu Coudron -date: 2019-02-05 ---- - -# User's Guide to Lua Infrastructure +# User's Guide to Lua Infrastructure {#users-guide-to-lua-infrastructure} ## Using Lua diff --git a/doc/languages-frameworks/maven.section.md b/doc/languages-frameworks/maven.section.md index fe183e7ba3c..5f3979d69fd 100644 --- a/doc/languages-frameworks/maven.section.md +++ b/doc/languages-frameworks/maven.section.md @@ -1,10 +1,4 @@ ---- -title: Maven -author: Farid Zakaria -date: 2020-10-15 ---- - -# Maven +# Maven {#maven} Maven is a well-known build tool for the Java ecosystem however it has some challenges when integrating into the Nix build system. diff --git a/doc/languages-frameworks/node.section.md b/doc/languages-frameworks/node.section.md index 2120adfc0b4..847db22941f 100644 --- a/doc/languages-frameworks/node.section.md +++ b/doc/languages-frameworks/node.section.md @@ -1,5 +1,5 @@ -Node.js -======= +# Node.js {#node.js} + The `pkgs/development/node-packages` folder contains a generated collection of [NPM packages](https://npmjs.com/) that can be installed with the Nix package manager. diff --git a/doc/languages-frameworks/python.section.md b/doc/languages-frameworks/python.section.md index 8a2fe2711c7..2dea2cb1bcc 100644 --- a/doc/languages-frameworks/python.section.md +++ b/doc/languages-frameworks/python.section.md @@ -1,4 +1,4 @@ -# Python +# Python {#python} ## User Guide diff --git a/doc/languages-frameworks/r.section.md b/doc/languages-frameworks/r.section.md index d4e1617779c..d7154adc55b 100644 --- a/doc/languages-frameworks/r.section.md +++ b/doc/languages-frameworks/r.section.md @@ -1,5 +1,4 @@ -R -= +# R {#r} ## Installation diff --git a/doc/languages-frameworks/rust.section.md b/doc/languages-frameworks/rust.section.md index 0230993d3f0..a5b13217fe7 100644 --- a/doc/languages-frameworks/rust.section.md +++ b/doc/languages-frameworks/rust.section.md @@ -1,10 +1,4 @@ ---- -title: Rust -author: Matthias Beyer -date: 2017-03-05 ---- - -# Rust +# Rust {#rust} To install the rust compiler and cargo put diff --git a/doc/languages-frameworks/texlive.section.md b/doc/languages-frameworks/texlive.section.md index 9584c56bb52..c3028731f4e 100644 --- a/doc/languages-frameworks/texlive.section.md +++ b/doc/languages-frameworks/texlive.section.md @@ -1,4 +1,3 @@ - # TeX Live {#sec-language-texlive} Since release 15.09 there is a new TeX Live packaging that lives entirely under attribute `texlive`. diff --git a/doc/languages-frameworks/titanium.section.md b/doc/languages-frameworks/titanium.section.md index 7a97664ec59..57360f034b9 100644 --- a/doc/languages-frameworks/titanium.section.md +++ b/doc/languages-frameworks/titanium.section.md @@ -1,9 +1,4 @@ ---- -title: Titanium -author: Sander van der Burg -date: 2018-11-18 ---- -# Titanium +# Titanium {#titanium} The Nixpkgs repository contains facilities to deploy a variety of versions of the [Titanium SDK](https://www.appcelerator.com) versions, a cross-platform diff --git a/doc/languages-frameworks/vim.section.md b/doc/languages-frameworks/vim.section.md index 84ad567e8c2..155dacc237b 100644 --- a/doc/languages-frameworks/vim.section.md +++ b/doc/languages-frameworks/vim.section.md @@ -1,9 +1,4 @@ ---- -title: User's Guide for Vim in Nixpkgs -author: Marc Weber -date: 2016-06-25 ---- -# Vim +# Vim {#vim} Both Neovim and Vim can be configured to include your favorite plugins and additional libraries. diff --git a/doc/preface.chapter.md b/doc/preface.chapter.md index 549e42de7aa..64c921c711b 100644 --- a/doc/preface.chapter.md +++ b/doc/preface.chapter.md @@ -1,10 +1,4 @@ ---- -title: Preface -author: Frederik Rietdijk -date: 2015-11-25 ---- - -# Preface +# Preface {#preface} The Nix Packages collection (Nixpkgs) is a set of thousands of packages for the [Nix package manager](https://nixos.org/nix/), released under a -- cgit 1.4.1 From b0c1583a0b606560a4a47322fc849cfc1cfa0090 Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Sun, 10 Jan 2021 22:30:22 +0100 Subject: doc: stdenv.lib -> lib Part of: https://github.com/NixOS/nixpkgs/issues/108938 Changing the documentation to not refer to stdenv.lib is the first step to make people use it directly. --- doc/languages-frameworks/lua.section.md | 3 +-- doc/languages-frameworks/maven.section.md | 4 ++-- doc/languages-frameworks/ocaml.section.md | 10 +++++----- doc/languages-frameworks/perl.section.md | 8 ++++---- doc/languages-frameworks/rust.section.md | 6 +++--- doc/stdenv/meta.xml | 22 +++++++++++----------- doc/stdenv/platform-notes.xml | 2 +- doc/using/configuration.xml | 4 ++-- 8 files changed, 29 insertions(+), 30 deletions(-) (limited to 'doc/languages-frameworks/rust.section.md') diff --git a/doc/languages-frameworks/lua.section.md b/doc/languages-frameworks/lua.section.md index 248e5971818..d81949c75f6 100644 --- a/doc/languages-frameworks/lua.section.md +++ b/doc/languages-frameworks/lua.section.md @@ -181,7 +181,7 @@ luaposix = buildLuarocksPackage { disabled = (luaOlder "5.1") || (luaAtLeast "5.4"); propagatedBuildInputs = [ bit32 lua std_normalize ]; - meta = with stdenv.lib; { + meta = with lib; { homepage = "https://github.com/luaposix/luaposix/"; description = "Lua bindings for POSIX"; maintainers = with maintainers; [ vyp lblasc ]; @@ -243,4 +243,3 @@ Following rules should be respected: * Make sure libraries build for all Lua interpreters. * Commit names of Lua libraries should reflect that they are Lua libraries, so write for example `luaPackages.luafilesystem: 1.11 -> 1.12`. - diff --git a/doc/languages-frameworks/maven.section.md b/doc/languages-frameworks/maven.section.md index 5f3979d69fd..7a863c500bc 100644 --- a/doc/languages-frameworks/maven.section.md +++ b/doc/languages-frameworks/maven.section.md @@ -116,7 +116,7 @@ The first step will be to build the Maven project as a fixed-output derivation i > Traditionally the Maven repository is at `~/.m2/repository`. We will override this to be the `$out` directory. ```nix -{ stdenv, maven }: +{ stdenv, lib, maven }: stdenv.mkDerivation { name = "maven-repository"; buildInputs = [ maven ]; @@ -139,7 +139,7 @@ stdenv.mkDerivation { outputHashAlgo = "sha256"; outputHashMode = "recursive"; # replace this with the correct SHA256 - outputHash = stdenv.lib.fakeSha256; + outputHash = lib.fakeSha256; } ``` diff --git a/doc/languages-frameworks/ocaml.section.md b/doc/languages-frameworks/ocaml.section.md index 1c5a5473a05..fa85a27e84f 100644 --- a/doc/languages-frameworks/ocaml.section.md +++ b/doc/languages-frameworks/ocaml.section.md @@ -7,7 +7,7 @@ Given that most of the OCaml ecosystem is now built with dune, nixpkgs includes Here is a simple package example. It defines an (optional) attribute `minimumOCamlVersion` that will be used to throw a descriptive evaluation error if building with an older OCaml is attempted. It uses the `fetchFromGitHub` fetcher to get its source. It sets the `doCheck` (optional) attribute to `true` which means that tests will be run with `dune runtest -p angstrom` after the build (`dune build -p angstrom`) is complete. It uses `alcotest` as a build input (because it is needed to run the tests) and `bigstringaf` and `result` as propagated build inputs (thus they will also be available to libraries depending on this library). The library will be installed using the `angstrom.install` file that dune generates. ```nix -{ stdenv +{ lib , fetchFromGitHub , buildDunePackage , alcotest @@ -35,8 +35,8 @@ buildDunePackage rec { meta = { homepage = "https://github.com/inhabitedtype/angstrom"; description = "OCaml parser combinators built for speed and memory efficiency"; - license = stdenv.lib.licenses.bsd3; - maintainers = with stdenv.lib.maintainers; [ sternenseemann ]; + license = lib.licenses.bsd3; + maintainers = with lib.maintainers; [ sternenseemann ]; }; } ``` @@ -44,7 +44,7 @@ buildDunePackage rec { Here is a second example, this time using a source archive generated with `dune-release`. It is a good idea to use this archive when it is available as it will usually contain substituted variables such as a `%%VERSION%%` field. This library does not depend on any other OCaml library and no tests are run after building it. ```nix -{ stdenv +{ lib , fetchurl , buildDunePackage }: @@ -60,7 +60,7 @@ buildDunePackage rec { sha256 = "1msg3vycd3k8qqj61sc23qks541cxpb97vrnrvrhjnqxsqnh6ygq"; }; - meta = with stdenv.lib; { + meta = with lib; { homepage = "https://github.com/flowtype/ocaml-wtf8"; description = "WTF-8 is a superset of UTF-8 that allows unpaired surrogates."; license = licenses.mit; diff --git a/doc/languages-frameworks/perl.section.md b/doc/languages-frameworks/perl.section.md index 2b31da84553..309d8ebcc2b 100644 --- a/doc/languages-frameworks/perl.section.md +++ b/doc/languages-frameworks/perl.section.md @@ -110,7 +110,7 @@ ClassC3Componentised = buildPerlPackage rec { On Darwin, if a script has too many `-Idir` flags in its first line (its “shebang line”), it will not run. This can be worked around by calling the `shortenPerlShebang` function from the `postInstall` phase: ```nix -{ stdenv, buildPerlPackage, fetchurl, shortenPerlShebang }: +{ stdenv, lib, buildPerlPackage, fetchurl, shortenPerlShebang }: ImageExifTool = buildPerlPackage { pname = "Image-ExifTool"; @@ -121,8 +121,8 @@ ImageExifTool = buildPerlPackage { sha256 = "0d8v48y94z8maxkmw1rv7v9m0jg2dc8xbp581njb6yhr7abwqdv3"; }; - buildInputs = stdenv.lib.optional stdenv.isDarwin shortenPerlShebang; - postInstall = stdenv.lib.optional stdenv.isDarwin '' + buildInputs = lib.optional stdenv.isDarwin shortenPerlShebang; + postInstall = lib.optional stdenv.isDarwin '' shortenPerlShebang $out/bin/exiftool ''; }; @@ -151,7 +151,7 @@ $ nix-generate-from-cpan XML::Simple propagatedBuildInputs = [ XMLNamespaceSupport XMLSAX XMLSAXExpat ]; meta = { description = "An API for simple XML files"; - license = with stdenv.lib.licenses; [ artistic1 gpl1Plus ]; + license = with lib.licenses; [ artistic1 gpl1Plus ]; }; }; ``` diff --git a/doc/languages-frameworks/rust.section.md b/doc/languages-frameworks/rust.section.md index 231cbe900e7..092e84461b8 100644 --- a/doc/languages-frameworks/rust.section.md +++ b/doc/languages-frameworks/rust.section.md @@ -32,7 +32,7 @@ rustPlatform.buildRustPackage rec { cargoSha256 = "03wf9r2csi6jpa7v5sw5lpxkrk4wfzwmzx7k3991q3bdjzcwnnwp"; - meta = with stdenv.lib; { + meta = with lib; { description = "A fast line-oriented regex search tool, similar to ag and ack"; homepage = "https://github.com/BurntSushi/ripgrep"; license = licenses.unlicense; @@ -58,13 +58,13 @@ then be taken from the failed build. A fake hash can be used for `cargoSha256` as follows: ``` - cargoSha256 = stdenv.lib.fakeSha256; + cargoSha256 = lib.fakeSha256; ``` For `cargoHash` you can use: ``` - cargoHash = stdenv.lib.fakeHash; + cargoHash = lib.fakeHash; ``` Per the instructions in the [Cargo Book](https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html) diff --git a/doc/stdenv/meta.xml b/doc/stdenv/meta.xml index c9d1b136219..10802d1af59 100644 --- a/doc/stdenv/meta.xml +++ b/doc/stdenv/meta.xml @@ -5,7 +5,7 @@ Nix packages can declare meta-attributes that contain information about a package such as a description, its homepage, its license, and so on. For instance, the GNU Hello package has a meta declaration like this: -meta = with stdenv.lib; { +meta = with lib; { description = "A program that produces a familiar, friendly greeting"; longDescription = '' GNU Hello is a program that prints "Hello, world!" when you run it. @@ -155,7 +155,7 @@ hello-2.3 A program that produces a familiar, friendly greeting - Single license referenced by attribute (preferred) stdenv.lib.licenses.gpl3Only. + Single license referenced by attribute (preferred) lib.licenses.gpl3Only. @@ -170,7 +170,7 @@ hello-2.3 A program that produces a familiar, friendly greeting - Multiple licenses referenced by attribute (preferred) with stdenv.lib.licenses; [ asl20 free ofl ]. + Multiple licenses referenced by attribute (preferred) with lib.licenses; [ asl20 free ofl ]. @@ -211,9 +211,9 @@ hello-2.3 A program that produces a familiar, friendly greeting The list of Nix platform types on which the package is supported. Hydra builds packages according to the platform specified. If no platform is specified, the package does not have prebuilt binaries. An example is: -meta.platforms = stdenv.lib.platforms.linux; +meta.platforms = lib.platforms.linux; - Attribute Set stdenv.lib.platforms defines various common lists of platforms types. + Attribute Set lib.platforms defines various common lists of platforms types. @@ -262,7 +262,7 @@ meta.platforms = stdenv.lib.platforms.linux; The list of Nix platform types for which the Hydra instance at hydra.nixos.org will build the package. (Hydra is the Nix-based continuous build system.) It defaults to the value of meta.platforms. Thus, the only reason to set meta.hydraPlatforms is if you want hydra.nixos.org to build the package on a subset of meta.platforms, or not at all, e.g. -meta.platforms = stdenv.lib.platforms.linux; +meta.platforms = lib.platforms.linux; meta.hydraPlatforms = []; @@ -294,7 +294,7 @@ meta.hydraPlatforms = []; Licenses - The meta.license attribute should preferrably contain a value from stdenv.lib.licenses defined in nixpkgs/lib/licenses.nix, or in-place license description of the same format if the license is unlikely to be useful in another expression. + The meta.license attribute should preferrably contain a value from lib.licenses defined in nixpkgs/lib/licenses.nix, or in-place license description of the same format if the license is unlikely to be useful in another expression. @@ -302,7 +302,7 @@ meta.hydraPlatforms = []; - stdenv.lib.licenses.free, "free" + lib.licenses.free, "free" @@ -312,7 +312,7 @@ meta.hydraPlatforms = []; - stdenv.lib.licenses.unfreeRedistributable, "unfree-redistributable" + lib.licenses.unfreeRedistributable, "unfree-redistributable" @@ -325,7 +325,7 @@ meta.hydraPlatforms = []; - stdenv.lib.licenses.unfree, "unfree" + lib.licenses.unfree, "unfree" @@ -335,7 +335,7 @@ meta.hydraPlatforms = []; - stdenv.lib.licenses.unfreeRedistributableFirmware, "unfree-redistributable-firmware" + lib.licenses.unfreeRedistributableFirmware, "unfree-redistributable-firmware" diff --git a/doc/stdenv/platform-notes.xml b/doc/stdenv/platform-notes.xml index 5a266fdc0ee..cc8efaece12 100644 --- a/doc/stdenv/platform-notes.xml +++ b/doc/stdenv/platform-notes.xml @@ -32,7 +32,7 @@ stdenv.mkDerivation { stdenv.mkDerivation { name = "libfoo-1.2.3"; # ... - makeFlags = stdenv.lib.optional stdenv.isDarwin "LDFLAGS=-Wl,-install_name,$(out)/lib/libfoo.dylib"; + makeFlags = lib.optional stdenv.isDarwin "LDFLAGS=-Wl,-install_name,$(out)/lib/libfoo.dylib"; } diff --git a/doc/using/configuration.xml b/doc/using/configuration.xml index 336bdf5b265..1e1df867e08 100644 --- a/doc/using/configuration.xml +++ b/doc/using/configuration.xml @@ -157,7 +157,7 @@ The following example configuration whitelists the licenses amd and wtfpl: { - whitelistedLicenses = with stdenv.lib.licenses; [ amd wtfpl ]; + whitelistedLicenses = with lib.licenses; [ amd wtfpl ]; } @@ -165,7 +165,7 @@ The following example configuration blacklists the gpl3Only and agpl3Only licenses: { - blacklistedLicenses = with stdenv.lib.licenses; [ agpl3Only gpl3Only ]; + blacklistedLicenses = with lib.licenses; [ agpl3Only gpl3Only ]; } -- cgit 1.4.1 From 72bebd8c0c4e8fdab99f04e51782ad6687f4881f Mon Sep 17 00:00:00 2001 From: Alexei Colin Date: Sun, 17 Jan 2021 01:29:15 -0500 Subject: doc: rust: fix syntax error in declarative overlay Otherwise pasting the snippet into shell.nix results in: error: syntax error, unexpected '=', expecting $end, at /.../shell.nix:2:9 Signed-off-by: Alexei Colin --- doc/languages-frameworks/rust.section.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'doc/languages-frameworks/rust.section.md') diff --git a/doc/languages-frameworks/rust.section.md b/doc/languages-frameworks/rust.section.md index 092e84461b8..dda8d485365 100644 --- a/doc/languages-frameworks/rust.section.md +++ b/doc/languages-frameworks/rust.section.md @@ -567,12 +567,13 @@ in the `~/.config/nixpkgs/overlays` directory. Add the following to your `configuration.nix`, `home-configuration.nix`, `shell.nix`, or similar: ``` - nixpkgs = { +{ pkgs ? import { overlays = [ (import (builtins.fetchTarball https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz)) # Further overlays go here ]; }; +}; ``` Note that this will fetch the latest overlay version when rebuilding your system. -- cgit 1.4.1 From 7c64854b231c4a37ebf85ceb4df5146d335fb5dd Mon Sep 17 00:00:00 2001 From: Jonathan Ringer Date: Mon, 18 Jan 2021 19:19:48 -0800 Subject: docs: pkgconfig -> pkg-config --- doc/languages-frameworks/emscripten.section.md | 6 +++--- doc/languages-frameworks/rust.section.md | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'doc/languages-frameworks/rust.section.md') diff --git a/doc/languages-frameworks/emscripten.section.md b/doc/languages-frameworks/emscripten.section.md index a5c15b43ac8..d391e038070 100644 --- a/doc/languages-frameworks/emscripten.section.md +++ b/doc/languages-frameworks/emscripten.section.md @@ -60,7 +60,7 @@ See the `zlib` example: stdenv = pkgs.emscriptenStdenv; }).overrideDerivation (old: rec { - buildInputs = old.buildInputs ++ [ pkgconfig ]; + buildInputs = old.buildInputs ++ [ pkg-config ]; # we need to reset this setting! NIX_CFLAGS_COMPILE=""; configurePhase = '' @@ -117,8 +117,8 @@ This `xmlmirror` example features a emscriptenPackage which is defined completel xmlmirror = pkgs.buildEmscriptenPackage rec { name = "xmlmirror"; - buildInputs = [ pkgconfig autoconf automake libtool gnumake libxml2 nodejs openjdk json_c ]; - nativeBuildInputs = [ pkgconfig zlib ]; + buildInputs = [ pkg-config autoconf automake libtool gnumake libxml2 nodejs openjdk json_c ]; + nativeBuildInputs = [ pkg-config zlib ]; src = pkgs.fetchgit { url = "https://gitlab.com/odfplugfest/xmlmirror.git"; diff --git a/doc/languages-frameworks/rust.section.md b/doc/languages-frameworks/rust.section.md index dda8d485365..550f2b576bd 100644 --- a/doc/languages-frameworks/rust.section.md +++ b/doc/languages-frameworks/rust.section.md @@ -480,7 +480,7 @@ stdenv.mkDerivation { rustc cargo # Example Build-time Additional Dependencies - pkgconfig + pkg-config ]; buildInputs = [ # Example Run-time Additional Dependencies @@ -522,7 +522,7 @@ stdenv.mkDerivation { latest.rustChannels.nightly.rust # Add some extra dependencies from `pkgs` - pkgconfig openssl + pkg-config openssl ]; # Set Environment Variables -- cgit 1.4.1 From 7616206b7747f12db15d32a7ab16b0ceaa3d7331 Mon Sep 17 00:00:00 2001 From: V Date: Thu, 21 Jan 2021 01:07:16 +0100 Subject: doc: add function argument order convention (#110060) * doc: add function argument order convention Ordering by usage is the de facto ordering given to arguments. It's logical, and makes finding argument usage easier. Putting lib first is common in NixOS modules, so it's reasonable to mirror this in nixpkgs proper. Additionally, it's not a package as such, has zero dependencies, and can be found used anywhere in a derivation. * doc: clean up usage of lib --- doc/contributing/coding-conventions.xml | 6 ++++++ doc/languages-frameworks/coq.section.md | 4 ++-- doc/languages-frameworks/idris.section.md | 10 +++++----- doc/languages-frameworks/maven.section.md | 8 ++++---- doc/languages-frameworks/ocaml.section.md | 6 +++--- doc/languages-frameworks/perl.section.md | 2 +- doc/languages-frameworks/qt.section.md | 2 +- doc/languages-frameworks/r.section.md | 8 +++----- doc/languages-frameworks/ruby.section.md | 2 +- doc/languages-frameworks/rust.section.md | 8 ++++---- 10 files changed, 30 insertions(+), 26 deletions(-) (limited to 'doc/languages-frameworks/rust.section.md') diff --git a/doc/contributing/coding-conventions.xml b/doc/contributing/coding-conventions.xml index cb6d60c2c13..9005a9ebafd 100644 --- a/doc/contributing/coding-conventions.xml +++ b/doc/contributing/coding-conventions.xml @@ -178,6 +178,12 @@ args.stdenv.mkDerivation (args // { + + + Arguments should be listed in the order they are used, with the + exception of lib, which always goes first. + + Prefer using the top-level lib over its alias diff --git a/doc/languages-frameworks/coq.section.md b/doc/languages-frameworks/coq.section.md index 5e16a4c546a..8f564c6e46b 100644 --- a/doc/languages-frameworks/coq.section.md +++ b/doc/languages-frameworks/coq.section.md @@ -42,8 +42,8 @@ It also takes other standard `mkDerivation` attributes, they are added as such, Here is a simple package example. It is a pure Coq library, thus it depends on Coq. It builds on the Mathematical Components library, thus it also takes some `mathcomp` derivations as `extraBuildInputs`. ```nix -{ coq, mkCoqDerivation, mathcomp, mathcomp-finmap, mathcomp-bigenough, - lib, version ? null }: +{ lib, mkCoqDerivation, version ? null +, coq, mathcomp, mathcomp-finmap, mathcomp-bigenough }: with lib; mkCoqDerivation { /* namePrefix leads to e.g. `name = coq8.11-mathcomp1.11-multinomials-1.5.2` */ namePrefix = [ "coq" "mathcomp" ]; diff --git a/doc/languages-frameworks/idris.section.md b/doc/languages-frameworks/idris.section.md index 2d06c4a19de..41e4f7ec312 100644 --- a/doc/languages-frameworks/idris.section.md +++ b/doc/languages-frameworks/idris.section.md @@ -69,11 +69,11 @@ prelude As an example of how a Nix expression for an Idris package can be created, here is the one for `idrisPackages.yaml`: ```nix -{ build-idris-package +{ lib +, build-idris-package , fetchFromGitHub , contrib , lightyear -, lib }: build-idris-package { name = "yaml"; @@ -94,11 +94,11 @@ build-idris-package { sha256 = "1g4pi0swmg214kndj85hj50ccmckni7piprsxfdzdfhg87s0avw7"; }; - meta = { + meta = with lib; { description = "Idris YAML lib"; homepage = "https://github.com/Heather/Idris.Yaml"; - license = lib.licenses.mit; - maintainers = [ lib.maintainers.brainrape ]; + license = licenses.mit; + maintainers = [ maintainers.brainrape ]; }; } ``` diff --git a/doc/languages-frameworks/maven.section.md b/doc/languages-frameworks/maven.section.md index 7a863c500bc..d66931e808d 100644 --- a/doc/languages-frameworks/maven.section.md +++ b/doc/languages-frameworks/maven.section.md @@ -116,7 +116,7 @@ The first step will be to build the Maven project as a fixed-output derivation i > Traditionally the Maven repository is at `~/.m2/repository`. We will override this to be the `$out` directory. ```nix -{ stdenv, lib, maven }: +{ lib, stdenv, maven }: stdenv.mkDerivation { name = "maven-repository"; buildInputs = [ maven ]; @@ -168,7 +168,7 @@ If your package uses _SNAPSHOT_ dependencies or _version ranges_; there is a str Regardless of which strategy is chosen above, the step to build the derivation is the same. ```nix -{ stdenv, lib, maven, callPackage }: +{ stdenv, maven, callPackage }: # pick a repository derivation, here we will use buildMaven let repository = callPackage ./build-maven-repository.nix { }; in stdenv.mkDerivation rec { @@ -222,7 +222,7 @@ We will read the Maven repository and flatten it to a single list. This list wil We make sure to provide this classpath to the `makeWrapper`. ```nix -{ stdenv, lib, maven, callPackage, makeWrapper, jre }: +{ stdenv, maven, callPackage, makeWrapper, jre }: let repository = callPackage ./build-maven-repository.nix { }; in stdenv.mkDerivation rec { @@ -298,7 +298,7 @@ Main-Class: Main We will modify the derivation above to add a symlink to our repository so that it's accessible to our JAR during the `installPhase`. ```nix -{ stdenv, lib, maven, callPackage, makeWrapper, jre }: +{ stdenv, maven, callPackage, makeWrapper, jre }: # pick a repository derivation, here we will use buildMaven let repository = callPackage ./build-maven-repository.nix { }; in stdenv.mkDerivation rec { diff --git a/doc/languages-frameworks/ocaml.section.md b/doc/languages-frameworks/ocaml.section.md index fa85a27e84f..9b92a80f471 100644 --- a/doc/languages-frameworks/ocaml.section.md +++ b/doc/languages-frameworks/ocaml.section.md @@ -32,11 +32,11 @@ buildDunePackage rec { propagatedBuildInputs = [ bigstringaf result ]; doCheck = true; - meta = { + meta = with lib; { homepage = "https://github.com/inhabitedtype/angstrom"; description = "OCaml parser combinators built for speed and memory efficiency"; - license = lib.licenses.bsd3; - maintainers = with lib.maintainers; [ sternenseemann ]; + license = licenses.bsd3; + maintainers = with maintainers; [ sternenseemann ]; }; } ``` diff --git a/doc/languages-frameworks/perl.section.md b/doc/languages-frameworks/perl.section.md index 309d8ebcc2b..dcb7dcb77b6 100644 --- a/doc/languages-frameworks/perl.section.md +++ b/doc/languages-frameworks/perl.section.md @@ -110,7 +110,7 @@ ClassC3Componentised = buildPerlPackage rec { On Darwin, if a script has too many `-Idir` flags in its first line (its “shebang line”), it will not run. This can be worked around by calling the `shortenPerlShebang` function from the `postInstall` phase: ```nix -{ stdenv, lib, buildPerlPackage, fetchurl, shortenPerlShebang }: +{ lib, stdenv, buildPerlPackage, fetchurl, shortenPerlShebang }: ImageExifTool = buildPerlPackage { pname = "Image-ExifTool"; diff --git a/doc/languages-frameworks/qt.section.md b/doc/languages-frameworks/qt.section.md index 6cfdc663550..5dd415852c1 100644 --- a/doc/languages-frameworks/qt.section.md +++ b/doc/languages-frameworks/qt.section.md @@ -8,7 +8,7 @@ There are primarily two problems which the Qt infrastructure is designed to addr ```{=docbook} -{ mkDerivation, lib, qtbase }: +{ mkDerivation, qtbase }: mkDerivation { pname = "myapp"; diff --git a/doc/languages-frameworks/r.section.md b/doc/languages-frameworks/r.section.md index 32a39ade279..c420d112c91 100644 --- a/doc/languages-frameworks/r.section.md +++ b/doc/languages-frameworks/r.section.md @@ -32,14 +32,12 @@ However, if you'd like to add a file to your project source to make the environment available for other contributors, you can create a `default.nix` file like so: ```nix -let - pkgs = import {}; - stdenv = pkgs.stdenv; -in with pkgs; { +with import {}; +{ myProject = stdenv.mkDerivation { name = "myProject"; version = "1"; - src = if pkgs.lib.inNixShell then null else nix; + src = if lib.inNixShell then null else nix; buildInputs = with rPackages; [ R diff --git a/doc/languages-frameworks/ruby.section.md b/doc/languages-frameworks/ruby.section.md index e292b3110ff..aeec154586c 100644 --- a/doc/languages-frameworks/ruby.section.md +++ b/doc/languages-frameworks/ruby.section.md @@ -232,7 +232,7 @@ If you want to package a specific version, you can use the standard Gemfile synt Now you can also also make a `default.nix` that looks like this: ```nix -{ lib, bundlerApp }: +{ bundlerApp }: bundlerApp { pname = "mdl"; diff --git a/doc/languages-frameworks/rust.section.md b/doc/languages-frameworks/rust.section.md index 550f2b576bd..8f6db28ab4d 100644 --- a/doc/languages-frameworks/rust.section.md +++ b/doc/languages-frameworks/rust.section.md @@ -19,6 +19,8 @@ or use Mozilla's [Rust nightlies overlay](#using-the-rust-nightlies-overlay). Rust applications are packaged by using the `buildRustPackage` helper from `rustPlatform`: ``` +{ lib, rustPlatform }: + rustPlatform.buildRustPackage rec { pname = "ripgrep"; version = "12.1.1"; @@ -226,8 +228,6 @@ 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. ``` -{ lib, rustPlatform, fetchFromGitHub }: - rustPlatform.buildRustPackage rec { (...) cargoPatches = [ @@ -263,7 +263,7 @@ Now, the file produced by the call to `carnix`, called `hello.nix`, looks like: ``` # Generated by carnix 0.6.5: carnix -o hello.nix --src ./. Cargo.lock --standalone -{ lib, stdenv, buildRustCrate, fetchgit }: +{ stdenv, buildRustCrate, fetchgit }: let kernel = stdenv.buildPlatform.parsed.kernel.name; # ... (content skipped) in @@ -292,7 +292,7 @@ following nix file: ``` # Generated by carnix 0.6.5: carnix -o hello.nix --src ./. Cargo.lock --standalone -{ lib, stdenv, buildRustCrate, fetchgit }: +{ stdenv, buildRustCrate, fetchgit }: let kernel = stdenv.buildPlatform.parsed.kernel.name; # ... (content skipped) in -- cgit 1.4.1 From 198dd776352220e1f3e50c0714874425adaeaa77 Mon Sep 17 00:00:00 2001 From: Daniël de Kok Date: Tue, 9 Feb 2021 13:46:32 +0100 Subject: doc: describe cargoSetupHook in the Rust section --- doc/languages-frameworks/rust.section.md | 98 ++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) (limited to 'doc/languages-frameworks/rust.section.md') diff --git a/doc/languages-frameworks/rust.section.md b/doc/languages-frameworks/rust.section.md index 8f6db28ab4d..e9850111376 100644 --- a/doc/languages-frameworks/rust.section.md +++ b/doc/languages-frameworks/rust.section.md @@ -237,6 +237,104 @@ rustPlatform.buildRustPackage rec { } ``` +## Compiling non-Rust packages that include Rust code + +Several non-Rust packages incorporate Rust code for performance- or +security-sensitive parts. `rustPlatform` exposes several functions and +hooks that can be used to integrate Cargo in non-Rust packages. + +### Vendoring of dependencies + +Since network access is not allowed in sandboxed builds, Rust crate +dependencies need to be retrieved using a fetcher. `rustPlatform` +provides the `fetchCargoTarball` fetcher, which vendors all +dependencies of a crate. This fetcher can be used jointly with +`cargoSetupHook` to vendor dependencies in derivations that do not use +`buildRustPackage`. + +In the following partial example, `fetchCargoTarball` and +`cargoSetupHook` are used to vendor dependencies in the Python +`tokenizers` derivation. The `tokenizers` Python package is in the +`source/bindings/python` directory of the project's source archive. We +use `fetchCargoTarball` to retrieve the dependencies specified in +`source/bidings/Cargo.{lock,toml}`. The resulting path is assigned to +the `cargoDeps` attribute, which is used by `cargoSetupHook` to +configure Cargo. + +```nix +{ fetchFromGitHub +, buildPythonPackage +, rustPlatform +, setuptools-rust +}: + +buildPythonPackage rec { + pname = "tokenizers"; + version = "0.10.0"; + + src = fetchFromGitHub { + owner = "huggingface"; + repo = pname; + rev = "python-v${version}"; + hash = "sha256-rQ2hRV52naEf6PvRsWVCTN7B1oXAQGmnpJw4iIdhamw="; + }; + + cargoDeps = rustPlatform.fetchCargoTarball { + inherit src sourceRoot; + name = "${pname}-${version}"; + hash = "sha256-BoHIN/519Top1NUBjpB/oEMqi86Omt3zTQcXFWqrek0="; + }; + + sourceRoot = "source/bindings/python"; + + nativeBuildInputs = [ setuptools-rust ] ++ (with rustPlatform; [ + cargoSetupHook + rust.cargo + rust.rustc + ]); + + # ... +} +``` + +In some projects, the Rust crate is not in the main source directory +of the projects. In such cases, the `cargoRoot` attribute can be used +to specify the crate's directory relative to `sourceRoot`. In the +following example, the crate is in `src/rust`, as specified in the +`cargoRoot` attribute. Note that we also need to specify the correct +path for `fetchCargoTarball`. + +```nix + +{ buildPythonPackage +, fetchPypi +, rustPlatform +, setuptools-rust +, openssl +}: + +buildPythonPackage rec { + pname = "cryptography"; + version = "3.4.2"; # Also update the hash in vectors.nix + + src = fetchPypi { + inherit pname version; + sha256 = "1i1mx5y9hkyfi9jrrkcw804hmkcglxi6rmf7vin7jfnbr2bf4q64"; + }; + + cargoDeps = rustPlatform.fetchCargoTarball { + inherit src; + sourceRoot = "${pname}-${version}/${cargoRoot}"; + name = "${pname}-${version}"; + hash = "sha256-PS562W4L1NimqDV2H0jl5vYhL08H9est/pbIxSdYVfo="; + }; + + cargoRoot = "src/rust"; + + # ... +} +``` + ## Compiling Rust crates using Nix instead of Cargo ### Simple operation -- cgit 1.4.1 From dbc8633daf5fd40bd673a74b6df9f140416a5454 Mon Sep 17 00:00:00 2001 From: Daniël de Kok Date: Fri, 12 Feb 2021 08:35:50 +0100 Subject: doc: describe cargoBuildHook and maturinBuildHook in the Rust section --- doc/languages-frameworks/rust.section.md | 118 +++++++++++++++++++++++++++---- 1 file changed, 103 insertions(+), 15 deletions(-) (limited to 'doc/languages-frameworks/rust.section.md') diff --git a/doc/languages-frameworks/rust.section.md b/doc/languages-frameworks/rust.section.md index e9850111376..c53818f8157 100644 --- a/doc/languages-frameworks/rust.section.md +++ b/doc/languages-frameworks/rust.section.md @@ -248,18 +248,65 @@ hooks that can be used to integrate Cargo in non-Rust packages. Since network access is not allowed in sandboxed builds, Rust crate dependencies need to be retrieved using a fetcher. `rustPlatform` provides the `fetchCargoTarball` fetcher, which vendors all -dependencies of a crate. This fetcher can be used jointly with -`cargoSetupHook` to vendor dependencies in derivations that do not use -`buildRustPackage`. - -In the following partial example, `fetchCargoTarball` and -`cargoSetupHook` are used to vendor dependencies in the Python -`tokenizers` derivation. The `tokenizers` Python package is in the -`source/bindings/python` directory of the project's source archive. We -use `fetchCargoTarball` to retrieve the dependencies specified in -`source/bidings/Cargo.{lock,toml}`. The resulting path is assigned to -the `cargoDeps` attribute, which is used by `cargoSetupHook` to -configure Cargo. +dependencies of a crate. For example, given a source path `src` +containing `Cargo.toml` and `Cargo.lock`, `fetchCargoTarball` +can be used as follows: + +```nix +cargoDeps = rustPlatform.fetchCargoTarball { + inherit src; + hash = "sha256-BoHIN/519Top1NUBjpB/oEMqi86Omt3zTQcXFWqrek0="; +}; +``` + +The `src` attribute is required, as well as a hash specified through +one of the `sha256` or `hash` attributes. The following optional +attributes can also be used: + +* `name`: the name that is used for the dependencies tarball. If + `name` is not specified, then the name `cargo-deps` will be used. +* `sourceRoot`: when the `Cargo.lock`/`Cargo.toml` are in a + subdirectory, `sourceRoot` specifies the relative path to these + files. +* `patches`: patches to apply before vendoring. This is useful when + the `Cargo.lock`/`Cargo.toml` files need to be patched before + vendoring. + +### Hooks + +`rustPlatform` provides the following hooks to automate Cargo builds: + +* `cargoSetupHook`: configure Cargo to use depenencies vendored + through `fetchCargoTarball`. This hook uses the `cargoDeps` + environment variable to find the vendored dependencies. If a project + already vendors its dependencies, the variable `cargoVendorDir` can + be used instead. When the `Cargo.toml`/`Cargo.lock` files are not in + `sourceRoot`, then the optional `cargoRoot` is used to specify the + Cargo root directory relative to `sourceRoot`. +* `cargoBuildHook`: use Cargo to build a crate. If the crate to be + built is a crate in e.g. a Cargo workspace, the relative path to the + crate to build can be set through the optional `buildAndTestSubdir` + environment variable. Additional Cargo build flags can be passed + through `cargoBuildFlags`. +* `maturinBuildHook`: use [Maturin](https://github.com/PyO3/maturin) + to build a Python wheel. Similar to `cargoBuildHook`, the optional + variable `buildAndTestSubdir` can be used to build a crate in a + Cargo workspace. Additional maturin flags can be passed through + `maturinBuildFlags`. + +### Examples + +#### Python package using `setuptools-rust` + +For Python packages using `setuptools-rust`, you can use +`fetchCargoTarball` and `cargoSetupHook` to retrieve and set up Cargo +dependencies. The build itself is then performed by +`buildPythonPackage`. + +The following example outlines how the `tokenizers` Python package is +built. Since the Python package is in the `source/bindings/python` +directory of the *tokenizers* project's source archive, we use +`sourceRoot` to point the tooling to this directory: ```nix { fetchFromGitHub @@ -297,9 +344,9 @@ buildPythonPackage rec { } ``` -In some projects, the Rust crate is not in the main source directory -of the projects. In such cases, the `cargoRoot` attribute can be used -to specify the crate's directory relative to `sourceRoot`. In the +In some projects, the Rust crate is not in the main Python source +directory. In such cases, the `cargoRoot` attribute can be used to +specify the crate's directory relative to `sourceRoot`. In the following example, the crate is in `src/rust`, as specified in the `cargoRoot` attribute. Note that we also need to specify the correct path for `fetchCargoTarball`. @@ -335,6 +382,47 @@ buildPythonPackage rec { } ``` +#### Python package using `maturin` + +Python packages that use [Maturin](https://github.com/PyO3/maturin) +can be built with `fetchCargoTarball`, `cargoSetupHook`, and +`maturinBuildHook`. For example, the following (partial) derivation +builds the `retworkx` Python package. `fetchCargoTarball` and +`cargoSetupHook` are used to fetch and set up the crate dependencies. +`maturinBuildHook` is used to perform the build. + +```nix +{ lib +, buildPythonPackage +, rustPlatform +, fetchFromGitHub +}: + +buildPythonPackage rec { + pname = "retworkx"; + version = "0.6.0"; + + src = fetchFromGitHub { + owner = "Qiskit"; + repo = "retworkx"; + rev = version; + sha256 = "11n30ldg3y3y6qxg3hbj837pnbwjkqw3nxq6frds647mmmprrd20"; + }; + + cargoDeps = rustPlatform.fetchCargoTarball { + inherit src; + name = "${pname}-${version}"; + hash = "sha256-heOBK8qi2nuc/Ib+I/vLzZ1fUUD/G/KTw9d7M4Hz5O0="; + }; + + format = "pyproject"; + + nativeBuildInputs = with rustPlatform; [ cargoSetupHook maturinBuildHook ]; + + # ... +} +``` + ## Compiling Rust crates using Nix instead of Cargo ### Simple operation -- cgit 1.4.1 From d92396039df6cf4c609cf1be47d0802496560e17 Mon Sep 17 00:00:00 2001 From: Daniël de Kok Date: Mon, 15 Feb 2021 07:06:31 +0100 Subject: buildRustPackage: add cargoDepsName attribute The directory in the tarball of vendored dependencies contains `name`, which is by default set to `${pname}-${version}`. This adds an additional attribute to permit setting the name to something of the user's choosing. Since `cargoSha256`/`cargoHash` depend on the name of the directory of vendored dependencies, `cargoDepsName` can be used to e.g. make the hash invariant to the package version by setting `cargoDepsName = pname`. --- doc/languages-frameworks/rust.section.md | 27 +++++++++++++++++++++++++++ pkgs/build-support/rust/default.nix | 6 +++++- 2 files changed, 32 insertions(+), 1 deletion(-) (limited to 'doc/languages-frameworks/rust.section.md') diff --git a/doc/languages-frameworks/rust.section.md b/doc/languages-frameworks/rust.section.md index 8f6db28ab4d..18d3cd9c926 100644 --- a/doc/languages-frameworks/rust.section.md +++ b/doc/languages-frameworks/rust.section.md @@ -80,6 +80,33 @@ The fetcher will verify that the `Cargo.lock` file is in sync with the `src` attribute, and fail the build if not. It will also will compress the vendor directory into a tar.gz archive. +The tarball with vendored dependencies contains a directory with the +package's `name`, which is normally composed of `pname` and +`version`. This means that the vendored dependencies hash +(`cargoSha256`/`cargoHash`) is dependent on the package name and +version. The `cargoDepsName` attribute can be used to use another name +for the directory of vendored dependencies. For example, the hash can +be made invariant to the version by setting `cargoDepsName` to +`pname`: + +```nix +rustPlatform.buildRustPackage rec { + pname = "broot"; + version = "1.2.0"; + + src = fetchCrate { + inherit pname version; + sha256 = "1mqaynrqaas82f5957lx31x80v74zwmwmjxxlbywajb61vh00d38"; + }; + + cargoHash = "sha256-JmBZcDVYJaK1cK05cxx5BrnGWp4t8ca6FLUbvIot67s="; + cargoDepsName = pname; + + # ... +} +``` + + ### Cross compilation By default, Rust packages are compiled for the host platform, just like any diff --git a/pkgs/build-support/rust/default.nix b/pkgs/build-support/rust/default.nix index dc86a7dc581..4213598b8a3 100644 --- a/pkgs/build-support/rust/default.nix +++ b/pkgs/build-support/rust/default.nix @@ -23,6 +23,9 @@ # Legacy hash , cargoSha256 ? "" + # Name for the vendored dependencies tarball +, cargoDepsName ? name + , src ? null , srcs ? null , unpackPhase ? null @@ -60,7 +63,8 @@ let cargoDeps = if cargoVendorDir == null then fetchCargoTarball ({ - inherit name src srcs sourceRoot unpackPhase cargoUpdateHook; + inherit src srcs sourceRoot unpackPhase cargoUpdateHook; + name = cargoDepsName; hash = cargoHash; patches = cargoPatches; sha256 = cargoSha256; -- cgit 1.4.1 From 9757c7101a0527c001fa9e9832764d5dc106ff25 Mon Sep 17 00:00:00 2001 From: Daniël de Kok Date: Mon, 15 Feb 2021 06:54:18 +0100 Subject: buildRustPackage: factor out install phase to cargoInstallHook --- doc/languages-frameworks/rust.section.md | 2 + pkgs/build-support/rust/default.nix | 40 ++---------------- pkgs/build-support/rust/hooks/cargo-build-hook.sh | 6 +-- .../build-support/rust/hooks/cargo-install-hook.sh | 49 ++++++++++++++++++++++ pkgs/build-support/rust/hooks/default.nix | 9 ++++ .../compilers/rust/make-rust-platform.nix | 4 +- 6 files changed, 69 insertions(+), 41 deletions(-) create mode 100644 pkgs/build-support/rust/hooks/cargo-install-hook.sh (limited to 'doc/languages-frameworks/rust.section.md') diff --git a/doc/languages-frameworks/rust.section.md b/doc/languages-frameworks/rust.section.md index c53818f8157..8451c126410 100644 --- a/doc/languages-frameworks/rust.section.md +++ b/doc/languages-frameworks/rust.section.md @@ -293,6 +293,8 @@ attributes can also be used: variable `buildAndTestSubdir` can be used to build a crate in a Cargo workspace. Additional maturin flags can be passed through `maturinBuildFlags`. +* `cargoInstallHook`: install binaries and static/shared libraries + that were built using `cargoBuildHook`. ### Examples diff --git a/pkgs/build-support/rust/default.nix b/pkgs/build-support/rust/default.nix index 19ec71261be..b7d6cb522bc 100644 --- a/pkgs/build-support/rust/default.nix +++ b/pkgs/build-support/rust/default.nix @@ -4,6 +4,7 @@ , cacert , cargo , cargoBuildHook +, cargoInstallHook , cargoSetupHook , fetchCargoTarball , runCommandNoCC @@ -87,9 +88,6 @@ let originalCargoToml = src + /Cargo.toml; # profile info is later extracted }; - releaseDir = "target/${shortTarget}/${buildType}"; - tmpDir = "${releaseDir}-tmp"; - in # Tests don't currently work for `no_std`, and all custom sysroots are currently built without `std`. @@ -99,16 +97,16 @@ assert useSysroot -> !(args.doCheck or true); stdenv.mkDerivation ((removeAttrs args ["depsExtraArgs"]) // lib.optionalAttrs useSysroot { RUSTFLAGS = "--sysroot ${sysroot} " + (args.RUSTFLAGS or ""); } // { - inherit buildAndTestSubdir cargoDeps releaseDir tmpDir; + inherit buildAndTestSubdir cargoDeps; cargoBuildFlags = lib.concatStringsSep " " cargoBuildFlags; - cargoBuildType = "--${buildType}"; + cargoBuildType = buildType; patchRegistryDeps = ./patch-registry-deps; nativeBuildInputs = nativeBuildInputs ++ - [ cacert git cargo cargoBuildHook cargoSetupHook rustc ]; + [ cacert git cargo cargoBuildHook cargoInstallHook cargoSetupHook rustc ]; buildInputs = buildInputs ++ lib.optional stdenv.hostPlatform.isMinGW windows.pthreads; @@ -144,36 +142,6 @@ stdenv.mkDerivation ((removeAttrs args ["depsExtraArgs"]) // lib.optionalAttrs u strictDeps = true; - installPhase = args.installPhase or '' - runHook preInstall - - # This needs to be done after postBuild: packages like `cargo` do a pushd/popd in - # the pre/postBuild-hooks that need to be taken into account before gathering - # all binaries to install. - mkdir -p $tmpDir - cp -r $releaseDir/* $tmpDir/ - bins=$(find $tmpDir \ - -maxdepth 1 \ - -type f \ - -executable ! \( -regex ".*\.\(so.[0-9.]+\|so\|a\|dylib\)" \)) - - # rename the output dir to a architecture independent one - mapfile -t targets < <(find "$NIX_BUILD_TOP" -type d | grep '${tmpDir}$') - for target in "''${targets[@]}"; do - rm -rf "$target/../../${buildType}" - ln -srf "$target" "$target/../../" - done - mkdir -p $out/bin $out/lib - - xargs -r cp -t $out/bin <<< $bins - find $tmpDir \ - -maxdepth 1 \ - -regex ".*\.\(so.[0-9.]+\|so\|a\|dylib\)" \ - -print0 | xargs -r -0 cp -t $out/lib - rmdir --ignore-fail-on-non-empty $out/lib $out/bin - runHook postInstall - ''; - passthru = { inherit cargoDeps; } // (args.passthru or {}); meta = { diff --git a/pkgs/build-support/rust/hooks/cargo-build-hook.sh b/pkgs/build-support/rust/hooks/cargo-build-hook.sh index 55585233413..85a3827dc10 100644 --- a/pkgs/build-support/rust/hooks/cargo-build-hook.sh +++ b/pkgs/build-support/rust/hooks/cargo-build-hook.sh @@ -17,16 +17,16 @@ cargoBuildHook() { cargo build -j $NIX_BUILD_CORES \ --target @rustTargetPlatformSpec@ \ --frozen \ - ${cargoBuildType} \ + --${cargoBuildType} \ ${cargoBuildFlags} ) - runHook postBuild - if [ ! -z "${buildAndTestSubdir-}" ]; then popd fi + runHook postBuild + echo "Finished cargoBuildHook" } diff --git a/pkgs/build-support/rust/hooks/cargo-install-hook.sh b/pkgs/build-support/rust/hooks/cargo-install-hook.sh new file mode 100644 index 00000000000..e6ffa300706 --- /dev/null +++ b/pkgs/build-support/rust/hooks/cargo-install-hook.sh @@ -0,0 +1,49 @@ +cargoInstallPostBuildHook() { + echo "Executing cargoInstallPostBuildHook" + + releaseDir=target/@shortTarget@/$cargoBuildType + tmpDir="${releaseDir}-tmp"; + + mkdir -p $tmpDir + cp -r ${releaseDir}/* $tmpDir/ + bins=$(find $tmpDir \ + -maxdepth 1 \ + -type f \ + -executable ! \( -regex ".*\.\(so.[0-9.]+\|so\|a\|dylib\)" \)) + + echo "Finished cargoInstallPostBuildHook" +} + +cargoInstallHook() { + echo "Executing cargoInstallHook" + + runHook preInstall + + # rename the output dir to a architecture independent one + + releaseDir=target/@shortTarget@/$cargoBuildType + tmpDir="${releaseDir}-tmp"; + + mapfile -t targets < <(find "$NIX_BUILD_TOP" -type d | grep "${tmpDir}$") + for target in "${targets[@]}"; do + rm -rf "$target/../../${cargoBuildType}" + ln -srf "$target" "$target/../../" + done + mkdir -p $out/bin $out/lib + + xargs -r cp -t $out/bin <<< $bins + find $tmpDir \ + -maxdepth 1 \ + -regex ".*\.\(so.[0-9.]+\|so\|a\|dylib\)" \ + -print0 | xargs -r -0 cp -t $out/lib + rmdir --ignore-fail-on-non-empty $out/lib $out/bin + runHook postInstall + + echo "Finished cargoInstallHook" +} + + +if [ -z "${installPhase-}" ]; then + installPhase=cargoInstallHook + postBuildHooks+=(cargoInstallPostBuildHook) +fi diff --git a/pkgs/build-support/rust/hooks/default.nix b/pkgs/build-support/rust/hooks/default.nix index d4b2cc15605..b43f83acda0 100644 --- a/pkgs/build-support/rust/hooks/default.nix +++ b/pkgs/build-support/rust/hooks/default.nix @@ -36,6 +36,15 @@ in { }; } ./cargo-build-hook.sh) {}; + cargoInstallHook = callPackage ({ }: + makeSetupHook { + name = "cargo-install-hook.sh"; + deps = [ ]; + substitutions = { + inherit shortTarget; + }; + } ./cargo-install-hook.sh) {}; + cargoSetupHook = callPackage ({ }: makeSetupHook { name = "cargo-setup-hook.sh"; diff --git a/pkgs/development/compilers/rust/make-rust-platform.nix b/pkgs/development/compilers/rust/make-rust-platform.nix index 1ea97b48c44..e963c463135 100644 --- a/pkgs/development/compilers/rust/make-rust-platform.nix +++ b/pkgs/development/compilers/rust/make-rust-platform.nix @@ -12,7 +12,7 @@ rec { }; buildRustPackage = callPackage ../../../build-support/rust { - inherit rustc cargo cargoBuildHook cargoSetupHook fetchCargoTarball; + inherit rustc cargo cargoBuildHook cargoInstallHook cargoSetupHook fetchCargoTarball; }; rustcSrc = callPackage ./rust-src.nix { @@ -26,5 +26,5 @@ rec { # Hooks inherit (callPackage ../../../build-support/rust/hooks { inherit cargo; - }) cargoBuildHook cargoSetupHook maturinBuildHook; + }) cargoBuildHook cargoInstallHook cargoSetupHook maturinBuildHook; } -- cgit 1.4.1 From 05e40e79a8559cdbe323ab05e003d56033000ee8 Mon Sep 17 00:00:00 2001 From: Daniël de Kok Date: Mon, 15 Feb 2021 10:26:40 +0100 Subject: buildRustPackage: factor out check phase to cargoCheckHook API change: `cargoParallelTestThreads` suggests that this attribute sets the number of threads used during tests, while it is actually a boolean option (use 1 thread or NIX_BUILD_CORES threads). In the hook, this is replaced by a more canonical name `dontUseCargoParallelTests`. --- doc/languages-frameworks/rust.section.md | 6 +++- .../networking/browsers/castor/default.nix | 2 +- pkgs/build-support/rust/default.nix | 26 ++++++--------- pkgs/build-support/rust/hooks/cargo-check-hook.sh | 37 ++++++++++++++++++++++ pkgs/build-support/rust/hooks/default.nix | 9 ++++++ .../compilers/rust/make-rust-platform.nix | 5 +-- pkgs/development/tools/the-way/default.nix | 2 +- 7 files changed, 66 insertions(+), 21 deletions(-) create mode 100644 pkgs/build-support/rust/hooks/cargo-check-hook.sh (limited to 'doc/languages-frameworks/rust.section.md') diff --git a/doc/languages-frameworks/rust.section.md b/doc/languages-frameworks/rust.section.md index 8451c126410..2290d92f7ad 100644 --- a/doc/languages-frameworks/rust.section.md +++ b/doc/languages-frameworks/rust.section.md @@ -196,7 +196,7 @@ sometimes it may be necessary to disable this so the tests run consecutively. ```nix rustPlatform.buildRustPackage { /* ... */ - cargoParallelTestThreads = false; + dontUseCargoParallelTests = true; } ``` @@ -293,6 +293,10 @@ attributes can also be used: variable `buildAndTestSubdir` can be used to build a crate in a Cargo workspace. Additional maturin flags can be passed through `maturinBuildFlags`. +* `cargoCheckHook`: run tests using Cargo. Additional flags can be + passed to Cargo using `checkFlags` and `checkFlagsArray`. By + default, tests are run in parallel. This can be disabled by setting + `dontUseCargoParallelTests`. * `cargoInstallHook`: install binaries and static/shared libraries that were built using `cargoBuildHook`. diff --git a/pkgs/applications/networking/browsers/castor/default.nix b/pkgs/applications/networking/browsers/castor/default.nix index be3d8295f99..daead82e485 100644 --- a/pkgs/applications/networking/browsers/castor/default.nix +++ b/pkgs/applications/networking/browsers/castor/default.nix @@ -39,7 +39,7 @@ rustPlatform.buildRustPackage rec { postInstall = "make PREFIX=$out copy-data"; # Sometimes tests fail when run in parallel - cargoParallelTestThreads = false; + dontUseCargoParallelThreads = true; meta = with lib; { description = "A graphical client for plain-text protocols written in Rust with GTK. It currently supports the Gemini, Gopher and Finger protocols"; diff --git a/pkgs/build-support/rust/default.nix b/pkgs/build-support/rust/default.nix index b7d6cb522bc..760f7c920da 100644 --- a/pkgs/build-support/rust/default.nix +++ b/pkgs/build-support/rust/default.nix @@ -2,8 +2,8 @@ , lib , buildPackages , cacert -, cargo , cargoBuildHook +, cargoCheckHook , cargoInstallHook , cargoSetupHook , fetchCargoTarball @@ -42,7 +42,6 @@ , cargoVendorDir ? null , checkType ? buildType , depsExtraArgs ? {} -, cargoParallelTestThreads ? true # Toggles whether a custom sysroot is created when the target is a .json file. , __internal_dontAddSysroot ? false @@ -105,8 +104,15 @@ stdenv.mkDerivation ((removeAttrs args ["depsExtraArgs"]) // lib.optionalAttrs u patchRegistryDeps = ./patch-registry-deps; - nativeBuildInputs = nativeBuildInputs ++ - [ cacert git cargo cargoBuildHook cargoInstallHook cargoSetupHook rustc ]; + nativeBuildInputs = nativeBuildInputs ++ [ + cacert + git + cargoBuildHook + cargoCheckHook + cargoInstallHook + cargoSetupHook + rustc + ]; buildInputs = buildInputs ++ lib.optional stdenv.hostPlatform.isMinGW windows.pthreads; @@ -126,18 +132,6 @@ stdenv.mkDerivation ((removeAttrs args ["depsExtraArgs"]) // lib.optionalAttrs u runHook postConfigure ''; - checkPhase = args.checkPhase or (let - argstr = "${lib.optionalString (checkType == "release") "--release"} --target ${target} --frozen"; - threads = if cargoParallelTestThreads then "$NIX_BUILD_CORES" else "1"; - in '' - ${lib.optionalString (buildAndTestSubdir != null) "pushd ${buildAndTestSubdir}"} - runHook preCheck - echo "Running cargo test ${argstr} -- ''${checkFlags} ''${checkFlagsArray+''${checkFlagsArray[@]}}" - cargo test -j $NIX_BUILD_CORES ${argstr} -- --test-threads=${threads} ''${checkFlags} ''${checkFlagsArray+"''${checkFlagsArray[@]}"} - runHook postCheck - ${lib.optionalString (buildAndTestSubdir != null) "popd"} - ''); - doCheck = args.doCheck or true; strictDeps = true; diff --git a/pkgs/build-support/rust/hooks/cargo-check-hook.sh b/pkgs/build-support/rust/hooks/cargo-check-hook.sh new file mode 100644 index 00000000000..a1df2babffb --- /dev/null +++ b/pkgs/build-support/rust/hooks/cargo-check-hook.sh @@ -0,0 +1,37 @@ +cargoCheckHook() { + echo "Executing cargoCheckHook" + + runHook preCheck + + if [[ -n "${buildAndTestSubdir-}" ]]; then + pushd "${buildAndTestSubdir}" + fi + + if [[ -z ${dontUseCargoParallelTests-} ]]; then + threads=$NIX_BUILD_CORES + else + threads=1 + fi + + argstr="--${cargoBuildType} --target @rustTargetPlatformSpec@ --frozen"; + + ( + set -x + cargo test \ + -j $NIX_BUILD_CORES \ + ${argstr} -- \ + --test-threads=${threads} \ + ${checkFlags} \ + ${checkFlagsArray+"${checkFlagsArray[@]}"} + ) + + if [[ -n "${buildAndTestSubdir-}" ]]; then + popd + fi + + echo "Finished cargoCheckHook" + + runHook postCheck +} + +checkPhase=cargoCheckHook diff --git a/pkgs/build-support/rust/hooks/default.nix b/pkgs/build-support/rust/hooks/default.nix index b43f83acda0..e8927e2b542 100644 --- a/pkgs/build-support/rust/hooks/default.nix +++ b/pkgs/build-support/rust/hooks/default.nix @@ -36,6 +36,15 @@ in { }; } ./cargo-build-hook.sh) {}; + cargoCheckHook = callPackage ({ }: + makeSetupHook { + name = "cargo-check-hook.sh"; + deps = [ cargo ]; + substitutions = { + inherit rustTargetPlatformSpec; + }; + } ./cargo-check-hook.sh) {}; + cargoInstallHook = callPackage ({ }: makeSetupHook { name = "cargo-install-hook.sh"; diff --git a/pkgs/development/compilers/rust/make-rust-platform.nix b/pkgs/development/compilers/rust/make-rust-platform.nix index e963c463135..584b1fdbe43 100644 --- a/pkgs/development/compilers/rust/make-rust-platform.nix +++ b/pkgs/development/compilers/rust/make-rust-platform.nix @@ -12,7 +12,8 @@ rec { }; buildRustPackage = callPackage ../../../build-support/rust { - inherit rustc cargo cargoBuildHook cargoInstallHook cargoSetupHook fetchCargoTarball; + inherit cargoBuildHook cargoCheckHook cargoInstallHook cargoSetupHook + fetchCargoTarball rustc; }; rustcSrc = callPackage ./rust-src.nix { @@ -26,5 +27,5 @@ rec { # Hooks inherit (callPackage ../../../build-support/rust/hooks { inherit cargo; - }) cargoBuildHook cargoInstallHook cargoSetupHook maturinBuildHook; + }) cargoBuildHook cargoCheckHook cargoInstallHook cargoSetupHook maturinBuildHook; } diff --git a/pkgs/development/tools/the-way/default.nix b/pkgs/development/tools/the-way/default.nix index e8f52fa8334..6d7fbef2f19 100644 --- a/pkgs/development/tools/the-way/default.nix +++ b/pkgs/development/tools/the-way/default.nix @@ -17,7 +17,7 @@ rustPlatform.buildRustPackage rec { cargoSha256 = "sha256-jTZso61Lyt6jprBxBAhvchgOsgM9y1qBleTxUx1jCnE="; checkFlagsArray = lib.optionals stdenv.isDarwin [ "--skip=copy" ]; - cargoParallelTestThreads = false; + dontUseCargoParallelTests = true; postInstall = '' $out/bin/the-way config default tmp.toml -- cgit 1.4.1 From c50a347cb5604fe92173204872d2ebdb694075b1 Mon Sep 17 00:00:00 2001 From: Daniël de Kok Date: Fri, 26 Feb 2021 11:51:31 +0100 Subject: buildRustPackage: use checkType argument The `checkType` argument of buildRustPackage was not used anymore since the refactoring of `buildRustPackage` into hooks. This was an oversight that is fixed by this change. The check type can also be passed directly to cargoCheckHook using the `cargoCheckType` environment variable. --- doc/languages-frameworks/rust.section.md | 7 ++++--- pkgs/build-support/rust/default.nix | 2 ++ pkgs/build-support/rust/hooks/cargo-check-hook.sh | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) (limited to 'doc/languages-frameworks/rust.section.md') diff --git a/doc/languages-frameworks/rust.section.md b/doc/languages-frameworks/rust.section.md index 94f94aaffe3..1a749d2c847 100644 --- a/doc/languages-frameworks/rust.section.md +++ b/doc/languages-frameworks/rust.section.md @@ -320,9 +320,10 @@ attributes can also be used: variable `buildAndTestSubdir` can be used to build a crate in a Cargo workspace. Additional maturin flags can be passed through `maturinBuildFlags`. -* `cargoCheckHook`: run tests using Cargo. Additional flags can be - passed to Cargo using `checkFlags` and `checkFlagsArray`. By - default, tests are run in parallel. This can be disabled by setting +* `cargoCheckHook`: run tests using Cargo. The build type for checks + can be set using `cargoCheckType`. Additional flags can be passed to + the tests using `checkFlags` and `checkFlagsArray`. By default, + tests are run in parallel. This can be disabled by setting `dontUseCargoParallelTests`. * `cargoInstallHook`: install binaries and static/shared libraries that were built using `cargoBuildHook`. diff --git a/pkgs/build-support/rust/default.nix b/pkgs/build-support/rust/default.nix index bfa6c0d17cd..ff9ca642daa 100644 --- a/pkgs/build-support/rust/default.nix +++ b/pkgs/build-support/rust/default.nix @@ -103,6 +103,8 @@ stdenv.mkDerivation ((removeAttrs args ["depsExtraArgs"]) // lib.optionalAttrs u cargoBuildType = buildType; + cargoCheckType = checkType; + patchRegistryDeps = ./patch-registry-deps; nativeBuildInputs = nativeBuildInputs ++ [ diff --git a/pkgs/build-support/rust/hooks/cargo-check-hook.sh b/pkgs/build-support/rust/hooks/cargo-check-hook.sh index 8c5b1a13219..82e669af3a0 100644 --- a/pkgs/build-support/rust/hooks/cargo-check-hook.sh +++ b/pkgs/build-support/rust/hooks/cargo-check-hook.sh @@ -15,7 +15,7 @@ cargoCheckHook() { threads=1 fi - argstr="--${cargoBuildType} --target @rustTargetPlatformSpec@ --frozen"; + argstr="--${cargoCheckType} --target @rustTargetPlatformSpec@ --frozen"; ( set -x -- cgit 1.4.1 From fa62f3716077be3239765b041702ed401bc257e3 Mon Sep 17 00:00:00 2001 From: Max Hausch Date: Wed, 24 Feb 2021 09:25:49 +0100 Subject: doc: rust: Fix code blocks in markdown And add a word --- doc/languages-frameworks/rust.section.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'doc/languages-frameworks/rust.section.md') diff --git a/doc/languages-frameworks/rust.section.md b/doc/languages-frameworks/rust.section.md index 1a749d2c847..48510b37add 100644 --- a/doc/languages-frameworks/rust.section.md +++ b/doc/languages-frameworks/rust.section.md @@ -72,8 +72,8 @@ For `cargoHash` you can use: Per the instructions in the [Cargo Book](https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html) best practices guide, Rust applications should always commit the `Cargo.lock` file in git to ensure a reproducible build. However, a few packages do not, and -Nix depends on this file, so if it missing you can use `cargoPatches` to apply -it in the `patchPhase`. Consider sending a PR upstream with a note to the +Nix depends on this file, so if it is missing you can use `cargoPatches` to +apply it in the `patchPhase`. Consider sending a PR upstream with a note to the maintainer describing why it's important to include in the application. The fetcher will verify that the `Cargo.lock` file is in sync with the `src` @@ -146,6 +146,8 @@ where they are known to differ. But there are ways to customize the argument: rustc.platform = { foo = ""; bar = ""; }; }; } + ``` + will result in: ```shell --target /nix/store/asdfasdfsadf-thumb-crazy.json # contains {"foo":"","bar":""} @@ -156,7 +158,7 @@ path) can be passed directly to `buildRustPackage`: ```nix pkgs.rustPlatform.buildRustPackage { - (...) + /* ... */ target = "x86_64-fortanix-unknown-sgx"; } ``` -- cgit 1.4.1 From ebe3ae4d4d4668f3f47a30f10592714df1c9b803 Mon Sep 17 00:00:00 2001 From: Max Hausch Date: Wed, 24 Feb 2021 09:32:22 +0100 Subject: buildRustPackage: Add cargoTestFlags This makes it possible to pass flags to `cargo test`, which is needed if a crate is compiled with custom feature flags. --- doc/languages-frameworks/rust.section.md | 7 +++++++ pkgs/build-support/rust/hooks/cargo-check-hook.sh | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'doc/languages-frameworks/rust.section.md') diff --git a/doc/languages-frameworks/rust.section.md b/doc/languages-frameworks/rust.section.md index 48510b37add..a3f0238bf3a 100644 --- a/doc/languages-frameworks/rust.section.md +++ b/doc/languages-frameworks/rust.section.md @@ -193,6 +193,13 @@ rustPlatform.buildRustPackage { Please note that the code will be compiled twice here: once in `release` mode for the `buildPhase`, and again in `debug` mode for the `checkPhase`. +Test flags, e.g., `--features xxx/yyy`, can be passed to `cargo test` via the +`cargoTestFlags` attribute. + +Another attribute, called `checkFlags`, is used to pass arguments to the test +binary itself, as stated +(here)[https://doc.rust-lang.org/cargo/commands/cargo-test.html]. + #### Tests relying on the structure of the `target/` directory Some tests may rely on the structure of the `target/` directory. Those tests diff --git a/pkgs/build-support/rust/hooks/cargo-check-hook.sh b/pkgs/build-support/rust/hooks/cargo-check-hook.sh index 82e669af3a0..bc913c6ab07 100644 --- a/pkgs/build-support/rust/hooks/cargo-check-hook.sh +++ b/pkgs/build-support/rust/hooks/cargo-check-hook.sh @@ -1,4 +1,5 @@ declare -a checkFlags +declare -a cargoTestFlags cargoCheckHook() { echo "Executing cargoCheckHook" @@ -15,7 +16,7 @@ cargoCheckHook() { threads=1 fi - argstr="--${cargoCheckType} --target @rustTargetPlatformSpec@ --frozen"; + argstr="--${cargoCheckType} --target @rustTargetPlatformSpec@ --frozen ${cargoTestFlags}"; ( set -x -- cgit 1.4.1 From 3329093c6aca716761a3d91089d49e5cbb873d77 Mon Sep 17 00:00:00 2001 From: Florian Engel Date: Sun, 14 Mar 2021 11:49:35 +0100 Subject: Remove repeating words from doc --- doc/builders/fetchers.chapter.md | 2 +- doc/builders/images/snaptools.xml | 2 +- doc/languages-frameworks/android.section.md | 2 +- doc/languages-frameworks/dotnet.section.md | 2 +- doc/languages-frameworks/lua.section.md | 4 ++-- doc/languages-frameworks/python.section.md | 4 ++-- doc/languages-frameworks/ruby.section.md | 2 +- doc/languages-frameworks/rust.section.md | 2 +- doc/using/overlays.xml | 2 +- 9 files changed, 11 insertions(+), 11 deletions(-) (limited to 'doc/languages-frameworks/rust.section.md') diff --git a/doc/builders/fetchers.chapter.md b/doc/builders/fetchers.chapter.md index 317c9430cd0..c70e3020bbf 100644 --- a/doc/builders/fetchers.chapter.md +++ b/doc/builders/fetchers.chapter.md @@ -18,7 +18,7 @@ stdenv.mkDerivation { The main difference between `fetchurl` and `fetchzip` is in how they store the contents. `fetchurl` will store the unaltered contents of the URL within the Nix store. `fetchzip` on the other hand will decompress the archive for you, making files and directories directly accessible in the future. `fetchzip` can only be used with archives. Despite the name, `fetchzip` is not limited to .zip files and can also be used with any tarball. -`fetchpatch` works very similarly to `fetchurl` with the same arguments expected. It expects patch files as a source and and performs normalization on them before computing the checksum. For example it will remove comments or other unstable parts that are sometimes added by version control systems and can change over time. +`fetchpatch` works very similarly to `fetchurl` with the same arguments expected. It expects patch files as a source and performs normalization on them before computing the checksum. For example it will remove comments or other unstable parts that are sometimes added by version control systems and can change over time. Other fetcher functions allow you to add source code directly from a VCS such as subversion or git. These are mostly straightforward nambes based on the name of the command used with the VCS system. Because they give you a working repository, they act most like `fetchzip`. diff --git a/doc/builders/images/snaptools.xml b/doc/builders/images/snaptools.xml index 422fcfa37d8..bbe2e3f5e14 100644 --- a/doc/builders/images/snaptools.xml +++ b/doc/builders/images/snaptools.xml @@ -16,7 +16,7 @@ - The base should not be be specified, as makeSnap will force set it. + The base should not be specified, as makeSnap will force set it. diff --git a/doc/languages-frameworks/android.section.md b/doc/languages-frameworks/android.section.md index 62e544cd48b..416073df078 100644 --- a/doc/languages-frameworks/android.section.md +++ b/doc/languages-frameworks/android.section.md @@ -80,7 +80,7 @@ Most of the function arguments have reasonable default settings. You can specify license names: -* `extraLicenses` is a list of of license names. +* `extraLicenses` is a list of license names. You can get these names from repo.json or `querypackages.sh licenses`. The SDK license (`android-sdk-license`) is accepted for you if you set accept_license to true. If you are doing something like working with preview SDKs, you will diff --git a/doc/languages-frameworks/dotnet.section.md b/doc/languages-frameworks/dotnet.section.md index 88fd74db825..c3947042494 100644 --- a/doc/languages-frameworks/dotnet.section.md +++ b/doc/languages-frameworks/dotnet.section.md @@ -64,7 +64,7 @@ $ dotnet --info The `dotnetCorePackages.sdk_X_Y` is preferred over the old dotnet-sdk as both major and minor version are very important for a dotnet environment. If a given minor version isn't present (or was changed), then this will likely break your ability to build a project. -## dotnetCorePackages.sdk vs vs dotnetCorePackages.net vs dotnetCorePackages.netcore vs dotnetCorePackages.aspnetcore +## dotnetCorePackages.sdk vs dotnetCorePackages.net vs dotnetCorePackages.netcore vs dotnetCorePackages.aspnetcore The `dotnetCorePackages.sdk` contains both a runtime and the full sdk of a given version. The `net`, `netcore` and `aspnetcore` packages are meant to serve as minimal runtimes to deploy alongside already built applications. For runtime versions >= .NET 5 `net` is used while `netcore` is used for older .NET Core runtime version. diff --git a/doc/languages-frameworks/lua.section.md b/doc/languages-frameworks/lua.section.md index d81949c75f6..5935cbd7bd5 100644 --- a/doc/languages-frameworks/lua.section.md +++ b/doc/languages-frameworks/lua.section.md @@ -50,7 +50,7 @@ and install it in your profile with ```shell nix-env -iA nixpkgs.myLuaEnv ``` -The environment is is installed by referring to the attribute, and considering +The environment is installed by referring to the attribute, and considering the `nixpkgs` channel was used. #### Lua environment defined in `/etc/nixos/configuration.nix` @@ -129,7 +129,7 @@ the whitelist maintainers/scripts/luarocks-packages.csv and updated by running m [luarocks2nix](https://github.com/nix-community/luarocks) is a tool capable of generating nix derivations from both rockspec and src.rock (and favors the src.rock). The automation only goes so far though and some packages need to be customized. These customizations go in `pkgs/development/lua-modules/overrides.nix`. -For instance if the rockspec defines `external_dependencies`, these need to be manually added in in its rockspec file then it won't work. +For instance if the rockspec defines `external_dependencies`, these need to be manually added in its rockspec file then it won't work. You can try converting luarocks packages to nix packages with the command `nix-shell -p luarocks-nix` and then `luarocks nix PKG_NAME`. Nix rely on luarocks to install lua packages, basically it runs: diff --git a/doc/languages-frameworks/python.section.md b/doc/languages-frameworks/python.section.md index e569cdaa935..26458c3906e 100644 --- a/doc/languages-frameworks/python.section.md +++ b/doc/languages-frameworks/python.section.md @@ -334,7 +334,7 @@ Above, we were mostly just focused on use cases and what to do to get started creating working Python environments in nix. Now that you know the basics to be up and running, it is time to take a step -back and take a deeper look at at how Python packages are packaged on Nix. Then, +back and take a deeper look at how Python packages are packaged on Nix. Then, we will look at how you can use development mode with your code. #### Python library packages in Nixpkgs @@ -918,7 +918,7 @@ because their behaviour is different: * `nativeBuildInputs ? []`: Build-time only dependencies. Typically executables as well as the items listed in `setup_requires`. -* `buildInputs ? []`: Build and/or run-time dependencies that need to be be +* `buildInputs ? []`: Build and/or run-time dependencies that need to be compiled for the host machine. Typically non-Python libraries which are being linked. * `checkInputs ? []`: Dependencies needed for running the `checkPhase`. These diff --git a/doc/languages-frameworks/ruby.section.md b/doc/languages-frameworks/ruby.section.md index aeec154586c..c519d79d3da 100644 --- a/doc/languages-frameworks/ruby.section.md +++ b/doc/languages-frameworks/ruby.section.md @@ -229,7 +229,7 @@ end If you want to package a specific version, you can use the standard Gemfile syntax for that, e.g. `gem 'mdl', '0.5.0'`, but if you want the latest stable version anyway, it's easier to update by simply running the `bundle lock` and `bundix` steps again. -Now you can also also make a `default.nix` that looks like this: +Now you can also make a `default.nix` that looks like this: ```nix { bundlerApp }: diff --git a/doc/languages-frameworks/rust.section.md b/doc/languages-frameworks/rust.section.md index 94f94aaffe3..020201d0866 100644 --- a/doc/languages-frameworks/rust.section.md +++ b/doc/languages-frameworks/rust.section.md @@ -737,7 +737,7 @@ with import "${src.out}/rust-overlay.nix" pkgs pkgs; stdenv.mkDerivation { name = "rust-env"; buildInputs = [ - # Note: to use use stable, just replace `nightly` with `stable` + # Note: to use stable, just replace `nightly` with `stable` latest.rustChannels.nightly.rust # Add some extra dependencies from `pkgs` diff --git a/doc/using/overlays.xml b/doc/using/overlays.xml index 1def8b06955..8f12aad2ada 100644 --- a/doc/using/overlays.xml +++ b/doc/using/overlays.xml @@ -230,7 +230,7 @@ self: super: - For BLAS/LAPACK switching to work correctly, all packages must depend on blas or lapack. This ensures that only one BLAS/LAPACK library is used at one time. There are two versions versions of BLAS/LAPACK currently in the wild, LP64 (integer size = 32 bits) and ILP64 (integer size = 64 bits). Some software needs special flags or patches to work with ILP64. You can check if ILP64 is used in Nixpkgs with blas.isILP64 and lapack.isILP64. Some software does NOT work with ILP64, and derivations need to specify an assertion to prevent this. You can prevent ILP64 from being used with the following: + For BLAS/LAPACK switching to work correctly, all packages must depend on blas or lapack. This ensures that only one BLAS/LAPACK library is used at one time. There are two versions of BLAS/LAPACK currently in the wild, LP64 (integer size = 32 bits) and ILP64 (integer size = 64 bits). Some software needs special flags or patches to work with ILP64. You can check if ILP64 is used in Nixpkgs with blas.isILP64 and lapack.isILP64. Some software does NOT work with ILP64, and derivations need to specify an assertion to prevent this. You can prevent ILP64 from being used with the following: -- cgit 1.4.1 From 29df3bc24cd80e5a13f866f639e5d7f4c47b643e Mon Sep 17 00:00:00 2001 From: Katharina Fey Date: Fri, 19 Mar 2021 13:30:28 +0100 Subject: doc: fix code formatting --- doc/languages-frameworks/rust.section.md | 1 + 1 file changed, 1 insertion(+) (limited to 'doc/languages-frameworks/rust.section.md') diff --git a/doc/languages-frameworks/rust.section.md b/doc/languages-frameworks/rust.section.md index 020201d0866..7789ef857ee 100644 --- a/doc/languages-frameworks/rust.section.md +++ b/doc/languages-frameworks/rust.section.md @@ -146,6 +146,7 @@ where they are known to differ. But there are ways to customize the argument: rustc.platform = { foo = ""; bar = ""; }; }; } + ``` will result in: ```shell --target /nix/store/asdfasdfsadf-thumb-crazy.json # contains {"foo":"","bar":""} -- cgit 1.4.1 From 2c143a461438a4e3c9509222274be819df8d86ef Mon Sep 17 00:00:00 2001 From: Sandro Jäckel Date: Sun, 14 Mar 2021 00:30:36 +0100 Subject: doc/languages-frameworks/*: add missing languages to code fences convert shell -> ShellSession --- doc/languages-frameworks/agda.section.md | 14 ++++---- doc/languages-frameworks/dotnet.section.md | 6 ++-- doc/languages-frameworks/idris.section.md | 18 +++++----- doc/languages-frameworks/python.section.md | 8 ++--- doc/languages-frameworks/qt.section.md | 6 ++-- doc/languages-frameworks/rust.section.md | 53 +++++++++++++++--------------- doc/languages-frameworks/vim.section.md | 8 ++--- 7 files changed, 57 insertions(+), 56 deletions(-) (limited to 'doc/languages-frameworks/rust.section.md') diff --git a/doc/languages-frameworks/agda.section.md b/doc/languages-frameworks/agda.section.md index f57b194a726..30a266502bf 100644 --- a/doc/languages-frameworks/agda.section.md +++ b/doc/languages-frameworks/agda.section.md @@ -3,7 +3,7 @@ ## How to use Agda Agda can be installed from `agda`: -``` +```ShellSession $ nix-env -iA agda ``` @@ -15,13 +15,13 @@ To use Agda with libraries, the `agda.withPackages` function can be used. This f For example, suppose we wanted a version of Agda which has access to the standard library. This can be obtained with the expressions: -``` +```nix agda.withPackages [ agdaPackages.standard-library ] ``` or -``` +```nix agda.withPackages (p: [ p.standard-library ]) ``` @@ -32,7 +32,7 @@ If you want to use a library in your home directory (for instance if it is a dev Agda will not by default use these libraries. To tell Agda to use the library we have some options: * Call `agda` with the library flag: -``` +```ShellSession $ agda -l standard-library -i . MyFile.agda ``` * Write a `my-library.agda-lib` file for the project you are working on which may look like: @@ -49,7 +49,7 @@ More information can be found in the [official Agda documentation on library man Agda modules can be compiled with the `--compile` flag. A version of `ghc` with `ieee754` is made available to the Agda program via the `--with-compiler` flag. This can be overridden by a different version of `ghc` as follows: -``` +```nix agda.withPackages { pkgs = [ ... ]; ghc = haskell.compiler.ghcHEAD; @@ -80,12 +80,12 @@ By default, Agda sources are files ending on `.agda`, or literate Agda files end ## Adding Agda packages to Nixpkgs To add an Agda package to `nixpkgs`, the derivation should be written to `pkgs/development/libraries/agda/${library-name}/` and an entry should be added to `pkgs/top-level/agda-packages.nix`. Here it is called in a scope with access to all other Agda libraries, so the top line of the `default.nix` can look like: -``` +```nix { mkDerivation, standard-library, fetchFromGitHub }: ``` and `mkDerivation` should be called instead of `agdaPackages.mkDerivation`. Here is an example skeleton derivation for iowa-stdlib: -``` +```nix mkDerivation { version = "1.5.0"; pname = "iowa-stdlib"; diff --git a/doc/languages-frameworks/dotnet.section.md b/doc/languages-frameworks/dotnet.section.md index c3947042494..36369fd4e63 100644 --- a/doc/languages-frameworks/dotnet.section.md +++ b/doc/languages-frameworks/dotnet.section.md @@ -4,7 +4,7 @@ For local development, it's recommended to use nix-shell to create a dotnet environment: -``` +```nix # shell.nix with import {}; @@ -20,7 +20,7 @@ mkShell { It's very likely that more than one sdk will be needed on a given project. Dotnet provides several different frameworks (E.g dotnetcore, aspnetcore, etc.) as well as many versions for a given framework. Normally, dotnet is able to fetch a framework and install it relative to the executable. However, this would mean writing to the nix store in nixpkgs, which is read-only. To support the many-sdk use case, one can compose an environment using `dotnetCorePackages.combinePackages`: -``` +```nix with import {}; mkShell { @@ -37,7 +37,7 @@ mkShell { This will produce a dotnet installation that has the dotnet 3.1, 3.0, and 2.1 sdk. The first sdk listed will have it's cli utility present in the resulting environment. Example info output: -``` +```ShellSesssion $ dotnet --info .NET Core SDK (reflecting any global.json): Version: 3.1.101 diff --git a/doc/languages-frameworks/idris.section.md b/doc/languages-frameworks/idris.section.md index 41e4f7ec312..000e3627d70 100644 --- a/doc/languages-frameworks/idris.section.md +++ b/doc/languages-frameworks/idris.section.md @@ -4,7 +4,7 @@ The easiest way to get a working idris version is to install the `idris` attribute: -``` +```ShellSesssion $ # On NixOS $ nix-env -i nixos.idris $ # On non-NixOS @@ -21,7 +21,7 @@ self: super: { And then: -``` +```ShellSesssion $ # On NixOS $ nix-env -iA nixos.myIdris $ # On non-NixOS @@ -29,7 +29,7 @@ $ nix-env -iA nixpkgs.myIdris ``` To see all available Idris packages: -``` +```ShellSesssion $ # On NixOS $ nix-env -qaPA nixos.idrisPackages $ # On non-NixOS @@ -37,7 +37,7 @@ $ nix-env -qaPA nixpkgs.idrisPackages ``` Similarly, entering a `nix-shell`: -``` +```ShellSesssion $ nix-shell -p 'idrisPackages.with-packages (with idrisPackages; [ contrib pruviloj ])' ``` @@ -45,14 +45,14 @@ $ nix-shell -p 'idrisPackages.with-packages (with idrisPackages; [ contrib pruvi To have access to these libraries in idris, call it with an argument `-p ` for each library: -``` +```ShellSesssion $ nix-shell -p 'idrisPackages.with-packages (with idrisPackages; [ contrib pruviloj ])' [nix-shell:~]$ idris -p contrib -p pruviloj ``` A listing of all available packages the Idris binary has access to is available via `--listlibs`: -``` +```ShellSesssion $ idris --listlibs 00prelude-idx.ibc pruviloj @@ -105,7 +105,7 @@ build-idris-package { Assuming this file is saved as `yaml.nix`, it's buildable using -``` +```ShellSesssion $ nix-build -E '(import {}).idrisPackages.callPackage ./yaml.nix {}' ``` @@ -121,7 +121,7 @@ with import {}; in another file (say `default.nix`) to be able to build it with -``` +```ShellSesssion $ nix-build -A yaml ``` @@ -133,7 +133,7 @@ Specifically, you can set `idrisBuildOptions`, `idrisTestOptions`, `idrisInstall For example you could set -``` +```nix build-idris-package { idrisBuildOptions = [ "--log" "1" "--verbose" ] diff --git a/doc/languages-frameworks/python.section.md b/doc/languages-frameworks/python.section.md index 26458c3906e..4c69f9c85cf 100644 --- a/doc/languages-frameworks/python.section.md +++ b/doc/languages-frameworks/python.section.md @@ -78,7 +78,7 @@ $ nix-shell -p 'python38.withPackages(ps: with ps; [ numpy toolz ])' By default `nix-shell` will start a `bash` session with this interpreter in our `PATH`, so if we then run: -``` +```Python console [nix-shell:~/src/nixpkgs]$ python3 Python 3.8.1 (default, Dec 18 2019, 19:06:26) [GCC 9.2.0] on linux @@ -89,7 +89,7 @@ Type "help", "copyright", "credits" or "license" for more information. Note that no other modules are in scope, even if they were imperatively installed into our user environment as a dependency of a Python application: -``` +```Python console >>> import requests Traceback (most recent call last): File "", line 1, in @@ -145,8 +145,8 @@ print(f"The dot product of {a} and {b} is: {np.dot(a, b)}") Executing this script requires a `python3` that has `numpy`. Using what we learned in the previous section, we could startup a shell and just run it like so: -``` -nix-shell -p 'python38.withPackages(ps: with ps; [ numpy ])' --run 'python3 foo.py' +```ShellSesssion +$ nix-shell -p 'python38.withPackages(ps: with ps; [ numpy ])' --run 'python3 foo.py' The dot product of [1 2] and [3 4] is: 11 ``` diff --git a/doc/languages-frameworks/qt.section.md b/doc/languages-frameworks/qt.section.md index 9747c1037ad..6f8c9626e6d 100644 --- a/doc/languages-frameworks/qt.section.md +++ b/doc/languages-frameworks/qt.section.md @@ -103,7 +103,7 @@ supported Qt version. ### Example adding a Qt library {#qt-library-all-packages-nix} The following represents the contents of `qt5-packages.nix`. -``` +```nix { # ... @@ -133,7 +133,7 @@ to select the Qt 5 version used for the application. ### Example adding a Qt application {#qt-application-all-packages-nix} The following represents the contents of `qt5-packages.nix`. -``` +```nix { # ... @@ -144,7 +144,7 @@ The following represents the contents of `qt5-packages.nix`. ``` The following represents the contents of `all-packages.nix`. -``` +```nix { # ... diff --git a/doc/languages-frameworks/rust.section.md b/doc/languages-frameworks/rust.section.md index 7789ef857ee..882eb9c4afa 100644 --- a/doc/languages-frameworks/rust.section.md +++ b/doc/languages-frameworks/rust.section.md @@ -2,13 +2,14 @@ To install the rust compiler and cargo put -``` -rustc -cargo +```nix +environment.systemPackages = [ + rustc + cargo +]; ``` -into the `environment.systemPackages` or bring them into -scope with `nix-shell -p rustc cargo`. +into your `configuration.nix` or bring them into scope with `nix-shell -p rustc cargo`. For other versions such as daily builds (beta and nightly), use either `rustup` from nixpkgs (which will manage the rust installation in your home directory), @@ -18,7 +19,7 @@ or use Mozilla's [Rust nightlies overlay](#using-the-rust-nightlies-overlay). Rust applications are packaged by using the `buildRustPackage` helper from `rustPlatform`: -``` +```nix { lib, rustPlatform }: rustPlatform.buildRustPackage rec { @@ -49,7 +50,7 @@ package. `cargoHash256` is used for traditional Nix SHA-256 hashes, such as the one in the example above. `cargoHash` should instead be used for [SRI](https://www.w3.org/TR/SRI/) hashes. For example: -``` +```nix cargoHash = "sha256-l1vL2ZdtDRxSGvP0X/l3nMw8+6WF67KPutJEzUROjg8="; ``` @@ -59,13 +60,13 @@ expression and building the package once. The correct checksum can then be taken from the failed build. A fake hash can be used for `cargoSha256` as follows: -``` +```nix cargoSha256 = lib.fakeSha256; ``` For `cargoHash` you can use: -``` +```nix cargoHash = lib.fakeHash; ``` @@ -255,7 +256,7 @@ Otherwise, some steps may fail because of the modified directory structure of `t 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 { (...) cargoPatches = [ @@ -481,7 +482,7 @@ an example for a minimal `hello` crate: Now, the file produced by the call to `carnix`, called `hello.nix`, looks like: -``` +```nix # Generated by carnix 0.6.5: carnix -o hello.nix --src ./. Cargo.lock --standalone { stdenv, buildRustCrate, fetchgit }: let kernel = stdenv.buildPlatform.parsed.kernel.name; @@ -510,7 +511,7 @@ dependencies, for instance by adding a single line `libc="*"` to our `Cargo.lock`. Then, `carnix` needs to be run again, and produces the following nix file: -``` +```nix # Generated by carnix 0.6.5: carnix -o hello.nix --src ./. Cargo.lock --standalone { stdenv, buildRustCrate, fetchgit }: let kernel = stdenv.buildPlatform.parsed.kernel.name; @@ -565,7 +566,7 @@ Some crates require external libraries. For crates from Starting from that file, one can add more overrides, to add features or build inputs by overriding the hello crate in a seperate file. -``` +```nix with import {}; ((import ./hello.nix).hello {}).override { crateOverrides = defaultCrateOverrides // { @@ -585,7 +586,7 @@ derivation depend on the crate's version, the `attrs` argument of the override above can be read, as in the following example, which patches the derivation: -``` +```nix with import {}; ((import ./hello.nix).hello {}).override { crateOverrides = defaultCrateOverrides // { @@ -606,7 +607,7 @@ dependencies. For instance, to override the build inputs for crate `libc` in the example above, where `libc` is a dependency of the main crate, we could do: -``` +```nix with import {}; ((import hello.nix).hello {}).override { crateOverrides = defaultCrateOverrides // { @@ -622,27 +623,27 @@ general. A number of other parameters can be overridden: - The version of rustc used to compile the crate: - ``` + ```nix (hello {}).override { rust = pkgs.rust; }; ``` - Whether to build in release mode or debug mode (release mode by default): - ``` + ```nix (hello {}).override { release = false; }; ``` - Whether to print the commands sent to rustc when building (equivalent to `--verbose` in cargo: - ``` + ```nix (hello {}).override { verbose = false; }; ``` - Extra arguments to be passed to `rustc`: - ``` + ```nix (hello {}).override { extraRustcOpts = "-Z debuginfo=2"; }; ``` @@ -654,7 +655,7 @@ general. A number of other parameters can be overridden: `postInstall`. As an example, here is how to create a new module before running the build script: - ``` + ```nix (hello {}).override { preConfigure = '' echo "pub const PATH=\"${hi.out}\";" >> src/path.rs" @@ -668,7 +669,7 @@ One can also supply features switches. For example, if we want to compile `diesel_cli` only with the `postgres` feature, and no default features, we would write: -``` +```nix (callPackage ./diesel.nix {}).diesel { default = false; postgres = true; @@ -691,7 +692,7 @@ Using the example `hello` project above, we want to do the following: A typical `shell.nix` might look like: -``` +```nix with import {}; stdenv.mkDerivation { @@ -713,7 +714,7 @@ stdenv.mkDerivation { ``` You should now be able to run the following: -``` +```ShellSesssion $ nix-shell --pure $ cargo build $ cargo test @@ -723,7 +724,7 @@ $ cargo test To control your rust version (i.e. use nightly) from within `shell.nix` (or other nix expressions) you can use the following `shell.nix` -``` +```nix # Latest Nightly with import {}; let src = fetchFromGitHub { @@ -751,7 +752,7 @@ stdenv.mkDerivation { ``` Now run: -``` +```ShellSession $ rustc --version rustc 1.26.0-nightly (188e693b3 2018-03-26) ``` @@ -786,7 +787,7 @@ in the `~/.config/nixpkgs/overlays` directory. Add the following to your `configuration.nix`, `home-configuration.nix`, `shell.nix`, or similar: -``` +```nix { pkgs ? import { overlays = [ (import (builtins.fetchTarball https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz)) diff --git a/doc/languages-frameworks/vim.section.md b/doc/languages-frameworks/vim.section.md index 155dacc237b..22b5e6f3013 100644 --- a/doc/languages-frameworks/vim.section.md +++ b/doc/languages-frameworks/vim.section.md @@ -156,7 +156,7 @@ assuming that "using latest version" is ok most of the time. First create a vim-scripts file having one plugin name per line. Example: -``` +```vim "tlib" {'name': 'vim-addon-sql'} {'filetype_regex': '\%(vim)$', 'names': ['reload', 'vim-dev-plugin']} @@ -197,7 +197,7 @@ nix-shell -p vimUtils.vim_with_vim2nix --command "vim -c 'source generate.vim'" You should get a Vim buffer with the nix derivations (output1) and vam.pluginDictionaries (output2). You can add your Vim to your system's configuration file like this and start it by "vim-my": -``` +```nix my-vim = let plugins = let inherit (vimUtils) buildVimPluginFrom2Nix; in { copy paste output1 here @@ -217,7 +217,7 @@ my-vim = Sample output1: -``` +```nix "reload" = buildVimPluginFrom2Nix { # created by nix#NixDerivation name = "reload"; src = fetchgit { @@ -248,7 +248,7 @@ Nix expressions for Vim plugins are stored in [pkgs/misc/vim-plugins](/pkgs/misc Some plugins require overrides in order to function properly. Overrides are placed in [overrides.nix](/pkgs/misc/vim-plugins/overrides.nix). Overrides are most often required when a plugin requires some dependencies, or extra steps are required during the build process. For example `deoplete-fish` requires both `deoplete-nvim` and `vim-fish`, and so the following override was added: -``` +```nix deoplete-fish = super.deoplete-fish.overrideAttrs(old: { dependencies = with super; [ deoplete-nvim vim-fish ]; }); -- cgit 1.4.1 From 2f46d77e2806dd22f4ec4ac6ea3f9981df81dd94 Mon Sep 17 00:00:00 2001 From: Daniël de Kok Date: Sat, 8 May 2021 07:40:34 +0200 Subject: rustPlatform.importCargoLock: init This function can be used to create an output path that is a cargo vendor directory. In contrast to e.g. fetchCargoTarball all the dependent crates are fetched using fixed-output derivations. The hashes for the fixed-output derivations are gathered from the Cargo.lock file. Usage is very simple, e.g.: importCargoLock { lockFile = ./Cargo.lock; } would use the lockfile from the current directory. The implementation of this function is based on Eelco Dolstra's import-cargo: https://github.com/edolstra/import-cargo/blob/master/flake.nix Compared to upstream: - We use fetchgit in place of builtins.fetchGit. - Sync to current cargo vendoring. --- doc/languages-frameworks/rust.section.md | 31 ++++ pkgs/build-support/rust/import-cargo-lock.nix | 167 +++++++++++++++++++++ .../compilers/rust/make-rust-platform.nix | 2 + 3 files changed, 200 insertions(+) create mode 100644 pkgs/build-support/rust/import-cargo-lock.nix (limited to 'doc/languages-frameworks/rust.section.md') diff --git a/doc/languages-frameworks/rust.section.md b/doc/languages-frameworks/rust.section.md index d1a6a566774..70aced7d5cb 100644 --- a/doc/languages-frameworks/rust.section.md +++ b/doc/languages-frameworks/rust.section.md @@ -308,6 +308,37 @@ attributes can also be used: the `Cargo.lock`/`Cargo.toml` files need to be patched before vendoring. +If a `Cargo.lock` file is available, you can alternatively use the +`importCargoLock` function. In contrast to `fetchCargoTarball`, this +function does not require a hash (unless git dependencies are used) +and fetches every dependency as a separate fixed-output derivation. +`importCargoLock` can be used as follows: + +``` +cargoDeps = rustPlatform.importCargoLock { + lockFile = ./Cargo.lock; +}; +``` + +If the `Cargo.lock` file includes git dependencies, then their output +hashes need to be specified since they are not available through the +lock file. For example: + +``` +cargoDeps = { + lockFile = ./Cargo.lock; + outputHashes = { + "rand-0.8.3" = "0ya2hia3cn31qa8894s3av2s8j5bjwb6yq92k0jsnlx7jid0jwqa"; + }; +}; +``` + +If you do not specify an output hash for a git dependency, building +`cargoDeps` will fail and inform you of which crate needs to be +added. To find the correct hash, you can first use `lib.fakeSha256` or +`lib.fakeHash` as a stub hash. Building `cargoDeps` will then inform +you of the correct hash. + ### Hooks `rustPlatform` provides the following hooks to automate Cargo builds: diff --git a/pkgs/build-support/rust/import-cargo-lock.nix b/pkgs/build-support/rust/import-cargo-lock.nix new file mode 100644 index 00000000000..244572f79e8 --- /dev/null +++ b/pkgs/build-support/rust/import-cargo-lock.nix @@ -0,0 +1,167 @@ +{ fetchgit, fetchurl, lib, runCommand, cargo, jq }: + +{ + # Cargo lock file + lockFile + + # Hashes for git dependencies. +, outputHashes ? {} +}: + +let + # Parse a git source into different components. + parseGit = src: + let + parts = builtins.match ''git\+([^?]+)(\?rev=(.*))?#(.*)?'' src; + rev = builtins.elemAt parts 2; + in + if parts == null then null + else { + url = builtins.elemAt parts 0; + sha = builtins.elemAt parts 3; + } // lib.optionalAttrs (rev != null) { inherit rev; }; + + packages = (builtins.fromTOML (builtins.readFile lockFile)).package; + + # There is no source attribute for the source package itself. But + # since we do not want to vendor the source package anyway, we can + # safely skip it. + depPackages = (builtins.filter (p: p ? "source") packages); + + # Create dependent crates from packages. + # + # Force evaluation of the git SHA -> hash mapping, so that an error is + # thrown if there are stale hashes. We cannot rely on gitShaOutputHash + # being evaluated otherwise, since there could be no git dependencies. + depCrates = builtins.deepSeq (gitShaOutputHash) (builtins.map mkCrate depPackages); + + # Map package name + version to git commit SHA for packages with a git source. + namesGitShas = builtins.listToAttrs ( + builtins.map nameGitSha (builtins.filter (pkg: lib.hasPrefix "git+" pkg.source) depPackages) + ); + + nameGitSha = pkg: let gitParts = parseGit pkg.source; in { + name = "${pkg.name}-${pkg.version}"; + value = gitParts.sha; + }; + + # Convert the attrset provided through the `outputHashes` argument to a + # a mapping from git commit SHA -> output hash. + # + # There may be multiple different packages with different names + # originating from the same git repository (typically a Cargo + # workspace). By using the git commit SHA as a universal identifier, + # the user does not have to specify the output hash for every package + # individually. + gitShaOutputHash = lib.mapAttrs' (nameVer: hash: + let + unusedHash = throw "A hash was specified for ${nameVer}, but there is no corresponding git dependency."; + rev = namesGitShas.${nameVer} or unusedHash; in { + name = rev; + value = hash; + }) outputHashes; + + # We can't use the existing fetchCrate function, since it uses a + # recursive hash of the unpacked crate. + fetchCrate = pkg: fetchurl { + name = "crate-${pkg.name}-${pkg.version}.tar.gz"; + url = "https://crates.io/api/v1/crates/${pkg.name}/${pkg.version}/download"; + sha256 = pkg.checksum; + }; + + # Fetch and unpack a crate. + mkCrate = pkg: + let + gitParts = parseGit pkg.source; + in + if pkg.source == "registry+https://github.com/rust-lang/crates.io-index" then + let + crateTarball = fetchCrate pkg; + in runCommand "${pkg.name}-${pkg.version}" {} '' + mkdir $out + tar xf "${crateTarball}" -C $out --strip-components=1 + + # Cargo is happy with largely empty metadata. + printf '{"files":{},"package":"${pkg.checksum}"}' > "$out/.cargo-checksum.json" + '' + else if gitParts != null then + let + missingHash = throw '' + No hash was found while vendoring the git dependency ${pkg.name}-${pkg.version}. You can add + a hash through the `outputHashes` argument of `importCargoLock`: + + outputHashes = { + "${pkg.name}-${pkg.version}" = ""; + }; + + If you use `buildRustPackage`, you can add this attribute to the `cargoLock` + attribute set. + ''; + sha256 = gitShaOutputHash.${gitParts.sha} or missingHash; + tree = fetchgit { + inherit sha256; + inherit (gitParts) url; + rev = gitParts.sha; # The commit SHA is always available. + }; + in runCommand "${pkg.name}-${pkg.version}" {} '' + tree=${tree} + if grep --quiet '\[workspace\]' "$tree/Cargo.toml"; then + # If the target package is in a workspace, find the crate path + # using `cargo metadata`. + crateCargoTOML=$(${cargo}/bin/cargo metadata --format-version 1 --no-deps --manifest-path $tree/Cargo.toml | \ + ${jq}/bin/jq -r '.packages[] | select(.name == "${pkg.name}") | .manifest_path') + + if [[ ! -z $crateCargoTOML ]]; then + tree=$(dirname $crateCargoTOML) + else + >&2 echo "Cannot find path for crate '${pkg.name}-${pkg.version}' in the Cargo workspace in: $tree" + exit 1 + fi + fi + + cp -prvd "$tree/" $out + chmod u+w $out + + # Cargo is happy with empty metadata. + printf '{"files":{},"package":null}' > "$out/.cargo-checksum.json" + + # Set up configuration for the vendor directory. + cat > $out/.cargo-config < $out/.cargo/config <> $out/.cargo/config + fi + fi + done + ''; +in + vendorDir diff --git a/pkgs/development/compilers/rust/make-rust-platform.nix b/pkgs/development/compilers/rust/make-rust-platform.nix index 584b1fdbe43..2343fd74901 100644 --- a/pkgs/development/compilers/rust/make-rust-platform.nix +++ b/pkgs/development/compilers/rust/make-rust-platform.nix @@ -16,6 +16,8 @@ rec { fetchCargoTarball rustc; }; + importCargoLock = buildPackages.callPackage ../../../build-support/rust/import-cargo-lock.nix {}; + rustcSrc = callPackage ./rust-src.nix { inherit rustc; }; -- cgit 1.4.1 From b3969f3ad793ee98af14cf0c649f626520943a53 Mon Sep 17 00:00:00 2001 From: Daniël de Kok Date: Sat, 8 May 2021 07:44:31 +0200 Subject: rustPlatform.buildRustPackage: support direct use of Cargo.lock This change introduces the cargoLock argument to buildRustPackage, which can be used in place of cargo{Sha256,Hash} or cargoVendorDir. It uses the importCargoLock function to build the vendor directory. Differences compared to cargo{Sha256,Hash}: - Requires a Cargo.lock file. - Does not require a Cargo hash. - Retrieves all dependencies as fixed-output derivations. This makes buildRustPackage much easier to use as part of a Rust project, since it does not require updating cargo{Sha256,Hash} for every change to the lock file. --- doc/languages-frameworks/rust.section.md | 48 ++++++++++++++++++++++ pkgs/build-support/rust/default.nix | 25 ++++++----- .../compilers/rust/make-rust-platform.nix | 2 +- 3 files changed, 64 insertions(+), 11 deletions(-) (limited to 'doc/languages-frameworks/rust.section.md') diff --git a/doc/languages-frameworks/rust.section.md b/doc/languages-frameworks/rust.section.md index 70aced7d5cb..008909e5c76 100644 --- a/doc/languages-frameworks/rust.section.md +++ b/doc/languages-frameworks/rust.section.md @@ -107,6 +107,54 @@ rustPlatform.buildRustPackage rec { } ``` +### Importing a `Cargo.lock` file + +Using `cargoSha256` or `cargoHash` is tedious when using +`buildRustPackage` within a project, since it requires that the hash +is updated after every change to `Cargo.lock`. Therefore, +`buildRustPackage` also supports vendoring dependencies directly from +a `Cargo.lock` file using the `cargoLock` argument. For example: + +```nix +rustPlatform.buildRustPackage rec { + pname = "myproject"; + version = "1.0.0"; + + cargoLock = { + lockFile = ./Cargo.lock; + } + + # ... +} +``` + +This will retrieve the dependencies using fixed-output derivations from +the specified lockfile. + +The output hash of each dependency that uses a git source must be +specified in the `outputHashes` attribute. For example: + +```nix +rustPlatform.buildRustPackage rec { + pname = "myproject"; + version = "1.0.0"; + + cargoLock = { + lockFile = ./Cargo.lock; + outputHashes = { + "finalfusion-0.14.0" = "17f4bsdzpcshwh74w5z119xjy2if6l2wgyjy56v621skr2r8y904"; + }; + } + + # ... +} +``` + +If you do not specify an output hash for a git dependency, building +the package will fail and inform you of which crate needs to be +added. To find the correct hash, you can first use `lib.fakeSha256` or +`lib.fakeHash` as a stub hash. Building the package (and thus the +vendored dependencies) will then inform you of the correct hash. ### Cross compilation diff --git a/pkgs/build-support/rust/default.nix b/pkgs/build-support/rust/default.nix index ff9ca642daa..711276116a6 100644 --- a/pkgs/build-support/rust/default.nix +++ b/pkgs/build-support/rust/default.nix @@ -7,6 +7,7 @@ , cargoInstallHook , cargoSetupHook , fetchCargoTarball +, importCargoLock , runCommandNoCC , rustPlatform , callPackage @@ -41,6 +42,7 @@ , cargoDepsHook ? "" , buildType ? "release" , meta ? {} +, cargoLock ? null , cargoVendorDir ? null , checkType ? buildType , depsExtraArgs ? {} @@ -55,19 +57,22 @@ , buildAndTestSubdir ? null , ... } @ args: -assert cargoVendorDir == null -> !(cargoSha256 == "" && cargoHash == ""); +assert cargoVendorDir == null && cargoLock == null -> cargoSha256 == "" && cargoHash == "" + -> throw "cargoSha256, cargoHash, cargoVendorDir, or cargoLock must be set"; assert buildType == "release" || buildType == "debug"; let - cargoDeps = if cargoVendorDir == null - then fetchCargoTarball ({ - inherit src srcs sourceRoot unpackPhase cargoUpdateHook; - name = cargoDepsName; - hash = cargoHash; - patches = cargoPatches; - sha256 = cargoSha256; - } // depsExtraArgs) + cargoDeps = + if cargoVendorDir == null + then if cargoLock != null then importCargoLock cargoLock + else fetchCargoTarball ({ + inherit src srcs sourceRoot unpackPhase cargoUpdateHook; + name = cargoDepsName; + hash = cargoHash; + patches = cargoPatches; + sha256 = cargoSha256; + } // depsExtraArgs) else null; # If we have a cargoSha256 fixed-output derivation, validate it at build time @@ -96,7 +101,7 @@ in # See https://os.phil-opp.com/testing/ for more information. assert useSysroot -> !(args.doCheck or true); -stdenv.mkDerivation ((removeAttrs args ["depsExtraArgs"]) // lib.optionalAttrs useSysroot { +stdenv.mkDerivation ((removeAttrs args [ "depsExtraArgs" "cargoLock" ]) // lib.optionalAttrs useSysroot { RUSTFLAGS = "--sysroot ${sysroot} " + (args.RUSTFLAGS or ""); } // { inherit buildAndTestSubdir cargoDeps; diff --git a/pkgs/development/compilers/rust/make-rust-platform.nix b/pkgs/development/compilers/rust/make-rust-platform.nix index 2343fd74901..2a38933df16 100644 --- a/pkgs/development/compilers/rust/make-rust-platform.nix +++ b/pkgs/development/compilers/rust/make-rust-platform.nix @@ -13,7 +13,7 @@ rec { buildRustPackage = callPackage ../../../build-support/rust { inherit cargoBuildHook cargoCheckHook cargoInstallHook cargoSetupHook - fetchCargoTarball rustc; + fetchCargoTarball importCargoLock rustc; }; importCargoLock = buildPackages.callPackage ../../../build-support/rust/import-cargo-lock.nix {}; -- cgit 1.4.1 From 9cca8ce4468487962ecd28f3ad8d937857636963 Mon Sep 17 00:00:00 2001 From: Daniël de Kok Date: Tue, 1 Jun 2021 13:14:28 +0200 Subject: doc: fix incorrect use of cargoDeps Thanks to @bjornfor for reporting this error! --- doc/languages-frameworks/rust.section.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'doc/languages-frameworks/rust.section.md') diff --git a/doc/languages-frameworks/rust.section.md b/doc/languages-frameworks/rust.section.md index 008909e5c76..5ff7a5edefd 100644 --- a/doc/languages-frameworks/rust.section.md +++ b/doc/languages-frameworks/rust.section.md @@ -373,7 +373,7 @@ hashes need to be specified since they are not available through the lock file. For example: ``` -cargoDeps = { +cargoDeps = rustPlatform.importCargoLock { lockFile = ./Cargo.lock; outputHashes = { "rand-0.8.3" = "0ya2hia3cn31qa8894s3av2s8j5bjwb6yq92k0jsnlx7jid0jwqa"; -- cgit 1.4.1 From 6ecc641d087df8b8896ebd876bba592e981877c9 Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Sat, 5 Jun 2021 21:22:45 +0200 Subject: doc: prepare for commonmark MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We are still using Pandoc’s Markdown parser, which differs from CommonMark spec slightly. Notably: - Line breaks in lists behave differently. - Admonitions do not support the simpler syntax https://github.com/jgm/commonmark-hs/issues/75 - The auto_identifiers uses a different algorithm – I made the previous ones explicit. - Languages (classes) of code blocks cannot contain whitespace so we have to use “pycon” alias instead of Python “console” as GitHub’s linguist While at it, I also fixed the following issues: - ShellSesssion was used - Removed some pointless docbook tags. --- doc/builders/fetchers.chapter.md | 25 ++-- doc/builders/images/appimagetools.section.md | 2 +- doc/builders/images/dockertools.section.md | 4 +- doc/builders/images/snaptools.section.md | 4 +- doc/builders/packages/cataclysm-dda.section.md | 6 +- doc/builders/packages/elm.section.md | 2 +- doc/builders/packages/firefox.section.md | 2 +- doc/builders/packages/opengl.section.md | 4 +- doc/builders/packages/steam.section.md | 23 ++-- doc/builders/packages/xorg.section.md | 8 +- doc/builders/trivial-builders.chapter.md | 2 +- doc/contributing/coding-conventions.chapter.md | 4 +- .../contributing-to-documentation.chapter.md | 2 +- .../reviewing-contributions.chapter.md | 5 +- doc/contributing/submitting-changes.chapter.md | 4 +- doc/languages-frameworks/agda.section.md | 35 +++--- doc/languages-frameworks/android.section.md | 33 +++--- doc/languages-frameworks/beam.section.md | 10 +- doc/languages-frameworks/bower.section.md | 2 +- doc/languages-frameworks/coq.section.md | 4 +- doc/languages-frameworks/crystal.section.md | 4 +- doc/languages-frameworks/dotnet.section.md | 14 +-- doc/languages-frameworks/emscripten.section.md | 14 +-- doc/languages-frameworks/gnome.section.md | 2 +- doc/languages-frameworks/go.section.md | 4 +- doc/languages-frameworks/idris.section.md | 26 ++-- doc/languages-frameworks/ios.section.md | 17 +-- doc/languages-frameworks/lua.section.md | 56 +++++---- doc/languages-frameworks/maven.section.md | 17 +-- doc/languages-frameworks/python.section.md | 121 ++++++++++--------- doc/languages-frameworks/qt.section.md | 11 +- doc/languages-frameworks/r.section.md | 10 +- doc/languages-frameworks/ruby.section.md | 22 ++-- doc/languages-frameworks/rust.section.md | 102 +++++++++------- doc/languages-frameworks/texlive.section.md | 2 + doc/languages-frameworks/titanium.section.md | 8 +- doc/languages-frameworks/vim.section.md | 20 ++-- doc/preface.chapter.md | 2 +- doc/stdenv/cross-compilation.chapter.md | 31 ++--- doc/stdenv/meta.chapter.md | 10 +- doc/stdenv/multiple-output.chapter.md | 22 ++-- doc/stdenv/stdenv.chapter.md | 132 +++++++++++---------- doc/using/overlays.chapter.md | 2 +- doc/using/overrides.chapter.md | 12 +- 44 files changed, 454 insertions(+), 388 deletions(-) (limited to 'doc/languages-frameworks/rust.section.md') diff --git a/doc/builders/fetchers.chapter.md b/doc/builders/fetchers.chapter.md index c70e3020bbf..30d06534485 100644 --- a/doc/builders/fetchers.chapter.md +++ b/doc/builders/fetchers.chapter.md @@ -20,59 +20,58 @@ The main difference between `fetchurl` and `fetchzip` is in how they store the c `fetchpatch` works very similarly to `fetchurl` with the same arguments expected. It expects patch files as a source and performs normalization on them before computing the checksum. For example it will remove comments or other unstable parts that are sometimes added by version control systems and can change over time. - Other fetcher functions allow you to add source code directly from a VCS such as subversion or git. These are mostly straightforward nambes based on the name of the command used with the VCS system. Because they give you a working repository, they act most like `fetchzip`. -## `fetchsvn` +## `fetchsvn` {#fetchsvn} Used with Subversion. Expects `url` to a Subversion directory, `rev`, and `sha256`. -## `fetchgit` +## `fetchgit` {#fetchgit} Used with Git. Expects `url` to a Git repo, `rev`, and `sha256`. `rev` in this case can be full the git commit id (SHA1 hash) or a tag name like `refs/tags/v1.0`. Additionally the following optional arguments can be given: `fetchSubmodules = true` makes `fetchgit` also fetch the submodules of a repository. If `deepClone` is set to true, the entire repository is cloned as opposing to just creating a shallow clone. `deepClone = true` also implies `leaveDotGit = true` which means that the `.git` directory of the clone won't be removed after checkout. -## `fetchfossil` +## `fetchfossil` {#fetchfossil} Used with Fossil. Expects `url` to a Fossil archive, `rev`, and `sha256`. -## `fetchcvs` +## `fetchcvs` {#fetchcvs} Used with CVS. Expects `cvsRoot`, `tag`, and `sha256`. -## `fetchhg` +## `fetchhg` {#fetchhg} Used with Mercurial. Expects `url`, `rev`, and `sha256`. A number of fetcher functions wrap part of `fetchurl` and `fetchzip`. They are mainly convenience functions intended for commonly used destinations of source code in Nixpkgs. These wrapper fetchers are listed below. -## `fetchFromGitHub` +## `fetchFromGitHub` {#fetchfromgithub} `fetchFromGitHub` expects four arguments. `owner` is a string corresponding to the GitHub user or organization that controls this repository. `repo` corresponds to the name of the software repository. These are located at the top of every GitHub HTML page as `owner`/`repo`. `rev` corresponds to the Git commit hash or tag (e.g `v1.0`) that will be downloaded from Git. Finally, `sha256` corresponds to the hash of the extracted directory. Again, other hash algorithms are also available but `sha256` is currently preferred. `fetchFromGitHub` uses `fetchzip` to download the source archive generated by GitHub for the specified revision. If `leaveDotGit`, `deepClone` or `fetchSubmodules` are set to `true`, `fetchFromGitHub` will use `fetchgit` instead. Refer to its section for documentation of these options. -## `fetchFromGitLab` +## `fetchFromGitLab` {#fetchfromgitlab} This is used with GitLab repositories. The arguments expected are very similar to fetchFromGitHub above. -## `fetchFromGitiles` +## `fetchFromGitiles` {#fetchfromgitiles} This is used with Gitiles repositories. The arguments expected are similar to fetchgit. -## `fetchFromBitbucket` +## `fetchFromBitbucket` {#fetchfrombitbucket} This is used with BitBucket repositories. The arguments expected are very similar to fetchFromGitHub above. -## `fetchFromSavannah` +## `fetchFromSavannah` {#fetchfromsavannah} This is used with Savannah repositories. The arguments expected are very similar to fetchFromGitHub above. -## `fetchFromRepoOrCz` +## `fetchFromRepoOrCz` {#fetchfromrepoorcz} This is used with repo.or.cz repositories. The arguments expected are very similar to fetchFromGitHub above. -## `fetchFromSourcehut` +## `fetchFromSourcehut` {#fetchfromsourcehut} This is used with sourcehut repositories. The arguments expected are very similar to fetchFromGitHub above. Don't forget the tilde (~) in front of the user name! diff --git a/doc/builders/images/appimagetools.section.md b/doc/builders/images/appimagetools.section.md index 7ab4e4e9d85..67e63dc5f61 100644 --- a/doc/builders/images/appimagetools.section.md +++ b/doc/builders/images/appimagetools.section.md @@ -2,7 +2,7 @@ `pkgs.appimageTools` is a set of functions for extracting and wrapping [AppImage](https://appimage.org/) files. They are meant to be used if traditional packaging from source is infeasible, or it would take too long. To quickly run an AppImage file, `pkgs.appimage-run` can be used as well. -::: warning +::: {.warning} The `appimageTools` API is unstable and may be subject to backwards-incompatible changes in the future. ::: diff --git a/doc/builders/images/dockertools.section.md b/doc/builders/images/dockertools.section.md index 2d21eb1c2e0..bfe1d17a606 100644 --- a/doc/builders/images/dockertools.section.md +++ b/doc/builders/images/dockertools.section.md @@ -1,6 +1,6 @@ # pkgs.dockerTools {#sec-pkgs-dockerTools} -`pkgs.dockerTools` is a set of functions for creating and manipulating Docker images according to the [ Docker Image Specification v1.2.0 ](https://github.com/moby/moby/blob/master/image/spec/v1.2.md#docker-image-specification-v120). Docker itself is not used to perform any of the operations done by these functions. +`pkgs.dockerTools` is a set of functions for creating and manipulating Docker images according to the [Docker Image Specification v1.2.0](https://github.com/moby/moby/blob/master/image/spec/v1.2.md#docker-image-specification-v120). Docker itself is not used to perform any of the operations done by these functions. ## buildImage {#ssec-pkgs-dockerTools-buildImage} @@ -52,7 +52,7 @@ The above example will build a Docker image `redis/latest` from the given base i > **_NOTE:_** Using this parameter requires the `kvm` device to be available. -- `config` is used to specify the configuration of the containers that will be started off the built image in Docker. The available options are listed in the [ Docker Image Specification v1.2.0 ](https://github.com/moby/moby/blob/master/image/spec/v1.2.md#image-json-field-descriptions). +- `config` is used to specify the configuration of the containers that will be started off the built image in Docker. The available options are listed in the [Docker Image Specification v1.2.0](https://github.com/moby/moby/blob/master/image/spec/v1.2.md#image-json-field-descriptions). After the new layer has been created, its closure (to which `contents`, `config` and `runAsRoot` contribute) will be copied in the layer itself. Only new dependencies that are not already in the existing layers will be copied. diff --git a/doc/builders/images/snaptools.section.md b/doc/builders/images/snaptools.section.md index 9e1403b8828..5f710d2de7f 100644 --- a/doc/builders/images/snaptools.section.md +++ b/doc/builders/images/snaptools.section.md @@ -14,7 +14,7 @@ Currently, `makeSnap` does not support creating GUI stubs. The following expression packages GNU Hello as a Snapcraft snap. -```{#ex-snapTools-buildSnap-hello .nix} +``` {#ex-snapTools-buildSnap-hello .nix} let inherit (import { }) snapTools hello; in snapTools.makeSnap { @@ -35,7 +35,7 @@ in snapTools.makeSnap { Graphical programs require many more integrations with the host. This example uses Firefox as an example, because it is one of the most complicated programs we could package. -```{#ex-snapTools-buildSnap-firefox .nix} +``` {#ex-snapTools-buildSnap-firefox .nix} let inherit (import { }) snapTools firefox; in snapTools.makeSnap { diff --git a/doc/builders/packages/cataclysm-dda.section.md b/doc/builders/packages/cataclysm-dda.section.md index 0f908cb7590..bfeacb47fef 100644 --- a/doc/builders/packages/cataclysm-dda.section.md +++ b/doc/builders/packages/cataclysm-dda.section.md @@ -1,6 +1,6 @@ # Cataclysm: Dark Days Ahead {#cataclysm-dark-days-ahead} -## How to install Cataclysm DDA +## How to install Cataclysm DDA {#how-to-install-cataclysm-dda} To install the latest stable release of Cataclysm DDA to your profile, execute `nix-env -f "" -iA cataclysm-dda`. For the curses build (build @@ -34,7 +34,7 @@ cataclysm-dda.override { } ``` -## Important note for overriding packages +## Important note for overriding packages {#important-note-for-overriding-packages} After applying `overrideAttrs`, you need to fix `passthru.pkgs` and `passthru.withMods` attributes either manually or by using `attachPkgs`: @@ -69,7 +69,7 @@ in goodExample2.withMods (_: []) # parallel building enabled ``` -## Customizing with mods +## Customizing with mods {#customizing-with-mods} To install Cataclysm DDA with mods of your choice, you can use `withMods` attribute: diff --git a/doc/builders/packages/elm.section.md b/doc/builders/packages/elm.section.md index 53087c0e9de..ae223c802da 100644 --- a/doc/builders/packages/elm.section.md +++ b/doc/builders/packages/elm.section.md @@ -6,6 +6,6 @@ To start a development environment do nix-shell -p elmPackages.elm elmPackages.elm-format ``` -To update the Elm compiler, see nixpkgs/pkgs/development/compilers/elm/README.md. +To update the Elm compiler, see `nixpkgs/pkgs/development/compilers/elm/README.md`. To package Elm applications, [read about elm2nix](https://github.com/hercules-ci/elm2nix#elm2nix). diff --git a/doc/builders/packages/firefox.section.md b/doc/builders/packages/firefox.section.md index acf31e188c3..b7c430db232 100644 --- a/doc/builders/packages/firefox.section.md +++ b/doc/builders/packages/firefox.section.md @@ -1,6 +1,6 @@ # Firefox {#sec-firefox} -## Build wrapped Firefox with extensions and policies +## Build wrapped Firefox with extensions and policies {#build-wrapped-firefox-with-extensions-and-policies} The `wrapFirefox` function allows to pass policies, preferences and extension that are available to firefox. With the help of `fetchFirefoxAddon` this allows build a firefox version that already comes with addons pre-installed: diff --git a/doc/builders/packages/opengl.section.md b/doc/builders/packages/opengl.section.md index 6866bf89221..ee7f3af98cf 100644 --- a/doc/builders/packages/opengl.section.md +++ b/doc/builders/packages/opengl.section.md @@ -4,11 +4,11 @@ OpenGL support varies depending on which hardware is used and which drivers are Broadly, we support both GL vendors: Mesa and NVIDIA. -## NixOS Desktop +## NixOS Desktop {#nixos-desktop} The NixOS desktop or other non-headless configurations are the primary target for OpenGL libraries and applications. The current solution for discovering which drivers are available is based on [libglvnd](https://gitlab.freedesktop.org/glvnd/libglvnd). `libglvnd` performs "vendor-neutral dispatch", trying a variety of techniques to find the system's GL implementation. In practice, this will be either via standard GLX for X11 users or EGL for Wayland users, and supporting either NVIDIA or Mesa extensions. -## Nix on GNU/Linux +## Nix on GNU/Linux {#nix-on-gnulinux} If you are using a non-NixOS GNU/Linux/X11 desktop with free software video drivers, consider launching OpenGL-dependent programs from Nixpkgs with Nixpkgs versions of `libglvnd` and `mesa.drivers` in `LD_LIBRARY_PATH`. For Mesa drivers, the Linux kernel version doesn't have to match nixpkgs. diff --git a/doc/builders/packages/steam.section.md b/doc/builders/packages/steam.section.md index e33f1192f7c..d7bb6e69d7d 100644 --- a/doc/builders/packages/steam.section.md +++ b/doc/builders/packages/steam.section.md @@ -20,6 +20,7 @@ Use `programs.steam.enable = true;` if you want to add steam to systemPackages a ## Troubleshooting {#sec-steam-troub} - **Steam fails to start. What do I do?** + Try to run ```ShellSession @@ -32,24 +33,26 @@ Use `programs.steam.enable = true;` if you want to add steam to systemPackages a - The `newStdcpp` parameter was removed since NixOS 17.09 and should not be needed anymore. - Steam ships statically linked with a version of libcrypto that conflics with the one dynamically loaded by radeonsi_dri.so. If you get the error + ``` steam.sh: line 713: 7842 Segmentation fault (core dumped) ``` + have a look at [this pull request](https://github.com/NixOS/nixpkgs/pull/20269). - **Java** 1. There is no java in steam chrootenv by default. If you get a message like - ``` - /home/foo/.local/share/Steam/SteamApps/common/towns/towns.sh: line 1: java: command not found - ``` + ``` + /home/foo/.local/share/Steam/SteamApps/common/towns/towns.sh: line 1: java: command not found + ``` - You need to add + you need to add - ```nix - steam.override { withJava = true; }; - ``` + ```nix + steam.override { withJava = true; }; + ``` ## steam-run {#sec-steam-run} @@ -57,9 +60,9 @@ The FHS-compatible chroot used for steam can also be used to run other linux gam ```nix pkgs.steam.override ({ - nativeOnly = true; - newStdcpp = true; - }).run + nativeOnly = true; + newStdcpp = true; +}).run ``` to your configuration, rebuild, and run the game with diff --git a/doc/builders/packages/xorg.section.md b/doc/builders/packages/xorg.section.md index be220a25404..ae885f92346 100644 --- a/doc/builders/packages/xorg.section.md +++ b/doc/builders/packages/xorg.section.md @@ -2,7 +2,7 @@ The Nix expressions for the X.org packages reside in `pkgs/servers/x11/xorg/default.nix`. This file is automatically generated from lists of tarballs in an X.org release. As such it should not be modified directly; rather, you should modify the lists, the generator script or the file `pkgs/servers/x11/xorg/overrides.nix`, in which you can override or add to the derivations produced by the generator. -## Katamari Tarballs +## Katamari Tarballs {#katamari-tarballs} X.org upstream releases used to include [katamari](https://en.wiktionary.org/wiki/%E3%81%8B%E3%81%9F%E3%81%BE%E3%82%8A) releases, which included a holistic recommended version for each tarball, up until 7.7. To create a list of tarballs in a katamari release: @@ -14,11 +14,11 @@ cat $(PRINT_PATH=1 nix-prefetch-url $url | tail -n 1) \ | sort > "tarballs-$release.list" ``` -## Individual Tarballs +## Individual Tarballs {#individual-tarballs} The upstream release process for [X11R7.8](https://x.org/wiki/Releases/7.8/) does not include a planned katamari. Instead, each component of X.org is released as its own tarball. We maintain `pkgs/servers/x11/xorg/tarballs.list` as a list of tarballs for each individual package. This list includes X.org core libraries and protocol descriptions, extra newer X11 interface libraries, like `xorg.libxcb`, and classic utilities which are largely unused but still available if needed, like `xorg.imake`. -## Generating Nix Expressions +## Generating Nix Expressions {#generating-nix-expressions} The generator is invoked as follows: @@ -29,6 +29,6 @@ cd pkgs/servers/x11/xorg For each of the tarballs in the `.list` files, the script downloads it, unpacks it, and searches its `configure.ac` and `*.pc.in` files for dependencies. This information is used to generate `default.nix`. The generator caches downloaded tarballs between runs. Pay close attention to the `NOT FOUND: $NAME` messages at the end of the run, since they may indicate missing dependencies. (Some might be optional dependencies, however.) -## Overriding the Generator +## Overriding the Generator {#overriding-the-generator} If the expression for a package requires derivation attributes that the generator cannot figure out automatically (say, `patches` or a `postInstall` hook), you should modify `pkgs/servers/x11/xorg/overrides.nix`. diff --git a/doc/builders/trivial-builders.chapter.md b/doc/builders/trivial-builders.chapter.md index bc1317cc49c..46620e1b459 100644 --- a/doc/builders/trivial-builders.chapter.md +++ b/doc/builders/trivial-builders.chapter.md @@ -37,7 +37,7 @@ This works just like `runCommand`. The only difference is that it also provides Variant of `runCommand` that forces the derivation to be built locally, it is not substituted. This is intended for very cheap commands (<1s execution time). It saves on the network roundrip and can speed up a build. -::: note +::: {.note} This sets [`allowSubstitutes` to `false`](https://nixos.org/nix/manual/#adv-attr-allowSubstitutes), so only use `runCommandLocal` if you are certain the user will always have a builder for the `system` of the derivation. This should be true for most trivial use cases (e.g. just copying some files to a different location or adding symlinks), because there the `system` is usually the same as `builtins.currentSystem`. ::: diff --git a/doc/contributing/coding-conventions.chapter.md b/doc/contributing/coding-conventions.chapter.md index 1eaa06a659d..4fa88895484 100644 --- a/doc/contributing/coding-conventions.chapter.md +++ b/doc/contributing/coding-conventions.chapter.md @@ -462,9 +462,9 @@ Preferred source hash type is sha256. There are several ways to get it. For package updates it is enough to change one symbol to make hash fake. For new packages, you can use `lib.fakeSha256`, `lib.fakeSha512` or any other fake hash. - This is last resort method when reconstructing source URL is non-trivial and `nix-prefetch-url -A` isn't applicable (for example, [one of `kodi` dependencies](https://github.com/NixOS/nixpkgs/blob/d2ab091dd308b99e4912b805a5eb088dd536adb9/pkgs/applications/video/kodi/default.nix#L73")). The easiest way then would be replace hash with a fake one and rebuild. Nix build will fail and error message will contain desired hash. + This is last resort method when reconstructing source URL is non-trivial and `nix-prefetch-url -A` isn’t applicable (for example, [one of `kodi` dependencies](https://github.com/NixOS/nixpkgs/blob/d2ab091dd308b99e4912b805a5eb088dd536adb9/pkgs/applications/video/kodi/default.nix#L73)). The easiest way then would be replace hash with a fake one and rebuild. Nix build will fail and error message will contain desired hash. -::: warning +::: {.warning} This method has security problems. Check below for details. ::: diff --git a/doc/contributing/contributing-to-documentation.chapter.md b/doc/contributing/contributing-to-documentation.chapter.md index 05b00d9bdda..44feac7fbf7 100644 --- a/doc/contributing/contributing-to-documentation.chapter.md +++ b/doc/contributing/contributing-to-documentation.chapter.md @@ -25,7 +25,7 @@ If the build succeeds, the manual will be in `./result/share/doc/nixpkgs/manual. ## Syntax {#sec-contributing-markup} -As per [RFC 0062](https://github.com/NixOS/rfcs/pull/72), all new documentation content should be written in [CommonMark](https://commonmark.org/) Markdown dialect. +As per [RFC 0072](https://github.com/NixOS/rfcs/pull/72), all new documentation content should be written in [CommonMark](https://commonmark.org/) Markdown dialect. Additionally, the following syntax extensions are currently used: diff --git a/doc/contributing/reviewing-contributions.chapter.md b/doc/contributing/reviewing-contributions.chapter.md index 0dfe22199c6..3f3ba60947c 100644 --- a/doc/contributing/reviewing-contributions.chapter.md +++ b/doc/contributing/reviewing-contributions.chapter.md @@ -1,6 +1,6 @@ # Reviewing contributions {#chap-reviewing-contributions} -::: warning +::: {.warning} The following section is a draft, and the policy for reviewing is still being discussed in issues such as [#11166](https://github.com/NixOS/nixpkgs/issues/11166) and [#20836](https://github.com/NixOS/nixpkgs/issues/20836). ::: @@ -35,15 +35,18 @@ Reviewing process: - Building the package locally. - pull requests are often targeted to the master or staging branch, and building the pull request locally when it is submitted can trigger many source builds. - It is possible to rebase the changes on nixos-unstable or nixpkgs-unstable for easier review by running the following commands from a nixpkgs clone. + ```ShellSession $ git fetch origin nixos-unstable $ git fetch origin pull/PRNUMBER/head $ git rebase --onto nixos-unstable BASEBRANCH FETCH_HEAD ``` + - The first command fetches the nixos-unstable branch. - The second command fetches the pull request changes, `PRNUMBER` is the number at the end of the pull request title and `BASEBRANCH` the base branch of the pull request. - The third command rebases the pull request changes to the nixos-unstable branch. - The [nixpkgs-review](https://github.com/Mic92/nixpkgs-review) tool can be used to review a pull request content in a single command. `PRNUMBER` should be replaced by the number at the end of the pull request title. You can also provide the full github pull request url. + ```ShellSession $ nix-shell -p nixpkgs-review --run "nixpkgs-review pr PRNUMBER" ``` diff --git a/doc/contributing/submitting-changes.chapter.md b/doc/contributing/submitting-changes.chapter.md index 0a465020092..97b32c15df1 100644 --- a/doc/contributing/submitting-changes.chapter.md +++ b/doc/contributing/submitting-changes.chapter.md @@ -71,6 +71,7 @@ Security fixes are submitted in the same way as other changes and thus the same - If a new version fixing the vulnerability has been released, update the package; - If the security fix comes in the form of a patch and a CVE is available, then add the patch to the Nixpkgs tree, and apply it to the package. The name of the patch should be the CVE identifier, so e.g. `CVE-2019-13636.patch`; If a patch is fetched the name needs to be set as well, e.g.: + ```nix (fetchpatch { name = "CVE-2019-11068.patch"; @@ -89,7 +90,7 @@ There is currently no policy when to remove a package. Before removing a package, one should try to find a new maintainer or fix smaller issues first. -### Steps to remove a package from Nixpkgs +### Steps to remove a package from Nixpkgs {#steps-to-remove-a-package-from-nixpkgs} We use jbidwatcher as an example for a discontinued project here. @@ -100,6 +101,7 @@ We use jbidwatcher as an example for a discontinued project here. 1. Add an alias for the package name in `pkgs/top-level/aliases.nix` (There is also `pkgs/misc/vim-plugins/aliases.nix`. Package sets typically do not have aliases, so we can't add them there.) For example in this case: + ``` jbidwatcher = throw "jbidwatcher was discontinued in march 2021"; # added 2021-03-15 ``` diff --git a/doc/languages-frameworks/agda.section.md b/doc/languages-frameworks/agda.section.md index 1675fcb0a79..2b7c35f68d3 100644 --- a/doc/languages-frameworks/agda.section.md +++ b/doc/languages-frameworks/agda.section.md @@ -1,6 +1,6 @@ # Agda {#agda} -## How to use Agda +## How to use Agda {#how-to-use-agda} Agda is available as the [agda](https://search.nixos.org/packages?channel=unstable&show=agda&from=0&size=30&sort=relevance&query=agda) package. @@ -43,6 +43,7 @@ agda.withPackages (p: [ ``` You can also reference a GitHub repository + ```nix agda.withPackages (p: [ (p.standard-library.overrideAttrs (oldAttrs: { @@ -59,6 +60,7 @@ agda.withPackages (p: [ If you want to use a library not added to Nixpkgs, you can add a dependency to a local library by calling `agdaPackages.mkDerivation`. + ```nix agda.withPackages (p: [ (p.mkDerivation { @@ -92,20 +94,21 @@ See [Building Agda Packages](#building-agda-packages) for more information on `m Agda will not by default use these libraries. To tell Agda to use a library we have some options: * Call `agda` with the library flag: -```ShellSession -$ agda -l standard-library -i . MyFile.agda -``` + ```ShellSession + $ agda -l standard-library -i . MyFile.agda + ``` * Write a `my-library.agda-lib` file for the project you are working on which may look like: -``` -name: my-library -include: . -depend: standard-library -``` + ``` + name: my-library + include: . + depend: standard-library + ``` * Create the file `~/.agda/defaults` and add any libraries you want to use by default. More information can be found in the [official Agda documentation on library management](https://agda.readthedocs.io/en/v2.6.1/tools/package-system.html). -## Compiling Agda +## Compiling Agda {#compiling-agda} + Agda modules can be compiled using the GHC backend with the `--compile` flag. A version of `ghc` with `ieee754` is made available to the Agda program via the `--with-compiler` flag. This can be overridden by a different version of `ghc` as follows: @@ -116,7 +119,8 @@ agda.withPackages { } ``` -## Writing Agda packages +## Writing Agda packages {#writing-agda-packages} + To write a nix derivation for an Agda library, first check that the library has a `*.agda-lib` file. A derivation can then be written using `agdaPackages.mkDerivation`. This has similar arguments to `stdenv.mkDerivation` with the following additions: @@ -140,19 +144,21 @@ agdaPackages.mkDerivation { } ``` -### Building Agda packages +### Building Agda packages {#building-agda-packages} + The default build phase for `agdaPackages.mkDerivation` simply runs `agda` on the `Everything.agda` file. If something else is needed to build the package (e.g. `make`) then the `buildPhase` should be overridden. Additionally, a `preBuild` or `configurePhase` can be used if there are steps that need to be done prior to checking the `Everything.agda` file. `agda` and the Agda libraries contained in `buildInputs` are made available during the build phase. -### Installing Agda packages +### Installing Agda packages {#installing-agda-packages} + The default install phase copies Agda source files, Agda interface files (`*.agdai`) and `*.agda-lib` files to the output directory. This can be overridden. By default, Agda sources are files ending on `.agda`, or literate Agda files ending on `.lagda`, `.lagda.tex`, `.lagda.org`, `.lagda.md`, `.lagda.rst`. The list of recognised Agda source extensions can be extended by setting the `extraExtensions` config variable. -## Adding Agda packages to Nixpkgs +## Adding Agda packages to Nixpkgs {#adding-agda-packages-to-nixpkgs} To add an Agda package to `nixpkgs`, the derivation should be written to `pkgs/development/libraries/agda/${library-name}/` and an entry should be added to `pkgs/top-level/agda-packages.nix`. Here it is called in a scope with access to all other Agda libraries, so the top line of the `default.nix` can look like: @@ -182,6 +188,7 @@ mkDerivation { ''; } ``` + This library has a file called `.agda-lib`, and so we give an empty string to `libraryFile` as nothing precedes `.agda-lib` in the filename. This file contains `name: IAL-1.3`, and so we let `libraryName = "IAL-1.3"`. This library does not use an `Everything.agda` file and instead has a Makefile, so there is no need to set `everythingFile` and we set a custom `buildPhase`. When writing an Agda package it is essential to make sure that no `.agda-lib` file gets added to the store as a single file (for example by using `writeText`). This causes Agda to think that the nix store is a Agda library and it will attempt to write to it whenever it typechecks something. See [https://github.com/agda/agda/issues/4613](https://github.com/agda/agda/issues/4613). diff --git a/doc/languages-frameworks/android.section.md b/doc/languages-frameworks/android.section.md index e7dbbf6f8ec..28128ead663 100644 --- a/doc/languages-frameworks/android.section.md +++ b/doc/languages-frameworks/android.section.md @@ -3,8 +3,8 @@ The Android build environment provides three major features and a number of supporting features. -Deploying an Android SDK installation with plugins --------------------------------------------------- +## Deploying an Android SDK installation with plugins {#deploying-an-android-sdk-installation-with-plugins} + The first use case is deploying the SDK with a desired set of plugins or subsets of an SDK. @@ -136,8 +136,8 @@ in androidComposition.platform-tools ``` -Using predefined Android package compositions ---------------------------------------------- +## Using predefined Android package compositions {#using-predefined-android-package-compositions} + In addition to composing an Android package set manually, it is also possible to use a predefined composition that contains all basic packages for a specific Android version, such as version 9.0 (API-level 28). @@ -159,12 +159,13 @@ with import {}; androidenv.androidPkgs_9_0.platform-tools ``` -Building an Android application -------------------------------- +## Building an Android application {#building-an-android-application} + In addition to the SDK, it is also possible to build an Ant-based Android project and automatically deploy all the Android plugins that a project requires. + ```nix with import {}; @@ -199,8 +200,8 @@ to build Android apps. An Android APK gets exposed as a build product and can be installed on any Android device with a web browser by navigating to the build result page. -Spawning emulator instances ---------------------------- +## Spawning emulator instances {#spawning-emulator-instances} + For testing purposes, it can also be quite convenient to automatically generate scripts that spawn emulator instances with all desired configuration settings. @@ -241,8 +242,8 @@ androidenv.emulateApp { In addition to prebuilt APKs, you can also bind the APK parameter to a `buildApp {}` function invocation shown in the previous example. -Notes on environment variables in Android projects --------------------------------------------------- +## Notes on environment variables in Android projects {#notes-on-environment-variables-in-android-projects} + * `ANDROID_SDK_ROOT` should point to the Android SDK. In your Nix expressions, this should be `${androidComposition.androidsdk}/libexec/android-sdk`. Note that `ANDROID_HOME` is deprecated, but if you rely on tools that need it, you can export it too. @@ -300,8 +301,8 @@ This shell.nix includes a shell hook that overwrites local.properties with the c sdk.dir and ndk.dir values. This will ensure that the SDK and NDK directories will both be correct when you run Android Studio inside nix-shell. -Notes on improving build.gradle compatibility ---------------------------------------------- +## Notes on improving build.gradle compatibility {#notes-on-improving-build.gradle-compatibility} + Ensure that your buildToolsVersion and ndkVersion match what is declared in androidenv. If you are using cmake, make sure its declared version is correct too. @@ -321,8 +322,8 @@ android { ``` -Querying the available versions of each plugin ----------------------------------------------- +## Querying the available versions of each plugin {#querying-the-available-versions-of-each-plugin} + repo.json provides all the options in one file now. A shell script in the `pkgs/development/mobile/androidenv/` subdirectory can be used to retrieve all @@ -334,8 +335,8 @@ possible options: The above command-line instruction queries all package versions in repo.json. -Updating the generated expressions ----------------------------------- +## Updating the generated expressions {#updating-the-generated-expressions} + repo.json is generated from XML files that the Android Studio package manager uses. To update the expressions run the `generate.sh` script that is stored in the `pkgs/development/mobile/androidenv/` subdirectory: diff --git a/doc/languages-frameworks/beam.section.md b/doc/languages-frameworks/beam.section.md index 68e84d2f990..348f66d4279 100644 --- a/doc/languages-frameworks/beam.section.md +++ b/doc/languages-frameworks/beam.section.md @@ -4,9 +4,9 @@ In this document and related Nix expressions, we use the term, _BEAM_, to describe the environment. BEAM is the name of the Erlang Virtual Machine and, as far as we're concerned, from a packaging perspective, all languages that run on the BEAM are interchangeable. That which varies, like the build system, is transparent to users of any given BEAM package, so we make no distinction. -## Available versions and deprecations schedule +## Available versions and deprecations schedule {#available-versions-and-deprecations-schedule} -### Elixir +### Elixir {#elixir} nixpkgs follows the [official elixir deprecation schedule](https://hexdocs.pm/elixir/compatibility-and-deprecations.html) and keeps the last 5 released versions of Elixir available. @@ -68,7 +68,7 @@ Erlang.mk functions similarly to Rebar3, except we use `buildErlangMk` instead o `mixRelease` is used to make a release in the mix sense. Dependencies will need to be fetched with `fetchMixDeps` and passed to it. -#### mixRelease - Elixir Phoenix example +#### mixRelease - Elixir Phoenix example {#mixrelease---elixir-phoenix-example} Here is how your `default.nix` file would look. @@ -148,7 +148,7 @@ Setup will require the following steps: - you can now `nix-build .` - To run the release, set the `RELEASE_TMP` environment variable to a directory that your program has write access to. It will be used to store the BEAM settings. -#### Example of creating a service for an Elixir - Phoenix project +#### Example of creating a service for an Elixir - Phoenix project {#example-of-creating-a-service-for-an-elixir---phoenix-project} In order to create a service with your release, you could add a `service.nix` in your project with the following @@ -228,7 +228,7 @@ mkShell { } ``` -#### Elixir - Phoenix project +#### Elixir - Phoenix project {#elixir---phoenix-project} Here is an example `shell.nix`. diff --git a/doc/languages-frameworks/bower.section.md b/doc/languages-frameworks/bower.section.md index f408bd5b2c9..6226dc0702d 100644 --- a/doc/languages-frameworks/bower.section.md +++ b/doc/languages-frameworks/bower.section.md @@ -149,7 +149,7 @@ A few notes about [Full example — `default.nix`](#ex-buildBowerComponentsDefau ## Troubleshooting {#ssec-bower2nix-troubleshooting} -### ENOCACHE errors from buildBowerComponents +### ENOCACHE errors from buildBowerComponents {#enocache-errors-from-buildbowercomponents} This means that Bower was looking for a package version which doesn't exist in the generated `bower-packages.nix`. diff --git a/doc/languages-frameworks/coq.section.md b/doc/languages-frameworks/coq.section.md index 5964d46e2f8..0674c5a4702 100644 --- a/doc/languages-frameworks/coq.section.md +++ b/doc/languages-frameworks/coq.section.md @@ -1,6 +1,6 @@ # Coq and coq packages {#sec-language-coq} -## Coq derivation: `coq` +## Coq derivation: `coq` {#coq-derivation-coq} The Coq derivation is overridable through the `coq.override overrides`, where overrides is an attribute set which contains the arguments to override. We recommend overriding either of the following @@ -8,7 +8,7 @@ The Coq derivation is overridable through the `coq.override overrides`, where ov * `customOCamlPackage` (optional, defaults to `null`, which lets Coq choose a version automatically), which can be set to any of the ocaml packages attribute of `ocaml-ng` (such as `ocaml-ng.ocamlPackages_4_10` which is the default for Coq 8.11 for example). * `coq-version` (optional, defaults to the short version e.g. "8.10"), is a version number of the form "x.y" that indicates which Coq's version build behavior to mimic when using a source which is not a release. E.g. `coq.override { version = "d370a9d1328a4e1cdb9d02ee032f605a9d94ec7a"; coq-version = "8.10"; }`. -## Coq packages attribute sets: `coqPackages` +## Coq packages attribute sets: `coqPackages` {#coq-packages-attribute-sets-coqpackages} The recommended way of defining a derivation for a Coq library, is to use the `coqPackages.mkCoqDerivation` function, which is essentially a specialization of `mkDerivation` taking into account most of the specifics of Coq libraries. The following attributes are supported: diff --git a/doc/languages-frameworks/crystal.section.md b/doc/languages-frameworks/crystal.section.md index 74790132974..cbe31f9f0b2 100644 --- a/doc/languages-frameworks/crystal.section.md +++ b/doc/languages-frameworks/crystal.section.md @@ -1,10 +1,11 @@ # Crystal {#crystal} -## Building a Crystal package +## Building a Crystal package {#building-a-crystal-package} This section uses [Mint](https://github.com/mint-lang/mint) as an example for how to build a Crystal package. If the Crystal project has any dependencies, the first step is to get a `shards.nix` file encoding those. Get a copy of the project and go to its root directory such that its `shard.lock` file is in the current directory, then run `crystal2nix` in it + ```bash $ git clone https://github.com/mint-lang/mint $ cd mint @@ -15,6 +16,7 @@ $ nix-shell -p crystal2nix --run crystal2nix This should have generated a `shards.nix` file. Next create a Nix file for your derivation and use `pkgs.crystal.buildCrystalPackage` as follows: + ```nix with import {}; crystal.buildCrystalPackage rec { diff --git a/doc/languages-frameworks/dotnet.section.md b/doc/languages-frameworks/dotnet.section.md index 725ffd4becc..1bcb6e45210 100644 --- a/doc/languages-frameworks/dotnet.section.md +++ b/doc/languages-frameworks/dotnet.section.md @@ -1,6 +1,6 @@ -# Dotnet +# Dotnet {#dotnet} -## Local Development Workflow +## Local Development Workflow {#local-development-workflow} For local development, it's recommended to use nix-shell to create a dotnet environment: @@ -16,7 +16,7 @@ mkShell { } ``` -### Using many sdks in a workflow +### Using many sdks in a workflow {#using-many-sdks-in-a-workflow} It's very likely that more than one sdk will be needed on a given project. Dotnet provides several different frameworks (E.g dotnetcore, aspnetcore, etc.) as well as many versions for a given framework. Normally, dotnet is able to fetch a framework and install it relative to the executable. However, this would mean writing to the nix store in nixpkgs, which is read-only. To support the many-sdk use case, one can compose an environment using `dotnetCorePackages.combinePackages`: @@ -37,7 +37,7 @@ mkShell { This will produce a dotnet installation that has the dotnet 3.1, 3.0, and 2.1 sdk. The first sdk listed will have it's cli utility present in the resulting environment. Example info output: -```ShellSesssion +```ShellSession $ dotnet --info .NET Core SDK (reflecting any global.json): Version: 3.1.101 @@ -60,15 +60,15 @@ $ dotnet --info Microsoft.NETCore.App 3.1.1 [/nix/store/iiv98i2jdi226dgh4jzkkj2ww7f8jgpd-dotnet-core-combined/shared/Microsoft.NETCore.App] ``` -## dotnet-sdk vs dotnetCorePackages.sdk +## dotnet-sdk vs dotnetCorePackages.sdk {#dotnet-sdk-vs-dotnetcorepackages.sdk} The `dotnetCorePackages.sdk_X_Y` is preferred over the old dotnet-sdk as both major and minor version are very important for a dotnet environment. If a given minor version isn't present (or was changed), then this will likely break your ability to build a project. -## dotnetCorePackages.sdk vs dotnetCorePackages.net vs dotnetCorePackages.netcore vs dotnetCorePackages.aspnetcore +## dotnetCorePackages.sdk vs dotnetCorePackages.net vs dotnetCorePackages.netcore vs dotnetCorePackages.aspnetcore {#dotnetcorepackages.sdk-vs-dotnetcorepackages.net-vs-dotnetcorepackages.netcore-vs-dotnetcorepackages.aspnetcore} The `dotnetCorePackages.sdk` contains both a runtime and the full sdk of a given version. The `net`, `netcore` and `aspnetcore` packages are meant to serve as minimal runtimes to deploy alongside already built applications. For runtime versions >= .NET 5 `net` is used while `netcore` is used for older .NET Core runtime version. -## Packaging a Dotnet Application +## Packaging a Dotnet Application {#packaging-a-dotnet-application} Ideally, we would like to build against the sdk, then only have the dotnet runtime available in the runtime closure. diff --git a/doc/languages-frameworks/emscripten.section.md b/doc/languages-frameworks/emscripten.section.md index d391e038070..b3ddf0cedae 100644 --- a/doc/languages-frameworks/emscripten.section.md +++ b/doc/languages-frameworks/emscripten.section.md @@ -27,16 +27,14 @@ Modes of use of `emscripten`: * dev-shell for zlib implementation hacking: * `nix-shell -A emscriptenPackages.zlib` - -## Imperative usage +## Imperative usage {#imperative-usage} A few things to note: * `export EMCC_DEBUG=2` is nice for debugging * `~/.emscripten`, the build artifact cache sometimes creates issues and needs to be removed from time to time - -## Declarative usage +## Declarative usage {#declarative-usage} Let's see two different examples from `pkgs/top-level/emscripten-packages.nix`: @@ -50,7 +48,7 @@ A special requirement of the `pkgs.buildEmscriptenPackage` is the `doCheck = tru * Use `export EMCC_DEBUG=2` from within a emscriptenPackage's `phase` to get more detailed debug output what is going wrong. * ~/.emscripten cache is requiring us to set `HOME=$TMPDIR` in individual phases. This makes compilation slower but also makes it more deterministic. -### Usage 1: pkgs.zlib.override +### Usage 1: pkgs.zlib.override {#usage-1-pkgs.zlib.override} This example uses `zlib` from nixpkgs but instead of compiling **C** to **ELF** it compiles **C** to **JS** since we were using `pkgs.zlib.override` and changed stdenv to `pkgs.emscriptenStdenv`. A few adaptions and hacks were set in place to make it working. One advantage is that when `pkgs.zlib` is updated, it will automatically update this package as well. However, this can also be the downside... @@ -110,7 +108,7 @@ See the `zlib` example: ''; }); -### Usage 2: pkgs.buildEmscriptenPackage +### Usage 2: pkgs.buildEmscriptenPackage {#usage-2-pkgs.buildemscriptenpackage} This `xmlmirror` example features a emscriptenPackage which is defined completely from this context and no `pkgs.zlib.override` is used. @@ -165,7 +163,7 @@ This `xmlmirror` example features a emscriptenPackage which is defined completel ''; }; -### Declarative debugging +### Declarative debugging {#declarative-debugging} Use `nix-shell -I nixpkgs=/some/dir/nixpkgs -A emscriptenPackages.libz` and from there you can go trough the individual steps. This makes it easy to build a good `unit test` or list the files of the project. @@ -177,7 +175,7 @@ Use `nix-shell -I nixpkgs=/some/dir/nixpkgs -A emscriptenPackages.libz` and from 6. `buildPhase` 7. ... happy hacking... -## Summary +## Summary {#summary} Using this toolchain makes it easy to leverage `nix` from NixOS, MacOSX or even Windows (WSL+ubuntu+nix). This toolchain is reproducible, behaves like the rest of the packages from nixpkgs and contains a set of well working examples to learn and adapt from. diff --git a/doc/languages-frameworks/gnome.section.md b/doc/languages-frameworks/gnome.section.md index 732b529cc22..a1121efe3f0 100644 --- a/doc/languages-frameworks/gnome.section.md +++ b/doc/languages-frameworks/gnome.section.md @@ -84,7 +84,7 @@ For convenience, it also adds `dconf.lib` for a GIO module implementing a GSetti - []{#ssec-gnome-hooks-gobject-introspection} `gobject-introspection` setup hook populates `GI_TYPELIB_PATH` variable with `lib/girepository-1.0` directories of dependencies, which is then added to wrapper by `wrapGAppsHook`. It also adds `share` directories of dependencies to `XDG_DATA_DIRS`, which is intended to promote GIR files but it also [pollutes the closures](https://github.com/NixOS/nixpkgs/issues/32790) of packages using `wrapGAppsHook`. - ::: warning + ::: {.warning} The setup hook [currently](https://github.com/NixOS/nixpkgs/issues/56943) does not work in expressions with `strictDeps` enabled, like Python packages. In those cases, you will need to disable it with `strictDeps = false;`. ::: diff --git a/doc/languages-frameworks/go.section.md b/doc/languages-frameworks/go.section.md index f52570ac8cc..b20a8d0c354 100644 --- a/doc/languages-frameworks/go.section.md +++ b/doc/languages-frameworks/go.section.md @@ -44,7 +44,7 @@ pet = buildGoModule rec { The function `buildGoPackage` builds legacy Go programs, not supporting Go modules. -### Example for `buildGoPackage` +### Example for `buildGoPackage` {#example-for-buildgopackage} In the following is an example expression using buildGoPackage, the following arguments are of special significance to the function: @@ -140,4 +140,4 @@ Removes the pre-existing vendor directory. This should only be used if the depen ### `subPackages` {#var-go-subPackages} -Limits the builder from building child packages that have not been listed. If subPackages is not specified, all child packages will be built. +Limits the builder from building child packages that have not been listed. If `subPackages` is not specified, all child packages will be built. diff --git a/doc/languages-frameworks/idris.section.md b/doc/languages-frameworks/idris.section.md index 000e3627d70..ffdd706eb0b 100644 --- a/doc/languages-frameworks/idris.section.md +++ b/doc/languages-frameworks/idris.section.md @@ -1,10 +1,10 @@ # Idris {#idris} -## Installing Idris +## Installing Idris {#installing-idris} The easiest way to get a working idris version is to install the `idris` attribute: -```ShellSesssion +```ShellSession $ # On NixOS $ nix-env -i nixos.idris $ # On non-NixOS @@ -21,7 +21,7 @@ self: super: { And then: -```ShellSesssion +```ShellSession $ # On NixOS $ nix-env -iA nixos.myIdris $ # On non-NixOS @@ -29,7 +29,8 @@ $ nix-env -iA nixpkgs.myIdris ``` To see all available Idris packages: -```ShellSesssion + +```ShellSession $ # On NixOS $ nix-env -qaPA nixos.idrisPackages $ # On non-NixOS @@ -37,22 +38,23 @@ $ nix-env -qaPA nixpkgs.idrisPackages ``` Similarly, entering a `nix-shell`: -```ShellSesssion + +```ShellSession $ nix-shell -p 'idrisPackages.with-packages (with idrisPackages; [ contrib pruviloj ])' ``` -## Starting Idris with library support +## Starting Idris with library support {#starting-idris-with-library-support} To have access to these libraries in idris, call it with an argument `-p ` for each library: -```ShellSesssion +```ShellSession $ nix-shell -p 'idrisPackages.with-packages (with idrisPackages; [ contrib pruviloj ])' [nix-shell:~]$ idris -p contrib -p pruviloj ``` A listing of all available packages the Idris binary has access to is available via `--listlibs`: -```ShellSesssion +```ShellSession $ idris --listlibs 00prelude-idx.ibc pruviloj @@ -64,7 +66,7 @@ prelude 00contrib-idx.ibc ``` -## Building an Idris project with Nix +## Building an Idris project with Nix {#building-an-idris-project-with-nix} As an example of how a Nix expression for an Idris package can be created, here is the one for `idrisPackages.yaml`: @@ -105,7 +107,7 @@ build-idris-package { Assuming this file is saved as `yaml.nix`, it's buildable using -```ShellSesssion +```ShellSession $ nix-build -E '(import {}).idrisPackages.callPackage ./yaml.nix {}' ``` @@ -121,11 +123,11 @@ with import {}; in another file (say `default.nix`) to be able to build it with -```ShellSesssion +```ShellSession $ nix-build -A yaml ``` -## Passing options to `idris` commands +## Passing options to `idris` commands {#passing-options-to-idris-commands} The `build-idris-package` function provides also optional input values to set additional options for the used `idris` commands. diff --git a/doc/languages-frameworks/ios.section.md b/doc/languages-frameworks/ios.section.md index a162e8d19fd..04b013be12e 100644 --- a/doc/languages-frameworks/ios.section.md +++ b/doc/languages-frameworks/ios.section.md @@ -20,8 +20,8 @@ Hydra. The Xcode build environment implements a number of features. -Deploying a proxy component wrapper exposing Xcode --------------------------------------------------- +## Deploying a proxy component wrapper exposing Xcode {#deploying-a-proxy-component-wrapper-exposing-xcode} + The first use case is deploying a Nix package that provides symlinks to the Xcode installation on the host system. This package can be used as a build input to any build function implemented in the Nix expression language that requires @@ -55,8 +55,8 @@ lrwxr-xr-x 1 sander staff 61 1 jan 1970 xcodebuild -> /Applications/Xcode.a lrwxr-xr-x 1 sander staff 14 1 jan 1970 xcrun -> /usr/bin/xcrun ``` -Building an iOS application ---------------------------- +## Building an iOS application {#building-an-ios-application} + We can build an iOS app executable for the simulator, or an IPA/xcarchive file for release purposes, e.g. ad-hoc, enterprise or store installations, by executing the `xcodeenv.buildApp {}` function: @@ -99,6 +99,7 @@ xcodeenv.buildApp { ``` The above function takes a variety of parameters: + * The `name` and `src` parameters are mandatory and specify the name of the app and the location where the source code resides * `sdkVersion` specifies which version of the iOS SDK to use. @@ -151,8 +152,8 @@ the `xcodeenv.composeXcodeWrapper {}` function takes. For example, the `xcodeBaseDir` parameter can be overridden to refer to a different Xcode version. -Spawning simulator instances ----------------------------- +## Spawning simulator instances {#spawning-simulator-instances} + In addition to building iOS apps, we can also automatically spawn simulator instances: @@ -213,8 +214,8 @@ xcode.simulateApp { By providing the result of an `xcode.buildApp {}` function and configuring the app bundle id, the app gets deployed automatically and started. -Troubleshooting ---------------- +## Troubleshooting {#troubleshooting} + In some rare cases, it may happen that after a failure, changes are not picked up. Most likely, this is caused by a derived data cache that Xcode maintains. To wipe it you can run: diff --git a/doc/languages-frameworks/lua.section.md b/doc/languages-frameworks/lua.section.md index 5935cbd7bd5..ea893ce3a4a 100644 --- a/doc/languages-frameworks/lua.section.md +++ b/doc/languages-frameworks/lua.section.md @@ -1,8 +1,8 @@ -# User's Guide to Lua Infrastructure {#users-guide-to-lua-infrastructure} +# User’s Guide to Lua Infrastructure {#users-guide-to-lua-infrastructure} -## Using Lua +## Using Lua {#using-lua} -### Overview of Lua +### Overview of Lua {#overview-of-lua} Several versions of the Lua interpreter are available: luajit, lua 5.1, 5.2, 5.3. The attribute `lua` refers to the default interpreter, it is also possible to refer to specific versions, e.g. `lua5_2` refers to Lua 5.2. @@ -17,27 +17,31 @@ The main package set contains aliases to these package sets, e.g. `luaPackages` refers to `lua5_1.pkgs` and `lua52Packages` to `lua5_2.pkgs`. -### Installing Lua and packages +### Installing Lua and packages {#installing-lua-and-packages} -#### Lua environment defined in separate `.nix` file +#### Lua environment defined in separate `.nix` file {#lua-environment-defined-in-separate-.nix-file} Create a file, e.g. `build.nix`, with the following expression + ```nix with import {}; lua5_2.withPackages (ps: with ps; [ busted luafilesystem ]) ``` + and install it in your profile with + ```shell nix-env -if build.nix ``` Now you can use the Lua interpreter, as well as the extra packages (`busted`, `luafilesystem`) that you added to the environment. -#### Lua environment defined in `~/.config/nixpkgs/config.nix` +#### Lua environment defined in `~/.config/nixpkgs/config.nix` {#lua-environment-defined-in-.confignixpkgsconfig.nix} If you prefer to, you could also add the environment as a package override to the Nixpkgs set, e.g. using `config.nix`, + ```nix { # ... @@ -46,14 +50,16 @@ using `config.nix`, }; } ``` + and install it in your profile with + ```shell nix-env -iA nixpkgs.myLuaEnv ``` The environment is installed by referring to the attribute, and considering the `nixpkgs` channel was used. -#### Lua environment defined in `/etc/nixos/configuration.nix` +#### Lua environment defined in `/etc/nixos/configuration.nix` {#lua-environment-defined-in-etcnixosconfiguration.nix} For the sake of completeness, here's another example how to install the environment system-wide. @@ -66,7 +72,7 @@ For the sake of completeness, here's another example how to install the environm } ``` -### How to override a Lua package using overlays? +### How to override a Lua package using overlays? {#how-to-override-a-lua-package-using-overlays} Use the following overlay template: @@ -87,18 +93,22 @@ final: prev: } ``` -### Temporary Lua environment with `nix-shell` +### Temporary Lua environment with `nix-shell` {#temporary-lua-environment-with-nix-shell} There are two methods for loading a shell with Lua packages. The first and recommended method is to create an environment with `lua.buildEnv` or `lua.withPackages` and load that. E.g. + ```sh $ nix-shell -p 'lua.withPackages(ps: with ps; [ busted luafilesystem ])' ``` + opens a shell from which you can launch the interpreter + ```sh [nix-shell:~] lua ``` + The other method, which is not recommended, does not create an environment and requires you to list the packages directly, ```sh @@ -108,7 +118,7 @@ Again, it is possible to launch the interpreter from the shell. The Lua interpreter has the attribute `pkgs` which contains all Lua libraries for that specific interpreter. -## Developing with Lua +## Developing with Lua {#developing-with-lua} Now that you know how to get a working Lua environment with Nix, it is time to go forward and start actually developing with Lua. There are two ways to @@ -116,7 +126,7 @@ package lua software, either it is on luarocks and most of it can be taken care of by the luarocks2nix converter or the packaging has to be done manually. Let's present the luarocks way first and the manual one in a second time. -### Packaging a library on luarocks +### Packaging a library on luarocks {#packaging-a-library-on-luarocks} [Luarocks.org](www.luarocks.org) is the main repository of lua packages. The site proposes two types of packages, the rockspec and the src.rock @@ -135,10 +145,11 @@ You can try converting luarocks packages to nix packages with the command `nix-s Nix rely on luarocks to install lua packages, basically it runs: `luarocks make --deps-mode=none --tree $out` -#### Packaging a library manually +#### Packaging a library manually {#packaging-a-library-manually} You can develop your package as you usually would, just don't forget to wrap it within a `toLuaModule` call, for instance + ```nix mynewlib = toLuaModule ( stdenv.mkDerivation { ... }); ``` @@ -146,16 +157,15 @@ mynewlib = toLuaModule ( stdenv.mkDerivation { ... }); There is also the `buildLuaPackage` function that can be used when lua modules are not packaged for luarocks. You can see a few examples at `pkgs/top-level/lua-packages.nix`. -## Lua Reference +## Lua Reference {#lua-reference} -### Lua interpreters +### Lua interpreters {#lua-interpreters} Versions 5.1, 5.2 and 5.3 of the lua interpreter are available as respectively `lua5_1`, `lua5_2` and `lua5_3`. Luajit is available too. The Nix expressions for the interpreters can be found in `pkgs/development/interpreters/lua-5`. - -#### Attributes on lua interpreters packages +#### Attributes on lua interpreters packages {#attributes-on-lua-interpreters-packages} Each interpreter has the following attributes: @@ -164,8 +174,7 @@ Each interpreter has the following attributes: - `withPackages`. Simpler interface to `buildEnv`. - `pkgs`. Set of Lua packages for that specific interpreter. The package set can be modified by overriding the interpreter and passing `packageOverrides`. - -#### `buildLuarocksPackage` function +#### `buildLuarocksPackage` function {#buildluarockspackage-function} The `buildLuarocksPackage` function is implemented in `pkgs/development/interpreters/lua-5/build-lua-package.nix` The following is an example: @@ -205,16 +214,17 @@ install the package By default `meta.platforms` is set to the same value as the interpreter unless overridden otherwise. -#### `buildLuaApplication` function +#### `buildLuaApplication` function {#buildluaapplication-function} The `buildLuaApplication` function is practically the same as `buildLuaPackage`. The difference is that `buildLuaPackage` by default prefixes the names of the packages with the version of the interpreter. Because with an application we're not interested in multiple version the prefix is dropped. -#### lua.withPackages function +#### lua.withPackages function {#lua.withpackages-function} The `lua.withPackages` takes a function as an argument that is passed the set of lua packages and returns the list of packages to be included in the environment. Using the `withPackages` function, the previous example for the luafilesystem environment can be written like this: + ```nix with import {}; @@ -223,6 +233,7 @@ lua.withPackages (ps: [ps.luafilesystem]) `withPackages` passes the correct package set for the specific interpreter version as an argument to the function. In the above example, `ps` equals `luaPackages`. But you can also easily switch to using `lua5_2`: + ```nix with import {}; @@ -231,13 +242,12 @@ lua5_2.withPackages (ps: [ps.lua]) Now, `ps` is set to `lua52Packages`, matching the version of the interpreter. - -### Possible Todos +### Possible Todos {#possible-todos} * export/use version specific variables such as `LUA_PATH_5_2`/`LUAROCKS_CONFIG_5_2` * let luarocks check for dependencies via exporting the different rocktrees in temporary config -### Lua Contributing guidelines +### Lua Contributing guidelines {#lua-contributing-guidelines} Following rules should be respected: diff --git a/doc/languages-frameworks/maven.section.md b/doc/languages-frameworks/maven.section.md index d66931e808d..f53a6fa8ac2 100644 --- a/doc/languages-frameworks/maven.section.md +++ b/doc/languages-frameworks/maven.section.md @@ -43,9 +43,9 @@ public class Main { You find this demo project at https://github.com/fzakaria/nixos-maven-example -## Solving for dependencies +## Solving for dependencies {#solving-for-dependencies} -### buildMaven with NixOS/mvn2nix-maven-plugin +### buildMaven with NixOS/mvn2nix-maven-plugin {#buildmaven-with-nixosmvn2nix-maven-plugin} > ⚠️ Although `buildMaven` is the "blessed" way within nixpkgs, as of 2020, it hasn't seen much activity in quite a while. @@ -82,6 +82,7 @@ This file is then given to the `buildMaven` function, and it returns 2 attribute A simple derivation that runs through `mvn compile` & `mvn package` to build the JAR. You may use this as inspiration for more complicated derivations. Here is an [example](https://github.com/fzakaria/nixos-maven-example/blob/main/build-maven-repository.nix) of building the Maven repository + ```nix { pkgs ? import { } }: with pkgs; @@ -103,7 +104,8 @@ The benefit over the _double invocation_ as we will see below, is that the _/nix │   └── 4.1.3 │   ├── avalon-framework-4.1.3.jar -> /nix/store/iv5fp3955w3nq28ff9xfz86wvxbiw6n9-avalon-framework-4.1.3.jar ``` -### Double Invocation + +### Double Invocation {#double-invocation} > ⚠️ This pattern is the simplest but may cause unnecessary rebuilds due to the output hash changing. @@ -163,7 +165,7 @@ The build will fail, and tell you the expected `outputHash` to place. When you'v If your package uses _SNAPSHOT_ dependencies or _version ranges_; there is a strong likelihood that over-time your output hash will change since the resolved dependencies may change. Hence this method is less recommended then using `buildMaven`. -## Building a JAR +## Building a JAR {#building-a-jar} Regardless of which strategy is chosen above, the step to build the derivation is the same. @@ -201,7 +203,7 @@ in stdenv.mkDerivation rec { 2 directories, 1 file ``` -## Runnable JAR +## Runnable JAR {#runnable-jar} The previous example builds a `jar` file but that's not a file one can run. @@ -213,7 +215,7 @@ We will use the same repository we built above (either _double invocation_ or _b The following two methods are more suited to Nix then building an [UberJar](https://imagej.net/Uber-JAR) which may be the more traditional approach. -### CLASSPATH +### CLASSPATH {#classpath} > This is ideal if you are providing a derivation for _nixpkgs_ and don't want to patch the project's `pom.xml`. @@ -252,11 +254,12 @@ in stdenv.mkDerivation rec { } ``` -### MANIFEST file via Maven Plugin +### MANIFEST file via Maven Plugin {#manifest-file-via-maven-plugin} > This is ideal if you are the project owner and want to change your `pom.xml` to set the CLASSPATH within it. Augment the `pom.xml` to create a JAR with the following manifest: + ```xml diff --git a/doc/languages-frameworks/python.section.md b/doc/languages-frameworks/python.section.md index feefefeabb7..54face47d1e 100644 --- a/doc/languages-frameworks/python.section.md +++ b/doc/languages-frameworks/python.section.md @@ -1,10 +1,10 @@ # Python {#python} -## User Guide +## User Guide {#user-guide} -### Using Python +### Using Python {#using-python} -#### Overview +#### Overview {#overview} Several versions of the Python interpreter are available on Nix, as well as a high amount of packages. The attribute `python3` refers to the default @@ -31,7 +31,7 @@ The main package set contains aliases to these package sets, e.g. `pythonPackages` refers to `python.pkgs` and `python38Packages` to `python38.pkgs`. -#### Installing Python and packages +#### Installing Python and packages {#installing-python-and-packages} The Nix and NixOS manuals explain how packages are generally installed. In the case of Python and Nix, it is important to make a distinction between whether the @@ -62,7 +62,7 @@ Philosphically, this should be familiar to users who are used to a `venv` style of development: individual projects create their own Python environments without impacting the global environment or each other. -#### Ad-hoc temporary Python environment with `nix-shell` +#### Ad-hoc temporary Python environment with `nix-shell` {#ad-hoc-temporary-python-environment-with-nix-shell} The simplest way to start playing with the way nix wraps and sets up Python environments is with `nix-shell` at the cmdline. These environments create a @@ -131,7 +131,7 @@ arbitrary dependencies. This is a good way to get a feel for how the Python interpreter and dependencies work in Nix and NixOS, but to do some actual development, we'll want to make it a bit more persistent. -##### Running Python scripts and using `nix-shell` as shebang +##### Running Python scripts and using `nix-shell` as shebang {#running-python-scripts-and-using-nix-shell-as-shebang} Sometimes, we have a script whose header looks like this: @@ -146,7 +146,7 @@ print(f"The dot product of {a} and {b} is: {np.dot(a, b)}") Executing this script requires a `python3` that has `numpy`. Using what we learned in the previous section, we could startup a shell and just run it like so: -```ShellSesssion +```ShellSession $ nix-shell -p 'python38.withPackages(ps: with ps; [ numpy ])' --run 'python3 foo.py' The dot product of [1 2] and [3 4] is: 11 ``` @@ -203,7 +203,7 @@ of the package versions. This is also a great way to ensure the script executes identically on different servers. -##### Load environment from `.nix` expression +##### Load environment from `.nix` expression {#load-environment-from-.nix-expression} We've now seen how to create an ad-hoc temporary shell session, and how to create a single script with Python dependencies, but in the course of normal @@ -262,7 +262,7 @@ and its Python dependencies, but also tools like `black` or `mypy` and libraries like `libffi` the `openssl` in scope. This is generic and can span any number of tools or languages across the Nixpkgs ecosystem. -##### Installing environments globally on the system +##### Installing environments globally on the system {#installing-environments-globally-on-the-system} Up to now, we've been creating environments scoped to an ad-hoc shell session, or a single script, or a single project. This is generally advisable, as it @@ -315,7 +315,7 @@ If you get a conflict or prefer to keep the setup clean, you can have `nix-env` atomically *uninstall* all other imperatively installed packages and replace your profile with just `myEnv` by using the `--replace` flag. -##### Environment defined in `/etc/nixos/configuration.nix` +##### Environment defined in `/etc/nixos/configuration.nix` {#environment-defined-in-etcnixosconfiguration.nix} For the sake of completeness, here's how to install the environment system-wide on NixOS. @@ -329,7 +329,7 @@ on NixOS. } ``` -### Developing with Python +### Developing with Python {#developing-with-python} Above, we were mostly just focused on use cases and what to do to get started creating working Python environments in nix. @@ -338,7 +338,7 @@ Now that you know the basics to be up and running, it is time to take a step back and take a deeper look at how Python packages are packaged on Nix. Then, we will look at how you can use development mode with your code. -#### Python library packages in Nixpkgs +#### Python library packages in Nixpkgs {#python-library-packages-in-nixpkgs} With Nix all packages are built by functions. The main function in Nix for building Python libraries is `buildPythonPackage`. Let's see how we can build the @@ -425,7 +425,7 @@ of `withPackages` we used a `let` expression. You can see that we used `toolz` from the Nixpkgs package set this time, but instead took our own version that we introduced with the `let` expression. -#### Handling dependencies +#### Handling dependencies {#handling-dependencies} Our example, `toolz`, does not have any dependencies on other Python packages or system libraries. According to the manual, `buildPythonPackage` uses the @@ -537,9 +537,10 @@ buildPythonPackage rec { }; } ``` + Note also the line `doCheck = false;`, we explicitly disabled running the test-suite. -#### Testing Python Packages +#### Testing Python Packages {#testing-python-packages} It is highly encouraged to have testing as part of the package build. This helps to avoid situations where the package was able to build and install, @@ -559,10 +560,11 @@ thus can cause issues when a test suite asserts on that behavior. as many tests should be enabled as possible. Failing tests can still be a good indication that the package is not in a valid state. -#### Using pytest +#### Using pytest {#using-pytest} Pytest is the most common test runner for python repositories. A trivial test run would be: + ``` checkInputs = [ pytest ]; checkPhase = "pytest"; @@ -572,6 +574,7 @@ However, many repositories' test suites do not translate well to nix's build sandbox, and will generally need many tests to be disabled. To filter tests using pytest, one can do the following: + ``` checkInputs = [ pytest ]; # avoid tests which need additional data or touch network @@ -587,19 +590,20 @@ easier than having to create a new package. `-k` is used to define a predicate for test names. In this example, we are filtering out tests which contain `download` or `update` in their test case name. -Only one `-k` argument is allows, and thus a long predicate should be concatenated -with "\" and wrapped to the next line. +Only one `-k` argument is allowed, and thus a long predicate should be concatenated +with “\\” and wrapped to the next line. -*NOTE:* In pytest==6.0.1, the use of "\" to continue a line (e.g. `-k 'not download \'`) has +*NOTE:* In pytest==6.0.1, the use of “\\” to continue a line (e.g. `-k 'not download \'`) has been removed, in this case, it's recommended to use `pytestCheckHook`. -#### Using pytestCheckHook +#### Using pytestCheckHook {#using-pytestcheckhook} `pytestCheckHook` is a convenient hook which will substitute the setuptools `test` command for a checkPhase which runs `pytest`. This is also beneficial when a package may need many items disabled to run the test suite. Using the example above, the analagous pytestCheckHook usage would be: + ``` checkInputs = [ pytestCheckHook ]; @@ -637,7 +641,7 @@ Trying to concatenate the related strings to disable tests in a regular checkPha would be much harder to read. This also enables us to comment on why specific tests are disabled. -#### Using pythonImportsCheck +#### Using pythonImportsCheck {#using-pythonimportscheck} Although unit tests are highly prefered to validate correctness of a package, not all packages have test suites that can be ran easily, and some have none at all. @@ -659,7 +663,7 @@ However, this is done in it's own phase, and not dependent on whether `doCheck = This can also be useful in verifying that the package doesn't assume commonly present packages (e.g. `setuptools`) -### Develop local package +### Develop local package {#develop-local-package} As a Python developer you're likely aware of [development mode](http://setuptools.readthedocs.io/en/latest/setuptools.html#development-mode) (`python setup.py develop`); instead of installing the package this command @@ -694,7 +698,7 @@ buildPythonPackage rec { It is important to note that due to how development mode is implemented on Nix it is not possible to have multiple packages simultaneously in development mode. -### Organising your packages +### Organising your packages {#organising-your-packages} So far we discussed how you can use Python on Nix, and how you can develop with it. We've looked at how you write expressions to package Python packages, and we @@ -706,7 +710,7 @@ like to be able to use in different projects. In order to minimise unnecessary duplication we now look at how you can maintain a repository with your own packages. The important functions here are `import` and `callPackage`. -### Including a derivation using `callPackage` +### Including a derivation using `callPackage` {#including-a-derivation-using-callpackage} Earlier we created a Python environment using `withPackages`, and included the `toolz` package via a `let` expression. @@ -756,9 +760,9 @@ don't explicitly define which `python` derivation should be used. In the above example we use `buildPythonPackage` that is part of the set `python38Packages`, and in this case the `python38` interpreter is automatically used. -## Reference +## Reference {#reference} -### Interpreters +### Interpreters {#interpreters} Versions 2.7, 3.6, 3.7, 3.8 and 3.9 of the CPython interpreter are available as respectively `python27`, `python36`, `python37`, `python38` and `python39`. The @@ -773,11 +777,11 @@ All packages depending on any Python interpreter get appended `out/{python.sitePackages}` to `$PYTHONPATH` if such directory exists. -#### Missing `tkinter` module standard library +#### Missing `tkinter` module standard library {#missing-tkinter-module-standard-library} To reduce closure size the `Tkinter`/`tkinter` is available as a separate package, `pythonPackages.tkinter`. -#### Attributes on interpreters packages +#### Attributes on interpreters packages {#attributes-on-interpreters-packages} Each interpreter has the following attributes: @@ -789,7 +793,7 @@ Each interpreter has the following attributes: - `executable`. Name of the interpreter executable, e.g. `python3.8`. - `pkgs`. Set of Python packages for that specific interpreter. The package set can be modified by overriding the interpreter and passing `packageOverrides`. -### Optimizations +### Optimizations {#optimizations} The Python interpreters are by default not build with optimizations enabled, because the builds are in that case not reproducible. To enable optimizations, override the @@ -806,7 +810,7 @@ let in mypython ``` -### Building packages and applications +### Building packages and applications {#building-packages-and-applications} Python libraries and applications that use `setuptools` or `distutils` are typically built with respectively the `buildPythonPackage` and @@ -838,7 +842,7 @@ and the aliases * `pkgs.python3Packages` pointing to `pkgs.python38Packages` * `pkgs.pythonPackages` pointing to `pkgs.python2Packages` -#### `buildPythonPackage` function +#### `buildPythonPackage` function {#buildpythonpackage-function} The `buildPythonPackage` function is implemented in `pkgs/development/interpreters/python/mk-python-derivation` @@ -890,7 +894,7 @@ e.g. the test runner, should be added to `checkInputs`. By default `meta.platforms` is set to the same value as the interpreter unless overridden otherwise. -##### `buildPythonPackage` parameters +##### `buildPythonPackage` parameters {#buildpythonpackage-parameters} All parameters from `stdenv.mkDerivation` function are still supported. The following are specific to `buildPythonPackage`: @@ -946,7 +950,7 @@ because their behaviour is different: `buildPythonPackage` also injects code into and wraps executables with the paths included in this list. Items listed in `install_requires` go here. -##### Overriding Python packages +##### Overriding Python packages {#overriding-python-packages} The `buildPythonPackage` function has a `overridePythonAttrs` method that can be used to override the package. In the following example we create an environment @@ -974,7 +978,7 @@ with import {}; in python.withPackages(ps: [ps.blaze])).env ``` -#### `buildPythonApplication` function +#### `buildPythonApplication` function {#buildpythonapplication-function} The `buildPythonApplication` function is practically the same as `buildPythonPackage`. The main purpose of this function is to build a Python @@ -1019,7 +1023,7 @@ luigi = callPackage ../applications/networking/cluster/luigi { }; Since the package is an application, a consumer doesn't need to care about Python versions or modules, which is why they don't go in `pythonPackages`. -#### `toPythonApplication` function +#### `toPythonApplication` function {#topythonapplication-function} A distinction is made between applications and libraries, however, sometimes a package is used as both. In this case the package is added as a library to @@ -1031,11 +1035,12 @@ The Nix expression shall use `buildPythonPackage` and be called from `python-packages.nix`. A reference shall be created from `all-packages.nix` to the attribute in `python-packages.nix`, and the `toPythonApplication` shall be applied to the reference: + ```nix youtube-dl = with pythonPackages; toPythonApplication youtube-dl; ``` -#### `toPythonModule` function +#### `toPythonModule` function {#topythonmodule-function} In some cases, such as bindings, a package is created using `stdenv.mkDerivation` and added as attribute in `all-packages.nix`. The Python @@ -1052,7 +1057,7 @@ opencv = toPythonModule (pkgs.opencv.override { Do pay attention to passing in the right Python version! -#### `python.buildEnv` function +#### `python.buildEnv` function {#python.buildenv-function} Python environments can be created using the low-level `pkgs.buildEnv` function. This example shows how to create an environment that has the Pyramid Web Framework. @@ -1090,8 +1095,8 @@ with import {}; will drop you into a shell where Python will have the specified packages in its path. +##### `python.buildEnv` arguments {#python.buildenv-arguments} -##### `python.buildEnv` arguments * `extraLibs`: List of packages installed inside the environment. * `postBuild`: Shell command executed after the build of environment. @@ -1099,7 +1104,7 @@ specified packages in its path. * `permitUserSite`: Skip setting the `PYTHONNOUSERSITE` environment variable in wrapped binaries in the environment. -#### `python.withPackages` function +#### `python.withPackages` function {#python.withpackages-function} The `python.withPackages` function provides a simpler interface to the `python.buildEnv` functionality. It takes a function as an argument that is passed the set of python packages and returns the list @@ -1141,7 +1146,7 @@ need them, you have to use `python.buildEnv`. Python 2 namespace packages may provide `__init__.py` that collide. In that case `python.buildEnv` should be used with `ignoreCollisions = true`. -#### Setup hooks +#### Setup hooks {#setup-hooks} The following are setup hooks specifically for Python packages. Most of these are used in `buildPythonPackage`. @@ -1166,7 +1171,7 @@ are used in `buildPythonPackage`. - `wheelUnpackHook` to move a wheel to the correct folder so it can be installed with the `pipInstallHook`. -### Development mode +### Development mode {#development-mode} Development or editable mode is supported. To develop Python packages `buildPythonPackage` has additional logic inside `shellPhase` to run `pip @@ -1175,6 +1180,7 @@ install -e . --prefix $TMPDIR/`for the package. Warning: `shellPhase` is executed only if `setup.py` exists. Given a `default.nix`: + ```nix with import {}; @@ -1197,7 +1203,7 @@ nix-shell -p pythonPackages.pyramid zlib libjpeg git Note: There is a boolean value `lib.inNixShell` set to `true` if nix-shell is invoked. -### Tools +### Tools {#tools} Packages inside nixpkgs are written by hand. However many tools exist in community to help save time. No tool is preferred at the moment. @@ -1209,7 +1215,7 @@ community to help save time. No tool is preferred at the moment. - [nixpkgs-pytools](https://github.com/nix-community/nixpkgs-pytools) - [poetry2nix](https://github.com/nix-community/poetry2nix) -### Deterministic builds +### Deterministic builds {#deterministic-builds} The Python interpreters are now built deterministically. Minor modifications had to be made to the interpreters in order to generate deterministic bytecode. This @@ -1221,7 +1227,7 @@ have timestamp 1. The `buildPythonPackage` function sets `DETERMINISTIC_BUILD=1` and [PYTHONHASHSEED=0](https://docs.python.org/3.8/using/cmdline.html#envvar-PYTHONHASHSEED). Both are also exported in `nix-shell`. -### Automatic tests +### Automatic tests {#automatic-tests} It is recommended to test packages as part of the build process. Source distributions (`sdist`) often include test files, but not always. @@ -1230,7 +1236,7 @@ By default the command `python setup.py test` is run as part of the `checkPhase`, but often it is necessary to pass a custom `checkPhase`. An example of such a situation is when `py.test` is used. -#### Common issues +#### Common issues {#common-issues} * Non-working tests can often be deselected. By default `buildPythonPackage` runs `python setup.py test`. Most Python modules follows the standard test @@ -1247,18 +1253,19 @@ example of such a situation is when `py.test` is used. ''; } ``` + * Tests that attempt to access `$HOME` can be fixed by using the following work-around before running tests (e.g. `preCheck`): `export HOME=$(mktemp -d)` -## FAQ +## FAQ {#faq} -### How to solve circular dependencies? +### How to solve circular dependencies? {#how-to-solve-circular-dependencies} Consider the packages `A` and `B` that depend on each other. When packaging `B`, a solution is to override package `A` not to depend on `B` as an input. The same should also be done when packaging `A`. -### How to override a Python package? +### How to override a Python package? {#how-to-override-a-python-package} We can override the interpreter and pass `packageOverrides`. In the following example we rename the `pandas` package and build it. @@ -1316,7 +1323,7 @@ let in newpkgs.inkscape ``` -### `python setup.py bdist_wheel` cannot create .whl +### `python setup.py bdist_wheel` cannot create .whl {#python-setup.py-bdist_wheel-cannot-create-.whl} Executing `python setup.py bdist_wheel` in a `nix-shell `fails with ``` @@ -1349,7 +1356,7 @@ or unset `SOURCE_DATE_EPOCH`: nix-shell --run "unset SOURCE_DATE_EPOCH; python3 setup.py bdist_wheel" ``` -### `install_data` / `data_files` problems +### `install_data` / `data_files` problems {#install_data-data_files-problems} If you get the following error: @@ -1369,7 +1376,7 @@ ${python.interpreter} setup.py install_data --install-dir=$out --root=$out sed -i '/ = data\_files/d' setup.py ``` -### Rationale of non-existent global site-packages +### Rationale of non-existent global site-packages {#rationale-of-non-existent-global-site-packages} On most operating systems a global `site-packages` is maintained. This however becomes problematic if you want to run multiple Python versions or have multiple @@ -1384,7 +1391,7 @@ If you want to create a Python environment for development, then the recommended method is to use `nix-shell`, either with or without the `python.buildEnv` function. -### How to consume Python modules using pip in a virtual environment like I am used to on other Operating Systems? +### How to consume Python modules using pip in a virtual environment like I am used to on other Operating Systems? {#how-to-consume-python-modules-using-pip-in-a-virtual-environment-like-i-am-used-to-on-other-operating-systems} While this approach is not very idiomatic from Nix perspective, it can still be useful when dealing with pre-existing projects or in situations where it's not @@ -1497,7 +1504,7 @@ is executed it will attempt to download the Python modules listed in requirements.txt. However these will be cached locally within the `virtualenv` folder and not downloaded again. -### How to override a Python package from `configuration.nix`? +### How to override a Python package from `configuration.nix`? {#how-to-override-a-python-package-from-configuration.nix} If you need to change a package's attribute(s) from `configuration.nix` you could do: @@ -1535,7 +1542,7 @@ this snippet: } ``` -### How to override a Python package using overlays? +### How to override a Python package using overlays? {#how-to-override-a-python-package-using-overlays} Use the following overlay template: @@ -1556,12 +1563,12 @@ self: super: { } ``` -### How to use Intel's MKL with numpy and scipy? +### How to use Intel’s MKL with numpy and scipy? {#how-to-use-intels-mkl-with-numpy-and-scipy} MKL can be configured using an overlay. See the section "[Using overlays to configure alternatives](#sec-overlays-alternatives-blas-lapack)". -### What inputs do `setup_requires`, `install_requires` and `tests_require` map to? +### What inputs do `setup_requires`, `install_requires` and `tests_require` map to? {#what-inputs-do-setup_requires-install_requires-and-tests_require-map-to} In a `setup.py` or `setup.cfg` it is common to declare dependencies: @@ -1569,9 +1576,9 @@ In a `setup.py` or `setup.cfg` it is common to declare dependencies: * `install_requires` corresponds to `propagatedBuildInputs` * `tests_require` corresponds to `checkInputs` -## Contributing +## Contributing {#contributing} -### Contributing guidelines +### Contributing guidelines {#contributing-guidelines} The following rules are desired to be respected: diff --git a/doc/languages-frameworks/qt.section.md b/doc/languages-frameworks/qt.section.md index 6f8c9626e6d..986deeb0d4b 100644 --- a/doc/languages-frameworks/qt.section.md +++ b/doc/languages-frameworks/qt.section.md @@ -90,19 +90,21 @@ stdenv.mkDerivation { } ``` -::: note +::: {.note} `wrapQtAppsHook` ignores files that are non-ELF executables. This means that scripts won't be automatically wrapped so you'll need to manually wrap them as previously mentioned. An example of when you'd always need to do this is with Python applications that use PyQt. ::: -## Adding a library to Nixpkgs +## Adding a library to Nixpkgs {#adding-a-library-to-nixpkgs} + Add Qt libraries to `qt5-packages.nix` to make them available for every supported Qt version. ### Example adding a Qt library {#qt-library-all-packages-nix} The following represents the contents of `qt5-packages.nix`. + ```nix { # ... @@ -126,13 +128,15 @@ stdenv.mkDerivation { } ``` -## Adding an application to Nixpkgs +## Adding an application to Nixpkgs {#adding-an-application-to-nixpkgs} + Add Qt applications to `qt5-packages.nix`. Add an alias to `all-packages.nix` to select the Qt 5 version used for the application. ### Example adding a Qt application {#qt-application-all-packages-nix} The following represents the contents of `qt5-packages.nix`. + ```nix { # ... @@ -144,6 +148,7 @@ The following represents the contents of `qt5-packages.nix`. ``` The following represents the contents of `all-packages.nix`. + ```nix { # ... diff --git a/doc/languages-frameworks/r.section.md b/doc/languages-frameworks/r.section.md index c420d112c91..56e3da64df2 100644 --- a/doc/languages-frameworks/r.section.md +++ b/doc/languages-frameworks/r.section.md @@ -1,6 +1,6 @@ # R {#r} -## Installation +## Installation {#installation} Define an environment for R that contains all the libraries that you'd like to use by adding the following snippet to your $HOME/.config/nixpkgs/config.nix file: @@ -31,6 +31,7 @@ output is the name that has to be passed to rWrapper in the code snipped above. However, if you'd like to add a file to your project source to make the environment available for other contributors, you can create a `default.nix` file like so: + ```nix with import {}; { @@ -50,7 +51,7 @@ with import {}; and then run `nix-shell .` to be dropped into a shell with those packages available. -## RStudio +## RStudio {#rstudio} RStudio uses a standard set of packages and ignores any custom R environments or installed packages you may have. To create a custom @@ -93,7 +94,7 @@ Executing `nix-shell` will then drop you into an environment equivalent to the one above. If you need additional packages just add them to the list and re-enter the shell. -## Updating the package set +## Updating the package set {#updating-the-package-set} ```bash nix-shell generate-shell.nix @@ -113,8 +114,7 @@ mv bioc-experiment-packages.nix.new bioc-experiment-packages.nix `generate-r-packages.R ` reads `-packages.nix`, therefor the renaming. - -## Testing if the Nix-expression could be evaluated +## Testing if the Nix-expression could be evaluated {#testing-if-the-nix-expression-could-be-evaluated} ```bash nix-build test-evaluation.nix --dry-run diff --git a/doc/languages-frameworks/ruby.section.md b/doc/languages-frameworks/ruby.section.md index b8fc19eb6b0..36b794458cb 100644 --- a/doc/languages-frameworks/ruby.section.md +++ b/doc/languages-frameworks/ruby.section.md @@ -1,6 +1,6 @@ # Ruby {#sec-language-ruby} -## Using Ruby +## Using Ruby {#using-ruby} Several versions of Ruby interpreters are available on Nix, as well as over 250 gems and many applications written in Ruby. The attribute `ruby` refers to the default Ruby interpreter, which is currently MRI 2.6. It's also possible to refer to specific versions, e.g. `ruby_2_y`, `jruby`, or `mruby`. @@ -12,7 +12,7 @@ The interpreters have common attributes, namely `gems`, and `withPackages`. So y Since not all gems have executables like `nokogiri`, it's usually more convenient to use the `withPackages` function like this: `ruby.withPackages (p: with p; [ nokogiri ])`. This will also make sure that the Ruby in your environment will be able to find the gem and it can be used in your Ruby code (for example via `ruby` or `irb` executables) via `require "nokogiri"` as usual. -### Temporary Ruby environment with `nix-shell` +### Temporary Ruby environment with `nix-shell` {#temporary-ruby-environment-with-nix-shell} Rather than having a single Ruby environment shared by all Ruby development projects on a system, Nix allows you to create separate environments per project. `nix-shell` gives you the possibility to temporarily load another environment akin to a combined `chruby` or `rvm` and `bundle exec`. @@ -30,7 +30,7 @@ $ nix-shell -p ruby.gems.nokogiri ruby.gems.pry Again, it's possible to launch the interpreter from the shell. The Ruby interpreter has the attribute `gems` which contains all Ruby gems for that specific interpreter. -#### Load Ruby environment from `.nix` expression +#### Load Ruby environment from `.nix` expression {#load-ruby-environment-from-.nix-expression} As explained in the Nix manual, `nix-shell` can also load an expression from a `.nix` file. Say we want to have Ruby 2.6, `nokogori`, and `pry`. Consider a `shell.nix` file with: @@ -45,7 +45,7 @@ What's happening here? 2. Then we create a Ruby environment with the `withPackages` function. 3. The `withPackages` function expects us to provide a function as an argument that takes the set of all ruby gems and returns a list of packages to include in the environment. Here, we select the packages `nokogiri` and `pry` from the package set. -#### Execute command with `--run` +#### Execute command with `--run` {#execute-command-with---run} A convenient flag for `nix-shell` is `--run`. It executes a command in the `nix-shell`. We can e.g. directly open a `pry` REPL: @@ -65,7 +65,7 @@ Or run a script using this environment: $ nix-shell -p "ruby.withPackages (ps: with ps; [ nokogiri pry ])" --run "ruby example.rb" ``` -#### Using `nix-shell` as shebang +#### Using `nix-shell` as shebang {#using-nix-shell-as-shebang} In fact, for the last case, there is a more convenient method. You can add a [shebang]() to your script specifying which dependencies `nix-shell` needs. With the following shebang, you can just execute `./example.rb`, and it will run with all dependencies. @@ -80,9 +80,9 @@ body = RestClient.get('http://example.com').body puts Nokogiri::HTML(body).at('h1').text ``` -## Developing with Ruby +## Developing with Ruby {#developing-with-ruby} -### Using an existing Gemfile +### Using an existing Gemfile {#using-an-existing-gemfile} In most cases, you'll already have a `Gemfile.lock` listing all your dependencies. This can be used to generate a `gemset.nix` which is used to fetch the gems and combine them into a single environment. The reason why you need to have a separate file for this, is that Nix requires you to have a checksum for each input to your build. Since the `Gemfile.lock` that `bundler` generates doesn't provide us with checksums, we have to first download each gem, calculate its SHA256, and store it in this separate file. @@ -120,7 +120,7 @@ One common issue that you might have is that you have Ruby 2.6, but also `bundle mkShell { buildInputs = [ gems (lowPrio gems.wrappedRuby) ]; } ``` -### Gem-specific configurations and workarounds +### Gem-specific configurations and workarounds {#gem-specific-configurations-and-workarounds} In some cases, especially if the gem has native extensions, you might need to modify the way the gem is built. @@ -201,7 +201,7 @@ $ nix-shell --run 'ruby -rpg -e "puts PG.library_version"' Of course for this use-case one could also use overlays since the configuration for `pg` depends on the `postgresql` alias, but for demonstration purposes this has to suffice. -### Adding a gem to the default gemset +### Adding a gem to the default gemset {#adding-a-gem-to-the-default-gemset} Now that you know how to get a working Ruby environment with Nix, it's time to go forward and start actually developing with Ruby. We will first have a look at how Ruby gems are packaged on Nix. Then, we will look at how you can use development mode with your code. @@ -215,7 +215,7 @@ To test that it works, you can then try using the gem with: NIX_PATH=nixpkgs=$PWD nix-shell -p "ruby.withPackages (ps: with ps; [ name-of-your-gem ])" ``` -### Packaging applications +### Packaging applications {#packaging-applications} A common task is to add a ruby executable to nixpkgs, popular examples would be `chef`, `jekyll`, or `sass`. A good way to do that is to use the `bundlerApp` function, that allows you to make a package that only exposes the listed executables, otherwise the package may cause conflicts through common paths like `bin/rake` or `bin/bundler` that aren't meant to be used. @@ -243,7 +243,7 @@ bundlerApp { All that's left to do is to generate the corresponding `Gemfile.lock` and `gemset.nix` as described above in the `Using an existing Gemfile` section. -#### Packaging executables that require wrapping +#### Packaging executables that require wrapping {#packaging-executables-that-require-wrapping} Sometimes your app will depend on other executables at runtime, and tries to find it through the `PATH` environment variable. diff --git a/doc/languages-frameworks/rust.section.md b/doc/languages-frameworks/rust.section.md index 5ff7a5edefd..f5c664bec20 100644 --- a/doc/languages-frameworks/rust.section.md +++ b/doc/languages-frameworks/rust.section.md @@ -15,7 +15,7 @@ For other versions such as daily builds (beta and nightly), use either `rustup` from nixpkgs (which will manage the rust installation in your home directory), or use Mozilla's [Rust nightlies overlay](#using-the-rust-nightlies-overlay). -## Compiling Rust applications with Cargo +## Compiling Rust applications with Cargo {#compiling-rust-applications-with-cargo} Rust applications are packaged by using the `buildRustPackage` helper from `rustPlatform`: @@ -107,7 +107,7 @@ rustPlatform.buildRustPackage rec { } ``` -### Importing a `Cargo.lock` file +### Importing a `Cargo.lock` file {#importing-a-cargo.lock-file} Using `cargoSha256` or `cargoHash` is tedious when using `buildRustPackage` within a project, since it requires that the hash @@ -156,7 +156,7 @@ added. To find the correct hash, you can first use `lib.fakeSha256` or `lib.fakeHash` as a stub hash. Building the package (and thus the vendored dependencies) will then inform you of the correct hash. -### Cross compilation +### Cross compilation {#cross-compilation} By default, Rust packages are compiled for the host platform, just like any other package is. The `--target` passed to rust tools is computed from this. @@ -168,6 +168,7 @@ where they are known to differ. But there are ways to customize the argument: name will be used instead. For example: + ```nix import { crossSystem = (import ).systems.examples.armhf-embedded // { @@ -175,7 +176,9 @@ where they are known to differ. But there are ways to customize the argument: }; } ``` + will result in: + ```shell --target thumbv7em-none-eabi ``` @@ -188,6 +191,7 @@ where they are known to differ. But there are ways to customize the argument: will be used instead. For example: + ```nix import { crossSystem = (import ).systems.examples.armhf-embedded // { @@ -196,7 +200,9 @@ where they are known to differ. But there are ways to customize the argument: }; } ``` + will result in: + ```shell --target /nix/store/asdfasdfsadf-thumb-crazy.json # contains {"foo":"","bar":""} ``` @@ -220,7 +226,7 @@ ad-hoc escape hatch to `buildRustPackage` can be removed. Note that currently custom targets aren't compiled with `std`, so `cargo test` will fail. This can be ignored by adding `doCheck = false;` to your derivation. -### Running package tests +### Running package tests {#running-package-tests} When using `buildRustPackage`, the `checkPhase` is enabled by default and runs `cargo test` on the package to build. To make sure that we don't compile the @@ -248,7 +254,7 @@ Another attribute, called `checkFlags`, is used to pass arguments to the test binary itself, as stated (here)[https://doc.rust-lang.org/cargo/commands/cargo-test.html]. -#### Tests relying on the structure of the `target/` directory +#### Tests relying on the structure of the `target/` directory {#tests-relying-on-the-structure-of-the-target-directory} Some tests may rely on the structure of the `target/` directory. Those tests are likely to fail because we use `cargo --target` during the build. This means that @@ -258,7 +264,7 @@ rather than in `target/release/`. This can only be worked around by patching the affected tests accordingly. -#### Disabling package-tests +#### Disabling package-tests {#disabling-package-tests} In some instances, it may be necessary to disable testing altogether (with `doCheck = false;`): @@ -272,7 +278,7 @@ The above are just guidelines, and exceptions may be granted on a case-by-case b However, please check if it's possible to disable a problematic subset of the test suite and leave a comment explaining your reasoning. -#### Setting `test-threads` +#### Setting `test-threads` {#setting-test-threads} `buildRustPackage` will use parallel test threads by default, sometimes it may be necessary to disable this so the tests run consecutively. @@ -284,7 +290,7 @@ rustPlatform.buildRustPackage { } ``` -### Building a package in `debug` mode +### Building a package in `debug` mode {#building-a-package-in-debug-mode} By default, `buildRustPackage` will use `release` mode for builds. If a package should be built in `debug` mode, it can be configured like so: @@ -298,14 +304,14 @@ rustPlatform.buildRustPackage { In this scenario, the `checkPhase` will be ran in `debug` mode as well. -### Custom `build`/`install`-procedures +### Custom `build`/`install`-procedures {#custom-buildinstall-procedures} Some packages may use custom scripts for building/installing, e.g. with a `Makefile`. In these cases, it's recommended to override the `buildPhase`/`installPhase`/`checkPhase`. Otherwise, some steps may fail because of the modified directory structure of `target/`. -### Building a crate with an absent or out-of-date Cargo.lock file +### Building a crate with an absent or out-of-date Cargo.lock file {#building-a-crate-with-an-absent-or-out-of-date-cargo.lock-file} `buildRustPackage` needs a `Cargo.lock` file to get all dependencies in the source code in a reproducible way. If it is missing or out-of-date one can use @@ -321,13 +327,13 @@ rustPlatform.buildRustPackage rec { } ``` -## Compiling non-Rust packages that include Rust code +## Compiling non-Rust packages that include Rust code {#compiling-non-rust-packages-that-include-rust-code} Several non-Rust packages incorporate Rust code for performance- or security-sensitive parts. `rustPlatform` exposes several functions and hooks that can be used to integrate Cargo in non-Rust packages. -### Vendoring of dependencies +### Vendoring of dependencies {#vendoring-of-dependencies} Since network access is not allowed in sandboxed builds, Rust crate dependencies need to be retrieved using a fetcher. `rustPlatform` @@ -387,7 +393,7 @@ added. To find the correct hash, you can first use `lib.fakeSha256` or `lib.fakeHash` as a stub hash. Building `cargoDeps` will then inform you of the correct hash. -### Hooks +### Hooks {#hooks} `rustPlatform` provides the following hooks to automate Cargo builds: @@ -416,9 +422,9 @@ you of the correct hash. * `cargoInstallHook`: install binaries and static/shared libraries that were built using `cargoBuildHook`. -### Examples +### Examples {#examples} -#### Python package using `setuptools-rust` +#### Python package using `setuptools-rust` {#python-package-using-setuptools-rust} For Python packages using `setuptools-rust`, you can use `fetchCargoTarball` and `cargoSetupHook` to retrieve and set up Cargo @@ -504,7 +510,7 @@ buildPythonPackage rec { } ``` -#### Python package using `maturin` +#### Python package using `maturin` {#python-package-using-maturin} Python packages that use [Maturin](https://github.com/PyO3/maturin) can be built with `fetchCargoTarball`, `cargoSetupHook`, and @@ -545,9 +551,9 @@ buildPythonPackage rec { } ``` -## Compiling Rust crates using Nix instead of Cargo +## Compiling Rust crates using Nix instead of Cargo {#compiling-rust-crates-using-nix-instead-of-cargo} -### Simple operation +### Simple operation {#simple-operation} When run, `cargo build` produces a file called `Cargo.lock`, containing pinned versions of all dependencies. Nixpkgs contains a @@ -558,14 +564,15 @@ That Nix expression calls `rustc` directly (hence bypassing Cargo), and can be used to compile a crate and all its dependencies. Here is an example for a minimal `hello` crate: - - $ cargo new hello - $ cd hello - $ cargo build +```ShellSession +$ cargo new hello +$ cd hello +$ cargo build Compiling hello v0.1.0 (file:///tmp/hello) - Finished dev [unoptimized + debuginfo] target(s) in 0.20 secs - $ carnix -o hello.nix --src ./. Cargo.lock --standalone - $ nix-build hello.nix -A hello_0_1_0 + Finished dev [unoptimized + debuginfo] target(s) in 0.20 secs +$ carnix -o hello.nix --src ./. Cargo.lock --standalone +$ nix-build hello.nix -A hello_0_1_0 +``` Now, the file produced by the call to `carnix`, called `hello.nix`, looks like: @@ -644,7 +651,7 @@ Here, the `libc` crate has no `src` attribute, so `buildRustCrate` will fetch it from [crates.io](https://crates.io). A `sha256` attribute is still needed for Nix purity. -### Handling external dependencies +### Handling external dependencies {#handling-external-dependencies} Some crates require external libraries. For crates from [crates.io](https://crates.io), such libraries can be specified in @@ -703,7 +710,7 @@ with import {}; } ``` -### Options and phases configuration +### Options and phases configuration {#options-and-phases-configuration} Actually, the overrides introduced in the previous section are more general. A number of other parameters can be overridden: @@ -750,7 +757,7 @@ general. A number of other parameters can be overridden: }; ``` -### Features +### Features {#features} One can also supply features switches. For example, if we want to compile `diesel_cli` only with the `postgres` feature, and no default @@ -765,14 +772,15 @@ features, we would write: Where `diesel.nix` is the file generated by Carnix, as explained above. +## Setting Up `nix-shell` {#setting-up-nix-shell} -## Setting Up `nix-shell` Oftentimes you want to develop code from within `nix-shell`. Unfortunately `buildRustCrate` does not support common `nix-shell` operations directly (see [this issue](https://github.com/NixOS/nixpkgs/issues/37945)) so we will use `stdenv.mkDerivation` instead. Using the example `hello` project above, we want to do the following: + - Have access to `cargo` and `rustc` - Have the `openssl` library available to a crate through it's _normal_ compilation mechanism (`pkg-config`). @@ -801,13 +809,15 @@ stdenv.mkDerivation { ``` You should now be able to run the following: -```ShellSesssion + +```ShellSession $ nix-shell --pure $ cargo build $ cargo test ``` -### Controlling Rust Version Inside `nix-shell` +### Controlling Rust Version Inside `nix-shell` {#controlling-rust-version-inside-nix-shell} + To control your rust version (i.e. use nightly) from within `shell.nix` (or other nix expressions) you can use the following `shell.nix` @@ -839,6 +849,7 @@ stdenv.mkDerivation { ``` Now run: + ```ShellSession $ rustc --version rustc 1.26.0-nightly (188e693b3 2018-03-26) @@ -846,31 +857,32 @@ rustc 1.26.0-nightly (188e693b3 2018-03-26) To see that you are using nightly. - -## Using the Rust nightlies overlay +## Using the Rust nightlies overlay {#using-the-rust-nightlies-overlay} Mozilla provides an overlay for nixpkgs to bring a nightly version of Rust into scope. This overlay can _also_ be used to install recent unstable or stable versions of Rust, if desired. -### Rust overlay installation +### Rust overlay installation {#rust-overlay-installation} You can use this overlay by either changing your local nixpkgs configuration, or by adding the overlay declaratively in a nix expression, e.g. in `configuration.nix`. -For more information see [#sec-overlays-install](the manual on installing overlays). +For more information see [the manual on installing overlays](#sec-overlays-install). -#### Imperative rust overlay installation +#### Imperative rust overlay installation {#imperative-rust-overlay-installation} Clone [nixpkgs-mozilla](https://github.com/mozilla/nixpkgs-mozilla), and create a symbolic link to the file [rust-overlay.nix](https://github.com/mozilla/nixpkgs-mozilla/blob/master/rust-overlay.nix) in the `~/.config/nixpkgs/overlays` directory. - $ git clone https://github.com/mozilla/nixpkgs-mozilla.git - $ mkdir -p ~/.config/nixpkgs/overlays - $ ln -s $(pwd)/nixpkgs-mozilla/rust-overlay.nix ~/.config/nixpkgs/overlays/rust-overlay.nix +```ShellSession +$ git clone https://github.com/mozilla/nixpkgs-mozilla.git +$ mkdir -p ~/.config/nixpkgs/overlays +$ ln -s $(pwd)/nixpkgs-mozilla/rust-overlay.nix ~/.config/nixpkgs/overlays/rust-overlay.nix +``` -### Declarative rust overlay installation +### Declarative rust overlay installation {#declarative-rust-overlay-installation} Add the following to your `configuration.nix`, `home-configuration.nix`, `shell.nix`, or similar: @@ -886,7 +898,7 @@ Add the following to your `configuration.nix`, `home-configuration.nix`, `shell. Note that this will fetch the latest overlay version when rebuilding your system. -### Rust overlay usage +### Rust overlay usage {#rust-overlay-usage} The overlay contains attribute sets corresponding to different versions of the rust toolchain, such as: @@ -900,11 +912,15 @@ For example, you might want to add `latest.rustChannels.stable.rust` to the list Imperatively, the latest stable version can be installed with the following command: - $ nix-env -Ai nixpkgs.latest.rustChannels.stable.rust +```ShellSession +$ nix-env -Ai nixpkgs.latest.rustChannels.stable.rust +``` Or using the attribute with nix-shell: - $ nix-shell -p nixpkgs.latest.rustChannels.stable.rust +```ShellSession +$ nix-shell -p nixpkgs.latest.rustChannels.stable.rust +``` Substitute the `nixpkgs` prefix with `nixos` on NixOS. To install the beta or nightly channel, "stable" should be substituted by diff --git a/doc/languages-frameworks/texlive.section.md b/doc/languages-frameworks/texlive.section.md index c3028731f4e..6b505cefcc9 100644 --- a/doc/languages-frameworks/texlive.section.md +++ b/doc/languages-frameworks/texlive.section.md @@ -5,6 +5,7 @@ Since release 15.09 there is a new TeX Live packaging that lives entirely under ## User's guide {#sec-language-texlive-user-guide} - For basic usage just pull `texlive.combined.scheme-basic` for an environment with basic LaTeX support. + - It typically won't work to use separately installed packages together. Instead, you can build a custom set of packages like this: ```nix @@ -14,6 +15,7 @@ Since release 15.09 there is a new TeX Live packaging that lives entirely under ``` - There are all the schemes, collections and a few thousand packages, as defined upstream (perhaps with tiny differences). + - By default you only get executables and files needed during runtime, and a little documentation for the core packages. To change that, you need to add `pkgFilter` function to `combine`. ```nix diff --git a/doc/languages-frameworks/titanium.section.md b/doc/languages-frameworks/titanium.section.md index 57360f034b9..306ad866276 100644 --- a/doc/languages-frameworks/titanium.section.md +++ b/doc/languages-frameworks/titanium.section.md @@ -9,8 +9,8 @@ applications for Android and iOS devices from source code. Not all Titanium features supported -- currently, it can only be used to build Android and iOS apps. -Building a Titanium app ------------------------ +## Building a Titanium app {#building-a-titanium-app} + We can build a Titanium app from source for Android or iOS and for debugging or release purposes by invoking the `titaniumenv.buildApp {}` function: @@ -103,8 +103,8 @@ When `enableWirelessDistribution` has been enabled, you must also provide the path of the PHP script (`installURL`) (that is included with the iOS build environment) to enable wireless ad-hoc installations. -Emulating or simulating the app -------------------------------- +## Emulating or simulating the app {#emulating-or-simulating-the-app} + It is also possible to simulate the correspond iOS simulator build by using `xcodeenv.simulateApp {}` and emulate an Android APK by using `androidenv.emulateApp {}`. diff --git a/doc/languages-frameworks/vim.section.md b/doc/languages-frameworks/vim.section.md index 5316db9a137..e170591605c 100644 --- a/doc/languages-frameworks/vim.section.md +++ b/doc/languages-frameworks/vim.section.md @@ -12,7 +12,7 @@ At the moment we support three different methods for managing plugins: - Pathogen - vim-plug -## Custom configuration +## Custom configuration {#custom-configuration} Adding custom .vimrc lines can be done using the following code: @@ -56,7 +56,7 @@ neovim-qt.override { } ``` -## Managing plugins with Vim packages +## Managing plugins with Vim packages {#managing-plugins-with-vim-packages} To store you plugins in Vim packages (the native Vim plugin manager, see `:help packages`) the following example can be used: @@ -116,7 +116,7 @@ The resulting package can be added to `packageOverrides` in `~/.nixpkgs/config.n After that you can install your special grafted `myVim` or `myNeovim` packages. -### What if your favourite Vim plugin isn't already packaged? +### What if your favourite Vim plugin isn’t already packaged? {#what-if-your-favourite-vim-plugin-isnt-already-packaged} If one of your favourite plugins isn't packaged, you can package it yourself: @@ -154,7 +154,7 @@ in } ``` -## Managing plugins with vim-plug +## Managing plugins with vim-plug {#managing-plugins-with-vim-plug} To use [vim-plug](https://github.com/junegunn/vim-plug) to manage your Vim plugins the following example can be used: @@ -183,14 +183,14 @@ neovim.override { } ``` -## Managing plugins with VAM +## Managing plugins with VAM {#managing-plugins-with-vam} -### Handling dependencies of Vim plugins +### Handling dependencies of Vim plugins {#handling-dependencies-of-vim-plugins} VAM introduced .json files supporting dependencies without versioning assuming that "using latest version" is ok most of the time. -### Example +### Example {#example} First create a vim-scripts file having one plugin name per line. Example: @@ -280,7 +280,7 @@ Sample output2: ] ``` -## Adding new plugins to nixpkgs +## Adding new plugins to nixpkgs {#adding-new-plugins-to-nixpkgs} Nix expressions for Vim plugins are stored in [pkgs/misc/vim-plugins](/pkgs/misc/vim-plugins). For the vast majority of plugins, Nix expressions are automatically generated by running [`./update.py`](/pkgs/misc/vim-plugins/update.py). This creates a [generated.nix](/pkgs/misc/vim-plugins/generated.nix) file based on the plugins listed in [vim-plugin-names](/pkgs/misc/vim-plugins/vim-plugin-names). Plugins are listed in alphabetical order in `vim-plugin-names` using the format `[github username]/[repository]`. For example https://github.com/scrooloose/nerdtree becomes `scrooloose/nerdtree`. @@ -298,7 +298,7 @@ To add a new plugin, run `./update.py --add "[owner]/[name]"`. **NOTE**: This sc Finally, there are some plugins that are also packaged in nodePackages because they have Javascript-related build steps, such as running webpack. Those plugins are not listed in `vim-plugin-names` or managed by `update.py` at all, and are included separately in `overrides.nix`. Currently, all these plugins are related to the `coc.nvim` ecosystem of Language Server Protocol integration with vim/neovim. -## Updating plugins in nixpkgs +## Updating plugins in nixpkgs {#updating-plugins-in-nixpkgs} Run the update script with a GitHub API token that has at least `public_repo` access. Running the script without the token is likely to result in rate-limiting (429 errors). For steps on creating an API token, please refer to [GitHub's token documentation](https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/creating-a-personal-access-token). @@ -312,7 +312,7 @@ Alternatively, set the number of processes to a lower count to avoid rate-limiti ./pkgs/misc/vim-plugins/update.py --proc 1 ``` -## Important repositories +## Important repositories {#important-repositories} - [vim-pi](https://bitbucket.org/vimcommunity/vim-pi) is a plugin repository from VAM plugin manager meant to be used by others as well used by diff --git a/doc/preface.chapter.md b/doc/preface.chapter.md index 64c921c711b..16f228272b3 100644 --- a/doc/preface.chapter.md +++ b/doc/preface.chapter.md @@ -12,7 +12,7 @@ Nixpkgs. If you like to learn more about the Nix package manager and the Nix expression language, then you are kindly referred to the [Nix manual](https://nixos.org/nix/manual/). The NixOS distribution is documented in the [NixOS manual](https://nixos.org/nixos/manual/). -## Overview of Nixpkgs +## Overview of Nixpkgs {#overview-of-nixpkgs} Nix expressions describe how to build packages from source and are collected in the [nixpkgs repository](https://github.com/NixOS/nixpkgs). Also included in the diff --git a/doc/stdenv/cross-compilation.chapter.md b/doc/stdenv/cross-compilation.chapter.md index 3755c13facf..b27e9cc6fea 100644 --- a/doc/stdenv/cross-compilation.chapter.md +++ b/doc/stdenv/cross-compilation.chapter.md @@ -6,7 +6,6 @@ This chapter will be organized in three parts. First, it will describe the basics of how to package software in a way that supports cross-compilation. Second, it will describe how to use Nixpkgs when cross-compiling. Third, it will describe the internal infrastructure supporting cross-compilation. - ## Packaging in a cross-friendly manner {#sec-cross-packaging} ### Platform parameters {#ssec-cross-platform-parameters} @@ -65,7 +64,7 @@ The exact schema these fields follow is a bit ill-defined due to a long and conv ### Theory of dependency categorization {#ssec-cross-dependency-categorization} -::: note +::: {.note} This is a rather philosophical description that isn't very Nixpkgs-specific. For an overview of all the relevant attributes given to `mkDerivation`, see . For a description of how everything is implemented, see . ::: @@ -81,10 +80,10 @@ Finally, if the depending package is a compiler or other machine-code-producing Putting this all together, that means we have dependencies in the form "host → target", in at most the following six combinations: +#### Possible dependency types {#possible-dependency-types} -#### Possible dependency types -| Dependency's host platform | Dependency's target platform | -| -- | -- | +| Dependency’s host platform | Dependency’s target platform | +|----------------------------|------------------------------| | build | build | | build | host | | build | target | @@ -113,15 +112,18 @@ On less powerful machines, it can be inconvenient to cross-compile a package onl $ nix-build '' -A pkgsCross.raspberryPi.hello ``` -#### What if my package's build system needs to build a C program to be run under the build environment? {#cross-qa-build-c-program-in-build-environment} +#### What if my package’s build system needs to build a C program to be run under the build environment? {#cross-qa-build-c-program-in-build-environment} + Add the following to your `mkDerivation` invocation. + ```nix depsBuildBuild = [ buildPackages.stdenv.cc ]; ``` -#### My package's testsuite needs to run host platform code. {#cross-testsuite-runs-host-code} +#### My package’s testsuite needs to run host platform code. {#cross-testsuite-runs-host-code} Add the following to your `mkDerivation` invocation. + ```nix doCheck = stdenv.hostPlatform == stdenv.buildPlatform; ``` @@ -134,7 +136,7 @@ Nixpkgs can be instantiated with `localSystem` alone, in which case there is no $ nix-build '' --arg crossSystem '(import ).systems.examples.fooBarBaz' -A whatever ``` -::: note +::: {.note} Eventually we would like to make these platform examples an unnecessary convenience so that ```ShellSession @@ -146,7 +148,7 @@ works in the vast majority of cases. The problem today is dependencies on other While one is free to pass both parameters in full, there's a lot of logic to fill in missing fields. As discussed in the previous section, only one of `system`, `config`, and `parsed` is needed to infer the other two. Additionally, `libc` will be inferred from `parse`. Finally, `localSystem.system` is also _impurely_ inferred based on the platform evaluation occurs. This means it is often not necessary to pass `localSystem` at all, as in the command-line example in the previous paragraph. -::: note +::: {.note} Many sources (manual, wiki, etc) probably mention passing `system`, `platform`, along with the optional `crossSystem` to Nixpkgs: `import { system = ..; platform = ..; crossSystem = ..; }`. Passing those two instead of `localSystem` is still supported for compatibility, but is discouraged. Indeed, much of the inference we do for these parameters is motivated by compatibility as much as convenience. ::: @@ -178,7 +180,7 @@ While there are many package sets, and thus many edges, the stages can also be a In each stage, `pkgsBuildHost` refers to the previous stage, `pkgsBuildBuild` refers to the one before that, and `pkgsHostTarget` refers to the current one, and `pkgsTargetTarget` refers to the next one. When there is no previous or next stage, they instead refer to the current stage. Note how all the invariants regarding the mapping between dependency and depending packages' build host and target platforms are preserved. `pkgsBuildTarget` and `pkgsHostHost` are more complex in that the stage fitting the requirements isn't always a fixed chain of "prevs" and "nexts" away (modulo the "saturating" self-references at the ends). We just special case each instead. All the primary edges are implemented is in `pkgs/stdenv/booter.nix`, and secondarily aliases in `pkgs/top-level/stage.nix`. -::: note +::: {.note} The native stages are bootstrapped in legacy ways that predate the current cross implementation. This is why the bootstrapping stages leading up to the final stages are ignored in the previous paragraph. ::: @@ -186,6 +188,7 @@ If one looks at the 3 platform triples, one can see that they overlap such that ``` (native, native, native, foreign, foreign) ``` + If one imagines the saturating self references at the end being replaced with infinite stages, and then overlays those platform triples, one ends up with the infinite tuple: ``` (native..., native, native, native, foreign, foreign, foreign...) @@ -193,8 +196,8 @@ If one imagines the saturating self references at the end being replaced with in One can then imagine any sequence of platforms such that there are bootstrap stages with their 3 platforms determined by "sliding a window" that is the 3 tuple through the sequence. This was the original model for bootstrapping. Without a target platform (assume a better world where all compilers are multi-target and all standard libraries are built in their own derivation), this is sufficient. Conversely if one wishes to cross compile "faster", with a "Canadian Cross" bootstrapping stage where `build != host != target`, more bootstrapping stages are needed since no sliding window provides the pesky `pkgsBuildTarget` package set since it skips the Canadian cross stage's "host". -::: note -It is much better to refer to `buildPackages` than `targetPackages`, or more broadly package sets that do not mention "target". There are three reasons for this. +::: {.note} +It is much better to refer to `buildPackages` than `targetPackages`, or more broadly package sets that do not mention “target”. There are three reasons for this. First, it is because bootstrapping stages do not have a unique `targetPackages`. For example a `(x86-linux, x86-linux, arm-linux)` and `(x86-linux, x86-linux, x86-windows)` package set both have a `(x86-linux, x86-linux, x86-linux)` package set. Because there is no canonical `targetPackages` for such a native (`build == host == target`) package set, we set their `targetPackages` @@ -203,6 +206,6 @@ Second, it is because this is a frequent source of hard-to-follow "infinite recu Thirdly, it is because everything target-mentioning only exists to accommodate compilers with lousy build systems that insist on the compiler itself and standard library being built together. Of course that is bad because bigger derivations means longer rebuilds. It is also problematic because it tends to make the standard libraries less like other libraries than they could be, complicating code and build systems alike. Because of the other problems, and because of these innate disadvantages, compilers ought to be packaged another way where possible. ::: -::: note -If one explores Nixpkgs, they will see derivations with names like `gccCross`. Such `*Cross` derivations is a holdover from before we properly distinguished between the host and target platforms—the derivation with "Cross" in the name covered the `build = host != target` case, while the other covered the `host = target`, with build platform the same or not based on whether one was using its `.nativeDrv` or `.crossDrv`. This ugliness will disappear soon. +::: {.note} +If one explores Nixpkgs, they will see derivations with names like `gccCross`. Such `*Cross` derivations is a holdover from before we properly distinguished between the host and target platforms—the derivation with “Cross” in the name covered the `build = host != target` case, while the other covered the `host = target`, with build platform the same or not based on whether one was using its `.nativeDrv` or `.crossDrv`. This ugliness will disappear soon. ::: diff --git a/doc/stdenv/meta.chapter.md b/doc/stdenv/meta.chapter.md index dd9f5325855..f226a725480 100644 --- a/doc/stdenv/meta.chapter.md +++ b/doc/stdenv/meta.chapter.md @@ -130,7 +130,7 @@ Attribute Set `lib.platforms` defines [various common lists](https://github.com/ ### `tests` {#var-meta-tests} -::: warning +::: {.warning} This attribute is special in that it is not actually under the `meta` attribute set but rather under the `passthru` attribute set. This is due to how `meta` attributes work, and the fact that they are supposed to contain only metadata, not derivations. ::: @@ -175,20 +175,20 @@ The `meta.license` attribute should preferably contain a value from `lib.license Although it’s typically better to indicate the specific license, a few generic options are available: -### `lib.licenses.free`, `"free"` +### `lib.licenses.free`, `"free"` {#lib.licenses.free-free} Catch-all for free software licenses not listed above. -### `lib.licenses.unfreeRedistributable`, `"unfree-redistributable"` +### `lib.licenses.unfreeRedistributable`, `"unfree-redistributable"` {#lib.licenses.unfreeredistributable-unfree-redistributable} Unfree package that can be redistributed in binary form. That is, it’s legal to redistribute the *output* of the derivation. This means that the package can be included in the Nixpkgs channel. Sometimes proprietary software can only be redistributed unmodified. Make sure the builder doesn’t actually modify the original binaries; otherwise we’re breaking the license. For instance, the NVIDIA X11 drivers can be redistributed unmodified, but our builder applies `patchelf` to make them work. Thus, its license is `"unfree"` and it cannot be included in the Nixpkgs channel. -### `lib.licenses.unfree`, `"unfree"` +### `lib.licenses.unfree`, `"unfree"` {#lib.licenses.unfree-unfree} Unfree package that cannot be redistributed. You can build it yourself, but you cannot redistribute the output of the derivation. Thus it cannot be included in the Nixpkgs channel. -### `lib.licenses.unfreeRedistributableFirmware`, `"unfree-redistributable-firmware"` +### `lib.licenses.unfreeRedistributableFirmware`, `"unfree-redistributable-firmware"` {#lib.licenses.unfreeredistributablefirmware-unfree-redistributable-firmware} This package supplies unfree, redistributable firmware. This is a separate value from `unfree-redistributable` because not everybody cares whether firmware is free. diff --git a/doc/stdenv/multiple-output.chapter.md b/doc/stdenv/multiple-output.chapter.md index 90bc25bef73..b8414614279 100644 --- a/doc/stdenv/multiple-output.chapter.md +++ b/doc/stdenv/multiple-output.chapter.md @@ -6,7 +6,7 @@ The Nix language allows a derivation to produce multiple outputs, which is simil The main motivation is to save disk space by reducing runtime closure sizes; consequently also sizes of substituted binaries get reduced. Splitting can be used to have more granular runtime dependencies, for example the typical reduction is to split away development-only files, as those are typically not needed during runtime. As a result, closure sizes of many packages can get reduced to a half or even much less. -::: note +::: {.note} The reduction effects could be instead achieved by building the parts in completely separate derivations. That would often additionally reduce build-time closures, but it tends to be much harder to write such derivations, as build systems typically assume all parts are being built at once. This compromise approach of single source package producing multiple binary packages is also utilized often by rpm and deb. ::: @@ -28,7 +28,7 @@ NixOS provides two ways to select the outputs to install for packages listed in `nix-env` lacks an easy way to select the outputs to install. When installing a package, `nix-env` always installs the outputs listed in `meta.outputsToInstall`, even when the user explicitly selects an output. -::: warning +::: {.warning} `nix-env` silenty disregards the outputs selected by the user, and instead installs the outputs from `meta.outputsToInstall`. For example, ```ShellSession @@ -69,7 +69,7 @@ outputs = [ "bin" "dev" "out" "doc" ]; Often such a single line is enough. For each output an equally named environment variable is passed to the builder and contains the path in nix store for that output. Typically you also want to have the main `out` output, as it catches any files that didn’t get elsewhere. -::: note +::: {.note} There is a special handling of the `debug` output, described at . ::: @@ -85,35 +85,35 @@ The reason for why `glibc` deviates from the convention is because referencing a The support code currently recognizes some particular kinds of outputs and either instructs the build system of the package to put files into their desired outputs or it moves the files during the fixup phase. Each group of file types has an `outputFoo` variable specifying the output name where they should go. If that variable isn’t defined by the derivation writer, it is guessed – a default output name is defined, falling back to other possibilities if the output isn’t defined. -#### ` $outputDev` +#### `$outputDev` {#outputdev} is for development-only files. These include C(++) headers (`include/`), pkg-config (`lib/pkgconfig/`), cmake (`lib/cmake/`) and aclocal files (`share/aclocal/`). They go to `dev` or `out` by default. -#### ` $outputBin` +#### `$outputBin` {#outputbin} is meant for user-facing binaries, typically residing in `bin/`. They go to `bin` or `out` by default. -#### ` $outputLib` +#### `$outputLib` {#outputlib} is meant for libraries, typically residing in `lib/` and `libexec/`. They go to `lib` or `out` by default. -#### ` $outputDoc` +#### `$outputDoc` {#outputdoc} is for user documentation, typically residing in `share/doc/`. It goes to `doc` or `out` by default. -#### ` $outputDevdoc` +#### `$outputDevdoc` {#outputdevdoc} is for _developer_ documentation. Currently we count gtk-doc and devhelp books, typically residing in `share/gtk-doc/` and `share/devhelp/`, in there. It goes to `devdoc` or is removed (!) by default. This is because e.g. gtk-doc tends to be rather large and completely unused by nixpkgs users. -#### ` $outputMan` +#### `$outputMan` {#outputman} is for man pages (except for section 3), typically residing in `share/man/man[0-9]/`. They go to `man` or `$outputBin` by default. -#### ` $outputDevman` +#### `$outputDevman` {#outputdevman} is for section 3 man pages, typically residing in `share/man/man[0-9]/`. They go to `devman` or `$outputMan` by default. -#### ` $outputInfo` +#### `$outputInfo` {#outputinfo} is for info pages, typically residing in `share/info/`. They go to `info` or `$outputBin` by default. diff --git a/doc/stdenv/stdenv.chapter.md b/doc/stdenv/stdenv.chapter.md index b23c50e8364..71eb991bbae 100644 --- a/doc/stdenv/stdenv.chapter.md +++ b/doc/stdenv/stdenv.chapter.md @@ -175,7 +175,8 @@ Because of the bounds checks, the uncommon cases are `h = t` and `h + 2 = t`. In Overall, the unifying theme here is that propagation shouldn’t be introducing transitive dependencies involving platforms the depending package is unaware of. \[One can imagine the dependending package asking for dependencies with the platforms it knows about; other platforms it doesn’t know how to ask for. The platform description in that scenario is a kind of unforagable capability.\] The offset bounds checking and definition of `mapOffset` together ensure that this is the case. Discovering a new offset is discovering a new platform, and since those platforms weren’t in the derivation “spec” of the needing package, they cannot be relevant. From a capability perspective, we can imagine that the host and target platforms of a package are the capabilities a package requires, and the depending package must provide the capability to the dependency. -### Variables specifying dependencies +### Variables specifying dependencies {#variables-specifying-dependencies} + #### `depsBuildBuild` {#var-stdenv-depsBuildBuild} A list of dependencies whose host and target platforms are the new derivation’s build platform. This means a `-1` host and `-1` target offset from the new derivation’s platforms. These are programs and libraries used at build time that produce programs and libraries also used at build time. If the dependency doesn’t care about the target platform (i.e. isn’t a compiler or similar tool), put it in `nativeBuildInputs` instead. The most common use of this `buildPackages.stdenv.cc`, the default C compiler for this role. That example crops up more than one might think in old commonly used C libraries. @@ -236,13 +237,13 @@ The propagated equivalent of `depsTargetTarget`. This is prefixed for the same r ## Attributes {#ssec-stdenv-attributes} -### Variables affecting `stdenv` initialisation +### Variables affecting `stdenv` initialisation {#variables-affecting-stdenv-initialisation} #### `NIX_DEBUG` {#var-stdenv-NIX_DEBUG} A natural number indicating how much information to log. If set to 1 or higher, `stdenv` will print moderate debugging information during the build. In particular, the `gcc` and `ld` wrapper scripts will print out the complete command line passed to the wrapped tools. If set to 6 or higher, the `stdenv` setup script will be run with `set -x` tracing. If set to 7 or higher, the `gcc` and `ld` wrapper scripts will also be run with `set -x` tracing. -### Attributes affecting build properties +### Attributes affecting build properties {#attributes-affecting-build-properties} #### `enableParallelBuilding` {#var-stdenv-enableParallelBuilding} @@ -250,7 +251,7 @@ If set to `true`, `stdenv` will pass specific flags to `make` and other build to Unless set to `false`, some build systems with good support for parallel building including `cmake`, `meson`, and `qmake` will set it to `true`. -### Special variables +### Special variables {#special-variables} #### `passthru` {#var-stdenv-passthru} @@ -298,7 +299,7 @@ passthru.updateScript = [ ../../update.sh pname "--requested-release=unstable" ] The script will be run with `UPDATE_NIX_ATTR_PATH` environment variable set to the attribute path it is supposed to update. -::: note +::: {.note} The script will be usually run from the root of the Nixpkgs repository but you should not rely on that. Also note that the update scripts will be run in parallel by default; you should avoid running `git commit` or any other commands that cannot handle that. ::: @@ -314,7 +315,7 @@ Each phase can be overridden in its entirety either by setting the environment v There are a number of variables that control what phases are executed and in what order: -#### Variables affecting phase control +#### Variables affecting phase control {#variables-affecting-phase-control} ##### `phases` {#var-stdenv-phases} @@ -354,21 +355,22 @@ Additional phases executed after any of the default phases. The unpack phase is responsible for unpacking the source code of the package. The default implementation of `unpackPhase` unpacks the source files listed in the `src` environment variable to the current directory. It supports the following files by default: -#### Tar files +#### Tar files {#tar-files} These can optionally be compressed using `gzip` (`.tar.gz`, `.tgz` or `.tar.Z`), `bzip2` (`.tar.bz2`, `.tbz2` or `.tbz`) or `xz` (`.tar.xz`, `.tar.lzma` or `.txz`). -#### Zip files +#### Zip files {#zip-files} Zip files are unpacked using `unzip`. However, `unzip` is not in the standard environment, so you should add it to `nativeBuildInputs` yourself. -#### Directories in the Nix store +#### Directories in the Nix store {#directories-in-the-nix-store} These are simply copied to the current directory. The hash part of the file name is stripped, e.g. `/nix/store/1wydxgby13cz...-my-sources` would be copied to `my-sources`. Additional file types can be supported by setting the `unpackCmd` variable (see below). -#### Variables controlling the unpack phase +#### Variables controlling the unpack phase {#variables-controlling-the-unpack-phase} + ##### `srcs` / `src` {#var-stdenv-src} The list of source files or directories to be unpacked or copied. One of these must be set. @@ -405,7 +407,7 @@ The unpack phase evaluates the string `$unpackCmd` for any unrecognised file. Th The patch phase applies the list of patches defined in the `patches` variable. -#### Variables controlling the patch phase +#### Variables controlling the patch phase {#variables-controlling-the-patch-phase} ##### `dontPatch` {#var-stdenv-dontPatch} @@ -431,7 +433,7 @@ Hook executed at the end of the patch phase. The configure phase prepares the source tree for building. The default `configurePhase` runs `./configure` (typically an Autoconf-generated script) if it exists. -#### Variables controlling the configure phase +#### Variables controlling the configure phase {#variables-controlling-the-configure-phase} ##### `configureScript` {#var-stdenv-configureScript} @@ -491,7 +493,7 @@ Hook executed at the end of the configure phase. The build phase is responsible for actually building the package (e.g. compiling it). The default `buildPhase` simply calls `make` if a file named `Makefile`, `makefile` or `GNUmakefile` exists in the current directory (or the `makefile` is explicitly set); otherwise it does nothing. -#### Variables controlling the build phase +#### Variables controlling the build phase {#variables-controlling-the-build-phase} ##### `dontBuild` {#var-stdenv-dontBuild} @@ -509,7 +511,7 @@ A list of strings passed as additional flags to `make`. These flags are also use makeFlags = [ "PREFIX=$(out)" ]; ``` -::: note +::: {.note} The flags are quoted in bash, but environment variables can be specified by using the make syntax. ::: @@ -545,7 +547,7 @@ Before and after running `make`, the hooks `preBuild` and `postBuild` are called The check phase checks whether the package was built correctly by running its test suite. The default `checkPhase` calls `make check`, but only if the `doCheck` variable is enabled. -#### Variables controlling the check phase +#### Variables controlling the check phase {#variables-controlling-the-check-phase} ##### `doCheck` {#var-stdenv-doCheck} @@ -557,7 +559,7 @@ doCheck = true; in the derivation to enable checks. The exception is cross compilation. Cross compiled builds never run tests, no matter how `doCheck` is set, as the newly-built program won’t run on the platform used to build it. -##### `makeFlags` / `makeFlagsArray` / `makefile` +##### `makeFlags` / `makeFlagsArray` / `makefile` {#makeflags-makeflagsarray-makefile} See the [build phase](#var-stdenv-makeFlags) for details. @@ -585,13 +587,13 @@ Hook executed at the end of the check phase. The install phase is responsible for installing the package in the Nix store under `out`. The default `installPhase` creates the directory `$out` and calls `make install`. -#### Variables controlling the install phase +#### Variables controlling the install phase {#variables-controlling-the-install-phase} ##### `dontInstall` {#var-stdenv-dontInstall} Set to true to skip the install phase. -##### `makeFlags` / `makeFlagsArray` / `makefile` +##### `makeFlags` / `makeFlagsArray` / `makefile` {#makeflags-makeflagsarray-makefile-1} See the [build phase](#var-stdenv-makeFlags) for details. @@ -624,7 +626,7 @@ The fixup phase performs some (Nix-specific) post-processing actions on the file - On Linux, it applies the `patchelf` command to ELF executables and libraries to remove unused directories from the `RPATH` in order to prevent unnecessary runtime dependencies. - It rewrites the interpreter paths of shell scripts to paths found in `PATH`. E.g., `/usr/bin/perl` will be rewritten to `/nix/store/some-perl/bin/perl` found in `PATH`. -#### Variables controlling the fixup phase +#### Variables controlling the fixup phase {#variables-controlling-the-fixup-phase} ##### `dontFixup` {#var-stdenv-dontFixup} @@ -706,7 +708,7 @@ to `~/.gdbinit`. GDB will then be able to find debug information installed via ` The installCheck phase checks whether the package was installed correctly by running its test suite against the installed directories. The default `installCheck` calls `make installcheck`. -#### Variables controlling the installCheck phase +#### Variables controlling the installCheck phase {#variables-controlling-the-installcheck-phase} ##### `doInstallCheck` {#var-stdenv-doInstallCheck} @@ -742,7 +744,7 @@ Hook executed at the end of the installCheck phase. The distribution phase is intended to produce a source distribution of the package. The default `distPhase` first calls `make dist`, then it copies the resulting source tarballs to `$out/tarballs/`. This phase is only executed if the attribute `doDist` is set. -#### Variables controlling the distribution phase +#### Variables controlling the distribution phase {#variables-controlling-the-distribution-phase} ##### `distTarget` {#var-stdenv-distTarget} @@ -879,7 +881,7 @@ The most typical use of the setup hook is actually to add other hooks which are Packages adding a hook should not hard code a specific hook, but rather choose a variable *relative* to how they are included. Returning to the C compiler wrapper example, if the wrapper itself is an `n` dependency, then it only wants to accumulate flags from `n + 1` dependencies, as only those ones match the compiler’s target platform. The `hostOffset` variable is defined with the current dependency’s host offset `targetOffset` with its target offset, before its setup hook is sourced. Additionally, since most environment hooks don’t care about the target platform, that means the setup hook can append to the right bash array by doing something like -```{.bash} +```bash addEnvHooks "$hostOffset" myBashFunction ``` @@ -887,47 +889,47 @@ The *existence* of setups hooks has long been documented and packages inside Nix First, let’s cover some setup hooks that are part of Nixpkgs default stdenv. This means that they are run for every package built using `stdenv.mkDerivation`. Some of these are platform specific, so they may run on Linux but not Darwin or vice-versa. -### `move-docs.sh` +### `move-docs.sh` {#move-docs.sh} This setup hook moves any installed documentation to the `/share` subdirectory directory. This includes the man, doc and info directories. This is needed for legacy programs that do not know how to use the `share` subdirectory. -### `compress-man-pages.sh` +### `compress-man-pages.sh` {#compress-man-pages.sh} This setup hook compresses any man pages that have been installed. The compression is done using the gzip program. This helps to reduce the installed size of packages. -### `strip.sh` +### `strip.sh` {#strip.sh} This runs the strip command on installed binaries and libraries. This removes unnecessary information like debug symbols when they are not needed. This also helps to reduce the installed size of packages. -### `patch-shebangs.sh` +### `patch-shebangs.sh` {#patch-shebangs.sh} This setup hook patches installed scripts to use the full path to the shebang interpreter. A shebang interpreter is the first commented line of a script telling the operating system which program will run the script (e.g `#!/bin/bash`). In Nix, we want an exact path to that interpreter to be used. This often replaces `/bin/sh` with a path in the Nix store. -### `audit-tmpdir.sh` +### `audit-tmpdir.sh` {#audit-tmpdir.sh} This verifies that no references are left from the install binaries to the directory used to build those binaries. This ensures that the binaries do not need things outside the Nix store. This is currently supported in Linux only. -### `multiple-outputs.sh` +### `multiple-outputs.sh` {#multiple-outputs.sh} This setup hook adds configure flags that tell packages to install files into any one of the proper outputs listed in `outputs`. This behavior can be turned off by setting `setOutputFlags` to false in the derivation environment. See for more information. -### `move-sbin.sh` +### `move-sbin.sh` {#move-sbin.sh} This setup hook moves any binaries installed in the `sbin/` subdirectory into `bin/`. In addition, a link is provided from `sbin/` to `bin/` for compatibility. -### `move-lib64.sh` +### `move-lib64.sh` {#move-lib64.sh} This setup hook moves any libraries installed in the `lib64/` subdirectory into `lib/`. In addition, a link is provided from `lib64/` to `lib/` for compatibility. -### `move-systemd-user-units.sh` +### `move-systemd-user-units.sh` {#move-systemd-user-units.sh} This setup hook moves any systemd user units installed in the `lib/` subdirectory into `share/`. In addition, a link is provided from `share/` to `lib/` for compatibility. This is needed for systemd to find user services when installed into the user profile. -### `set-source-date-epoch-to-latest.sh` +### `set-source-date-epoch-to-latest.sh` {#set-source-date-epoch-to-latest.sh} This sets `SOURCE_DATE_EPOCH` to the modification time of the most recent file. -### Bintools Wrapper +### Bintools Wrapper {#bintools-wrapper} The Bintools Wrapper wraps the binary utilities for a bunch of miscellaneous purposes. These are GNU Binutils when targetting Linux, and a mix of cctools and GNU binutils for Darwin. \[The “Bintools” name is supposed to be a compromise between “Binutils” and “cctools” not denoting any specific implementation.\] Specifically, the underlying bintools package, and a C standard library (glibc or Darwin’s libSystem, just for the dynamic loader) are all fed in, and dependency finding, hardening (see below), and purity checks for each are handled by the Bintools Wrapper. Packages typically depend on CC Wrapper, which in turn (at run time) depends on the Bintools Wrapper. @@ -937,7 +939,7 @@ A final task of the setup hook is defining a number of standard environment vari A problem with this final task is that the Bintools Wrapper is honest and defines `LD` as `ld`. Most packages, however, firstly use the C compiler for linking, secondly use `LD` anyways, defining it as the C compiler, and thirdly, only so define `LD` when it is undefined as a fallback. This triple-threat means Bintools Wrapper will break those packages, as LD is already defined as the actual linker which the package won’t override yet doesn’t want to use. The workaround is to define, just for the problematic package, `LD` as the C compiler. A good way to do this would be `preConfigure = "LD=$CC"`. -### CC Wrapper +### CC Wrapper {#cc-wrapper} The CC Wrapper wraps a C toolchain for a bunch of miscellaneous purposes. Specifically, a C compiler (GCC or Clang), wrapped binary tools, and a C standard library (glibc or Darwin’s libSystem, just for the dynamic loader) are all fed in, and dependency finding, hardening (see below), and purity checks for each are handled by the CC Wrapper. Packages typically depend on the CC Wrapper, which in turn (at run-time) depends on the Bintools Wrapper. @@ -971,11 +973,11 @@ The `autoreconfHook` derivation adds `autoreconfPhase`, which runs autoreconf, l Adds every file named `catalog.xml` found under the `xml/dtd` and `xml/xsl` subdirectories of each build input to the `XML_CATALOG_FILES` environment variable. -### teTeX / TeX Live +### teTeX / TeX Live {#tetex-tex-live} Adds the `share/texmf-nix` subdirectory of each build input to the `TEXINPUTS` environment variable. -### Qt 4 +### Qt 4 {#qt-4} Sets the `QTDIR` environment variable to Qt’s path. @@ -983,11 +985,11 @@ Sets the `QTDIR` environment variable to Qt’s path. Exports `GDK_PIXBUF_MODULE_FILE` environment variable to the builder. Add librsvg package to `buildInputs` to get svg support. See also the [setup hook description in GNOME platform docs](#ssec-gnome-hooks-gdk-pixbuf). -### GHC +### GHC {#ghc} Creates a temporary package database and registers every Haskell build input in it (TODO: how?). -### GNOME platform +### GNOME platform {#gnome-platform} Hooks related to GNOME platform and related libraries like GLib, GTK and GStreamer are described in . @@ -1003,7 +1005,7 @@ By default `autoPatchelf` will fail as soon as any ELF file requires a dependenc The `autoPatchelf` command also recognizes a `--no-recurse` command line flag, which prevents it from recursing into subdirectories. -### breakpointHook +### breakpointHook {#breakpointhook} This hook will make a build pause instead of stopping when a failure happens. It prevents nix from cleaning up the build environment immediately and allows the user to attach to a build environment using the `cntr` command. Upon build error it will print instructions on how to use `cntr`, which can be used to enter the environment for debugging. Installing cntr and running the command will provide shell access to the build sandbox of failed build. At `/var/lib/cntr` the sandboxed filesystem is mounted. All commands and files of the system are still accessible within the shell. To execute commands from the sandbox use the cntr exec subcommand. `cntr` is only supported on Linux-based platforms. To use it first add `cntr` to your `environment.systemPackages` on NixOS or alternatively to the root user on non-NixOS systems. Then in the package that is supposed to be inspected, add `breakpointHook` to `nativeBuildInputs`. @@ -1013,15 +1015,15 @@ nativeBuildInputs = [ breakpointHook ]; When a build failure happens there will be an instruction printed that shows how to attach with `cntr` to the build sandbox. -::: note -::: title +::: {.note} +::: {.title} Caution with remote builds ::: This won’t work with remote builds as the build environment is on a different machine and can’t be accessed by `cntr`. Remote builds can be turned off by setting `--option builders ''` for `nix-build` or `--builders ''` for `nix build`. ::: -### installShellFiles +### installShellFiles {#installshellfiles} This hook helps with installing manpages and shell completion files. It exposes 2 shell functions `installManPage` and `installShellCompletion` that can be used from your `postInstall` hook. @@ -1047,61 +1049,61 @@ postInstall = '' ''; ``` -### libiconv, libintl +### libiconv, libintl {#libiconv-libintl} A few libraries automatically add to `NIX_LDFLAGS` their library, making their symbols automatically available to the linker. This includes libiconv and libintl (gettext). This is done to provide compatibility between GNU Linux, where libiconv and libintl are bundled in, and other systems where that might not be the case. Sometimes, this behavior is not desired. To disable this behavior, set `dontAddExtraLibs`. -### validatePkgConfig +### validatePkgConfig {#validatepkgconfig} The `validatePkgConfig` hook validates all pkg-config (`.pc`) files in a package. This helps catching some common errors in pkg-config files, such as undefined variables. -### cmake +### cmake {#cmake} Overrides the default configure phase to run the CMake command. By default, we use the Make generator of CMake. In addition, dependencies are added automatically to CMAKE_PREFIX_PATH so that packages are correctly detected by CMake. Some additional flags are passed in to give similar behavior to configure-based packages. You can disable this hook’s behavior by setting configurePhase to a custom value, or by setting dontUseCmakeConfigure. cmakeFlags controls flags passed only to CMake. By default, parallel building is enabled as CMake supports parallel building almost everywhere. When Ninja is also in use, CMake will detect that and use the ninja generator. -### xcbuildHook +### xcbuildHook {#xcbuildhook} Overrides the build and install phases to run the "xcbuild" command. This hook is needed when a project only comes with build files for the XCode build system. You can disable this behavior by setting buildPhase and configurePhase to a custom value. xcbuildFlags controls flags passed only to xcbuild. -### Meson +### Meson {#meson} Overrides the configure phase to run meson to generate Ninja files. To run these files, you should accompany Meson with ninja. By default, `enableParallelBuilding` is enabled as Meson supports parallel building almost everywhere. -#### Variables controlling Meson +#### Variables controlling Meson {#variables-controlling-meson} -##### `mesonFlags` +##### `mesonFlags` {#mesonflags} Controls the flags passed to meson. -##### `mesonBuildType` +##### `mesonBuildType` {#mesonbuildtype} Which [`--buildtype`](https://mesonbuild.com/Builtin-options.html#core-options) to pass to Meson. We default to `plain`. -##### `mesonAutoFeatures` +##### `mesonAutoFeatures` {#mesonautofeatures} What value to set [`-Dauto_features=`](https://mesonbuild.com/Builtin-options.html#core-options) to. We default to `enabled`. -##### `mesonWrapMode` +##### `mesonWrapMode` {#mesonwrapmode} What value to set [`-Dwrap_mode=`](https://mesonbuild.com/Builtin-options.html#core-options) to. We default to `nodownload` as we disallow network access. -##### `dontUseMesonConfigure` +##### `dontUseMesonConfigure` {#dontusemesonconfigure} Disables using Meson’s `configurePhase`. -### ninja +### ninja {#ninja} Overrides the build, install, and check phase to run ninja instead of make. You can disable this behavior with the `dontUseNinjaBuild`, `dontUseNinjaInstall`, and `dontUseNinjaCheck`, respectively. Parallel building is enabled by default in Ninja. -### unzip +### unzip {#unzip} This setup hook will allow you to unzip .zip files specified in `$src`. There are many similar packages like `unrar`, `undmg`, etc. -### wafHook +### wafHook {#wafhook} Overrides the configure, build, and install phases. This will run the “waf” script used by many projects. If `wafPath` (default `./waf`) doesn’t exist, it will copy the version of waf available in Nixpkgs. `wafFlags` can be used to pass flags to the waf script. -### scons +### scons {#scons} Overrides the build, install, and check phases. This uses the scons build system as a replacement for make. scons does not provide a configure phase, so everything is managed at build and install time. @@ -1119,7 +1121,7 @@ Both parameters take a list of flags as strings. The special `"all"` flag can be The following flags are enabled by default and might require disabling with `hardeningDisable` if the program to package is incompatible. -### `format` +### `format` {#format} Adds the `-Wformat -Wformat-security -Werror=format-security` compiler options. At present, this warns about calls to `printf` and `scanf` functions where the format string is not a string literal and there are no format arguments, as in `printf(foo);`. This may be a security hole if the format string came from untrusted input and contains `%n`. @@ -1132,7 +1134,7 @@ This needs to be turned off or fixed for errors similar to: cc1plus: some warnings being treated as errors ``` -### `stackprotector` +### `stackprotector` {#stackprotector} Adds the `-fstack-protector-strong --param ssp-buffer-size=4` compiler options. This adds safety checks against stack overwrites rendering many potential code injection attacks into aborting situations. In the best case this turns code injection vulnerabilities into denial of service or into non-issues (depending on the application). @@ -1143,7 +1145,7 @@ bin/blib.a(bios_console.o): In function `bios_handle_cup': /tmp/nix-build-ipxe-20141124-5cbdc41.drv-0/ipxe-5cbdc41/src/arch/i386/firmware/pcbios/bios_console.c:86: undefined reference to `__stack_chk_fail' ``` -### `fortify` +### `fortify` {#fortify} Adds the `-O2 -D_FORTIFY_SOURCE=2` compiler options. During code generation the compiler knows a great deal of information about buffer sizes (where possible), and attempts to replace insecure unlimited length buffer function calls with length-limited ones. This is especially useful for old, crufty code. Additionally, format strings in writable memory that contain `%n` are blocked. If an application depends on such a format string, it will need to be worked around. @@ -1164,7 +1166,7 @@ installwatch.c:3751:5: error: conflicting types for '__open_2' fcntl2.h:50:4: error: call to '__open_missing_mode' declared with attribute error: open with O_CREAT or O_TMPFILE in second argument needs 3 arguments ``` -### `pic` +### `pic` {#pic} Adds the `-fPIC` compiler options. This options adds support for position independent code in shared libraries and thus making ASLR possible. @@ -1177,19 +1179,19 @@ ccbLfRgg.s: Assembler messages: ccbLfRgg.s:33: Error: missing or invalid displacement expression `private_key_len@GOTOFF' ``` -### `strictoverflow` +### `strictoverflow` {#strictoverflow} Signed integer overflow is undefined behaviour according to the C standard. If it happens, it is an error in the program as it should check for overflow before it can happen, not afterwards. GCC provides built-in functions to perform arithmetic with overflow checking, which are correct and faster than any custom implementation. As a workaround, the option `-fno-strict-overflow` makes gcc behave as if signed integer overflows were defined. This flag should not trigger any build or runtime errors. -### `relro` +### `relro` {#relro} Adds the `-z relro` linker option. During program load, several ELF memory sections need to be written to by the linker, but can be turned read-only before turning over control to the program. This prevents some GOT (and .dtors) overwrite attacks, but at least the part of the GOT used by the dynamic linker (.got.plt) is still vulnerable. This flag can break dynamic shared object loading. For instance, the module systems of Xorg and OpenCV are incompatible with this flag. In almost all cases the `bindnow` flag must also be disabled and incompatible programs typically fail with similar errors at runtime. -### `bindnow` +### `bindnow` {#bindnow} Adds the `-z bindnow` linker option. During program load, all dynamic symbols are resolved, allowing for the complete GOT to be marked read-only (due to `relro`). This prevents GOT overwrite attacks. For very large applications, this can incur some performance loss during initial load while symbols are resolved, but this shouldn’t be an issue for daemons. @@ -1201,7 +1203,7 @@ intel_drv.so: undefined symbol: vgaHWFreeHWRec The following flags are disabled by default and should be enabled with `hardeningEnable` for packages that take untrusted input like network services. -### `pie` +### `pie` {#pie} Adds the `-fPIE` compiler and `-pie` linker options. Position Independent Executables are needed to take advantage of Address Space Layout Randomization, supported by modern kernel versions. While ASLR can already be enforced for data areas in the stack and heap (brk and mmap), the code areas must be compiled as position-independent. Shared libraries already do this with the `pic` flag, so they gain ASLR automatically, but binary .text regions need to be build with `pie` to gain ASLR. When this happens, ROP attacks are much harder since there are no static locations to bounce off of during a memory corruption attack. diff --git a/doc/using/overlays.chapter.md b/doc/using/overlays.chapter.md index 21efe467b84..537d031bcdb 100644 --- a/doc/using/overlays.chapter.md +++ b/doc/using/overlays.chapter.md @@ -63,7 +63,7 @@ The second argument (`super`) corresponds to the result of the evaluation of the The value returned by this function should be a set similar to `pkgs/top-level/all-packages.nix`, containing overridden and/or new packages. -Overlays are similar to other methods for customizing Nixpkgs, in particular the `packageOverrides` attribute described in . Indeed, `packageOverrides` acts as an overlay with only the `super` argument. It is therefore appropriate for basic use, but overlays are more powerful and easier to distribute. +Overlays are similar to other methods for customizing Nixpkgs, in particular the `packageOverrides` attribute described in. Indeed, `packageOverrides` acts as an overlay with only the `super` argument. It is therefore appropriate for basic use, but overlays are more powerful and easier to distribute. ## Using overlays to configure alternatives {#sec-overlays-alternatives} diff --git a/doc/using/overrides.chapter.md b/doc/using/overrides.chapter.md index c1ab710e061..66e5103531a 100644 --- a/doc/using/overrides.chapter.md +++ b/doc/using/overrides.chapter.md @@ -48,17 +48,17 @@ In the above example, the `separateDebugInfo` attribute is overridden to be true The argument `oldAttrs` is conventionally used to refer to the attr set originally passed to `stdenv.mkDerivation`. -::: note -Note that `separateDebugInfo` is processed only by the `stdenv.mkDerivation` function, not the generated, raw Nix derivation. Thus, using `overrideDerivation` will not work in this case, as it overrides only the attributes of the final derivation. It is for this reason that `overrideAttrs` should be preferred in (almost) all cases to `overrideDerivation`, i.e. to allow using `stdenv.mkDerivation` to process input arguments, as well as the fact that it is easier to use (you can use the same attribute names you see in your Nix code, instead of the ones generated (e.g. `buildInputs` vs `nativeBuildInputs`), and it involves less typing). +::: {.note} +Note that `separateDebugInfo` is processed only by the `stdenv.mkDerivation` function, not the generated, raw Nix derivation. Thus, using `overrideDerivation` will not work in this case, as it overrides only the attributes of the final derivation. It is for this reason that `overrideAttrs` should be preferred in (almost) all cases to `overrideDerivation`, i.e. to allow using `stdenv.mkDerivation` to process input arguments, as well as the fact that it is easier to use (you can use the same attribute names you see in your Nix code, instead of the ones generated (e.g. `buildInputs` vs `nativeBuildInputs`), and it involves less typing). ::: ## <pkg>.overrideDerivation {#sec-pkg-overrideDerivation} -::: warning +::: {.warning} You should prefer `overrideAttrs` in almost all cases, see its documentation for the reasons why. `overrideDerivation` is not deprecated and will continue to work, but is less nice to use and does not have as many abilities as `overrideAttrs`. ::: -::: warning +::: {.warning} Do not use this function in Nixpkgs as it evaluates a Derivation before modifying it, which breaks package abstraction and removes error-checking of function arguments. In addition, this evaluation-per-function application incurs a performance penalty, which can become a problem if many overrides are used. It is only intended for ad-hoc customisation, such as in `~/.config/nixpkgs/config.nix`. ::: @@ -81,8 +81,8 @@ In the above example, the `name`, `src`, and `patches` of the derivation will be The argument `oldAttrs` is used to refer to the attribute set of the original derivation. -::: note -A package's attributes are evaluated *before* being modified by the `overrideDerivation` function. For example, the `name` attribute reference in `url = "mirror://gnu/hello/${name}.tar.gz";` is filled-in *before* the `overrideDerivation` function modifies the attribute set. This means that overriding the `name` attribute, in this example, *will not* change the value of the `url` attribute. Instead, we need to override both the `name` *and* `url` attributes. +::: {.note} +A package's attributes are evaluated *before* being modified by the `overrideDerivation` function. For example, the `name` attribute reference in `url = "mirror://gnu/hello/${name}.tar.gz";` is filled-in *before* the `overrideDerivation` function modifies the attribute set. This means that overriding the `name` attribute, in this example, *will not* change the value of the `url` attribute. Instead, we need to override both the `name` *and* `url` attributes. ::: ## lib.makeOverridable {#sec-lib-makeOverridable} -- cgit 1.4.1