diff options
author | Kasper Gałkowski | 2023-03-14 17:03:07 +0100 |
---|---|---|
committer | Kasper Gałkowski | 2023-03-14 17:07:39 +0100 |
commit | e5eb0322a2f7c235c64662b4dce720b62111fc88 (patch) | |
tree | 71ebb5b481e62b15362414a03c7f3fe1bfc1e67c /doc | |
parent | 97ec9764a4c2a23eef5c505183c858a3ae80606c (diff) | |
parent | 9e91539bb454af74b2e8f012e1aae08cb8abd9ff (diff) |
merge master
Diffstat (limited to 'doc')
-rw-r--r-- | doc/builders/fetchers.chapter.md | 1 | ||||
-rw-r--r-- | doc/builders/images/makediskimage.section.md | 1 | ||||
-rw-r--r-- | doc/languages-frameworks/haskell.section.md | 24 | ||||
-rw-r--r-- | doc/languages-frameworks/rust.section.md | 172 |
4 files changed, 92 insertions, 106 deletions
diff --git a/doc/builders/fetchers.chapter.md b/doc/builders/fetchers.chapter.md index 551df86a58f4..ecff01894840 100644 --- a/doc/builders/fetchers.chapter.md +++ b/doc/builders/fetchers.chapter.md @@ -71,6 +71,7 @@ The main difference between `fetchurl` and `fetchzip` is in how they store the c - `relative`: Similar to using `git-diff`'s `--relative` flag, only keep changes inside the specified directory, making paths relative to it. - `stripLen`: Remove the first `stripLen` components of pathnames in the patch. +- `decode`: Pipe the downloaded data through this command before processing it as a patch. - `extraPrefix`: Prefix pathnames by this string. - `excludes`: Exclude files matching these patterns (applies after the above arguments). - `includes`: Include only files matching these patterns (applies after the above arguments). diff --git a/doc/builders/images/makediskimage.section.md b/doc/builders/images/makediskimage.section.md index 833a6461e57b..c4566e753108 100644 --- a/doc/builders/images/makediskimage.section.md +++ b/doc/builders/images/makediskimage.section.md @@ -101,6 +101,7 @@ in diskSize = "auto"; additionalSpace = "0M"; # Defaults to 512M. copyChannel = false; + memSize = 2048; # Qemu VM memory size in megabytes. Defaults to 1024M. } ``` diff --git a/doc/languages-frameworks/haskell.section.md b/doc/languages-frameworks/haskell.section.md index c6d85a240a90..ec123e7c7bac 100644 --- a/doc/languages-frameworks/haskell.section.md +++ b/doc/languages-frameworks/haskell.section.md @@ -71,8 +71,10 @@ $ nix-env -f '<nixpkgs>' -qaP -A haskell.compiler haskell.compiler.ghc810 ghc-8.10.7 haskell.compiler.ghc88 ghc-8.8.4 haskell.compiler.ghc90 ghc-9.0.2 -haskell.compiler.ghc92 ghc-9.2.4 +haskell.compiler.ghc924 ghc-9.2.4 haskell.compiler.ghc925 ghc-9.2.5 +haskell.compiler.ghc926 ghc-9.2.6 +haskell.compiler.ghc92 ghc-9.2.7 haskell.compiler.ghc942 ghc-9.4.2 haskell.compiler.ghc943 ghc-9.4.3 haskell.compiler.ghc94 ghc-9.4.4 @@ -86,13 +88,15 @@ haskell.compiler.ghc924Binary ghc-binary-9.2.4 haskell.compiler.ghc924BinaryMinimal ghc-binary-9.2.4 haskell.compiler.integer-simple.ghc810 ghc-integer-simple-8.10.7 haskell.compiler.integer-simple.ghc8107 ghc-integer-simple-8.10.7 -haskell.compiler.integer-simple.ghc884 ghc-integer-simple-8.8.4 haskell.compiler.integer-simple.ghc88 ghc-integer-simple-8.8.4 +haskell.compiler.integer-simple.ghc884 ghc-integer-simple-8.8.4 haskell.compiler.native-bignum.ghc90 ghc-native-bignum-9.0.2 haskell.compiler.native-bignum.ghc902 ghc-native-bignum-9.0.2 -haskell.compiler.native-bignum.ghc92 ghc-native-bignum-9.2.4 haskell.compiler.native-bignum.ghc924 ghc-native-bignum-9.2.4 haskell.compiler.native-bignum.ghc925 ghc-native-bignum-9.2.5 +haskell.compiler.native-bignum.ghc926 ghc-native-bignum-9.2.6 +haskell.compiler.native-bignum.ghc92 ghc-native-bignum-9.2.7 +haskell.compiler.native-bignum.ghc927 ghc-native-bignum-9.2.7 haskell.compiler.native-bignum.ghc942 ghc-native-bignum-9.4.2 haskell.compiler.native-bignum.ghc943 ghc-native-bignum-9.4.3 haskell.compiler.native-bignum.ghc94 ghc-native-bignum-9.4.4 @@ -105,15 +109,15 @@ Each of those compiler versions has a corresponding attribute set built using it. However, the non-standard package sets are not tested regularly and, as a result, contain fewer working packages. The corresponding package set for GHC 9.4.4 is `haskell.packages.ghc944`. In fact `haskellPackages` is just an alias -for `haskell.packages.ghc924`: +for `haskell.packages.ghc927`: ```console -$ nix-env -f '<nixpkgs>' -qaP -A haskell.packages.ghc924 -haskell.packages.ghc924.a50 a50-0.5 -haskell.packages.ghc924.AAI AAI-0.2.0.1 -haskell.packages.ghc924.aasam aasam-0.2.0.0 -haskell.packages.ghc924.abacate abacate-0.0.0.0 -haskell.packages.ghc924.abc-puzzle abc-puzzle-0.2.1 +$ nix-env -f '<nixpkgs>' -qaP -A haskell.packages.ghc927 +haskell.packages.ghc927.a50 a50-0.5 +haskell.packages.ghc927.AAI AAI-0.2.0.1 +haskell.packages.ghc927.aasam aasam-0.2.0.0 +haskell.packages.ghc927.abacate abacate-0.0.0.0 +haskell.packages.ghc927.abc-puzzle abc-puzzle-0.2.1 … ``` diff --git a/doc/languages-frameworks/rust.section.md b/doc/languages-frameworks/rust.section.md index ec703105e15a..b3f4405ee935 100644 --- a/doc/languages-frameworks/rust.section.md +++ b/doc/languages-frameworks/rust.section.md @@ -13,7 +13,7 @@ into your `configuration.nix` or bring them into scope with `nix-shell -p rustc 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 a community maintained [Rust overlay](#using-community-rust-overlays). +or use [community maintained Rust toolchains](#using-community-maintained-rust-toolchains). ## `buildRustPackage`: Compiling Rust applications with Cargo {#compiling-rust-applications-with-cargo} @@ -686,31 +686,61 @@ $ cargo build $ cargo test ``` -### Controlling Rust Version Inside `nix-shell` {#controlling-rust-version-inside-nix-shell} +## Using community maintained Rust toolchains {#using-community-maintained-rust-toolchains} -To control your rust version (i.e. use nightly) from within `shell.nix` (or -other nix expressions) you can use the following `shell.nix` +::: {.note} +Note: The following projects cannot be used within nixpkgs since [IFD](#ssec-import-from-derivation) is disallowed. +To package things that require Rust nightly, `RUSTC_BOOTSTRAP = true;` can sometimes be used as a hack. +::: + +There are two community maintained approaches to Rust toolchain management: +- [oxalica's Rust overlay](https://github.com/oxalica/rust-overlay) +- [fenix](https://github.com/nix-community/fenix) + +Despite their names, both projects provides a similar set of packages and overlays under different APIs. + +Oxalica's overlay allows you to select a particular Rust version without you providing a hash or a flake input, +but comes with a larger git repository than fenix. + +Fenix also provides rust-analyzer nightly in addition to the Rust toolchains. + +Both oxalica's overlay and fenix better integrate with nix and cache optimizations. +Because of this and ergonomics, either of those community projects +should be preferred to the Mozilla's Rust overlay ([nixpkgs-mozilla](https://github.com/mozilla/nixpkgs-mozilla)). + +The following documentation demonstrates examples using fenix and oxalica's Rust overlay +with `nix-shell` and building derivations. More advanced usages like flake usage +are documented in their own repositories. + +### Using Rust nightly with `nix-shell` {#using-rust-nightly-with-nix-shell} + +Here is a simple `shell.nix` that provides Rust nightly (default profile) using fenix: ```nix -# Latest Nightly -with import <nixpkgs> {}; -let src = fetchFromGitHub { - owner = "mozilla"; - repo = "nixpkgs-mozilla"; - # commit from: 2019-05-15 - rev = "9f35c4b09fd44a77227e79ff0c1b4b6a69dff533"; - hash = "sha256-18h0nvh55b5an4gmlgfbvwbyqj91bklf1zymis6lbdh75571qaz0="; - }; +with import <nixpkgs> { }; +let + fenix = callPackage + (fetchFromGitHub { + owner = "nix-community"; + repo = "fenix"; + # commit from: 2023-03-03 + rev = "e2ea04982b892263c4d939f1cc3bf60a9c4deaa1"; + hash = "sha256-AsOim1A8KKtMWIxG+lXh5Q4P2bhOZjoUhFWJ1EuZNNk="; + }) + { }; in -with import "${src.out}/rust-overlay.nix" pkgs pkgs; -stdenv.mkDerivation { +mkShell { name = "rust-env"; - buildInputs = [ - # Note: to use stable, just replace `nightly` with `stable` - latest.rustChannels.nightly.rust + nativeBuildInputs = [ + # Note: to use stable, just replace `default` with `stable` + fenix.default.toolchain - # Add some extra dependencies from `pkgs` - pkg-config openssl + # Example Build-time Additional Dependencies + pkg-config + ]; + buildInputs = [ + # Example Run-time Additional Dependencies + openssl ]; # Set Environment Variables @@ -718,116 +748,66 @@ stdenv.mkDerivation { } ``` -Now run: +Save this to `shell.nix`, then run: ```ShellSession $ rustc --version -rustc 1.26.0-nightly (188e693b3 2018-03-26) +rustc 1.69.0-nightly (13471d3b2 2023-03-02) ``` To see that you are using nightly. -## Using community Rust overlays {#using-community-rust-overlays} +Oxalica's Rust overlay has more complete examples of `shell.nix` (and cross compilation) under its +[`examples` directory](https://github.com/oxalica/rust-overlay/tree/e53e8853aa7b0688bc270e9e6a681d22e01cf299/examples). -There are two community maintained approaches to Rust toolchain management: -- [oxalica's Rust overlay](https://github.com/oxalica/rust-overlay) -- [fenix](https://github.com/nix-community/fenix) - -Oxalica's overlay allows you to select a particular Rust version and components. -See [their documentation](https://github.com/oxalica/rust-overlay#rust-overlay) for more -detailed usage. +### Using Rust nightly in a derivation with `buildRustPackage` {#using-rust-nightly-in-a-derivation-with-buildrustpackage} -Fenix is an alternative to `rustup` and can also be used as an overlay. - -Both oxalica's overlay and fenix better integrate with nix and cache optimizations. -Because of this and ergonomics, either of those community projects -should be preferred to the Mozilla's Rust overlay (`nixpkgs-mozilla`). +You can also use Rust nightly to build rust packages using `makeRustPlatform`. +The below snippet demonstrates invoking `buildRustPackage` with a Rust toolchain from oxalica's overlay: -### How to select a specific `rustc` and toolchain version {#how-to-select-a-specific-rustc-and-toolchain-version} - -You can consume the oxalica overlay and use it to grab a specific Rust toolchain version. -Here is an example `shell.nix` showing how to grab the current stable toolchain: ```nix -{ pkgs ? import <nixpkgs> { - overlays = [ - (import (fetchTarball "https://github.com/oxalica/rust-overlay/archive/master.tar.gz")) - ]; - } -}: -pkgs.mkShell { - nativeBuildInputs = with pkgs; [ - pkg-config - rust-bin.stable.latest.minimal - ]; -} -``` - -You can try this out by: -1. Saving that to `shell.nix` -2. Executing `nix-shell --pure --command 'rustc --version'` - -As of writing, this prints out `rustc 1.56.0 (09c42c458 2021-10-18)`. - -### How to use an overlay toolchain in a derivation {#how-to-use-an-overlay-toolchain-in-a-derivation} - -You can also use an overlay's Rust toolchain with `buildRustPackage`. -The below snippet demonstrates invoking `buildRustPackage` with an oxalica overlay selected Rust toolchain: -```nix -with import <nixpkgs> { +with import <nixpkgs> +{ overlays = [ (import (fetchTarball "https://github.com/oxalica/rust-overlay/archive/master.tar.gz")) ]; }; +let + rustPlatform = makeRustPlatform { + cargo = rust-bin.stable.latest.minimal; + rustc = rust-bin.stable.latest.minimal; + }; +in rustPlatform.buildRustPackage rec { pname = "ripgrep"; version = "12.1.1"; - nativeBuildInputs = [ - rust-bin.stable.latest.minimal - ]; src = fetchFromGitHub { owner = "BurntSushi"; repo = "ripgrep"; rev = version; - hash = "sha256-1hqps7l5qrjh9f914r5i6kmcz6f1yb951nv4lby0cjnp5l253kps="; + hash = "sha256-+s5RBC3XSgb8omTbUNLywZnP6jSxZBKSS1BmXOjRF8M="; }; - cargoSha256 = "03wf9r2csi6jpa7v5sw5lpxkrk4wfzwmzx7k3991q3bdjzcwnnwp"; + cargoHash = "sha256-l1vL2ZdtDRxSGvP0X/l3nMw8+6WF67KPutJEzUROjg8="; + + doCheck = false; 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; - maintainers = [ maintainers.tailhook ]; + license = with licenses; [ mit unlicense ]; + maintainers = with maintainers; [ tailhook ]; }; } ``` Follow the below steps to try that snippet. -1. create a new directory 1. save the above snippet as `default.nix` in that directory -1. cd into that directory and run `nix-build` - -### 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 [the manual on installing overlays](#sec-overlays-install). - -### Declarative Rust overlay installation {#declarative-rust-overlay-installation} - -This snippet shows how to use oxalica's Rust overlay. -Add the following to your `configuration.nix`, `home-configuration.nix`, `shell.nix`, or similar: - -```nix -{ pkgs ? import <nixpkgs> { - overlays = [ - (import (builtins.fetchTarball "https://github.com/oxalica/rust-overlay/archive/master.tar.gz")) - # Further overlays go here - ]; - }; -}; -``` +2. cd into that directory and run `nix-build` -Note that this will fetch the latest overlay version when rebuilding your system. +Fenix also has examples with `buildRustPackage`, +[crane](https://github.com/ipetkov/crane), +[naersk](https://github.com/nix-community/naersk), +and cross compilation in its [Examples](https://github.com/nix-community/fenix#examples) section. |