diff --git a/docs/reference/options.md b/docs/reference/options.md index a10955d57..a76bcc312 100644 --- a/docs/reference/options.md +++ b/docs/reference/options.md @@ -9213,8 +9213,6 @@ list of package ## git-hooks.hooks.dune-fmt.stages - - Confines the hook to run at a particular stage. @@ -11311,8 +11309,6 @@ null or signed integer ## git-hooks.hooks.flynt.settings.no-multiline - - Convert only single line expressions. @@ -13442,8 +13438,6 @@ list of string ## git-hooks.hooks.isort.description - - Description of the hook. Used for metadata purposes only. @@ -15482,8 +15476,6 @@ internal name, same as ` id ` ## git-hooks.hooks.lychee.pass_filenames - - Whether to pass filenames as arguments to the entry point. @@ -17591,8 +17583,6 @@ list of package ## git-hooks.hooks.mypy.fail_fast - - if true pre-commit will stop running hooks if this hook fails. @@ -19682,8 +19672,6 @@ list of (one of “commit-msg”, “post-checkout”, “post-commit”, “pos ## git-hooks.hooks.ormolu.types - - List of file types to run on. See [Filtering files with types](https://pre-commit.com/\#filtering-files-with-types). @@ -21801,8 +21789,6 @@ list of package ## git-hooks.hooks.prettier.fail_fast - - if true pre-commit will stop running hooks if this hook fails. @@ -23826,8 +23812,6 @@ submodule ## git-hooks.hooks.pyright.enable - - Whether to enable this pre-commit hook. @@ -34947,7 +34931,7 @@ string -List of extra [targets](https://github.com/nix-community/fenix\#supported-platforms-and-targets) +List of extra [targets](https://doc.rust-lang.org/nightly/rustc/platform-support.html) to install. Defaults to only the native target. @@ -35091,6 +35075,28 @@ null or package +## languages.rust.version + + + +Which version of rust to use, this value could be ` latest `,` 1.81.0 `, ` 2021-01-01 `. +Only works when languages.rust.channel is NOT nixpkgs. + + + +*Type:* +string + + + +*Default:* +` "latest" ` + +*Declared by:* + - [https://github.com/cachix/devenv/blob/main/src/modules/languages/rust.nix](https://github.com/cachix/devenv/blob/main/src/modules/languages/rust.nix) + + + ## languages.scala.enable diff --git a/docs/supported-languages/rust.md b/docs/supported-languages/rust.md index 5db06a345..bc489054e 100644 --- a/docs/supported-languages/rust.md +++ b/docs/supported-languages/rust.md @@ -103,7 +103,7 @@ string -List of extra [targets](https://github\.com/nix-community/fenix\#supported-platforms-and-targets) +List of extra [targets](https://doc\.rust-lang\.org/nightly/rustc/platform-support\.html) to install\. Defaults to only the native target\. @@ -223,3 +223,22 @@ null or package *Default:* ` pkgs.rustfmt ` + + + +## languages\.rust\.version + + + +Which version of rust to use, this value could be ` latest `,` 1.81.0 `, ` 2021-01-01 `\. +Only works when languages\.rust\.channel is NOT nixpkgs\. + + + +*Type:* +string + + + +*Default:* +` "latest" ` diff --git a/examples/rust-wasm-cross/devenv.yaml b/examples/rust-wasm-cross/devenv.yaml index aecda8b76..c08ccc882 100644 --- a/examples/rust-wasm-cross/devenv.yaml +++ b/examples/rust-wasm-cross/devenv.yaml @@ -1,6 +1,6 @@ inputs: - fenix: - url: github:nix-community/fenix + rust-overlay: + url: github:oxalica/rust-overlay inputs: nixpkgs: follows: nixpkgs diff --git a/examples/rust/devenv.yaml b/examples/rust/devenv.yaml index aecda8b76..c08ccc882 100644 --- a/examples/rust/devenv.yaml +++ b/examples/rust/devenv.yaml @@ -1,6 +1,6 @@ inputs: - fenix: - url: github:nix-community/fenix + rust-overlay: + url: github:oxalica/rust-overlay inputs: nixpkgs: follows: nixpkgs diff --git a/src/modules/languages/rust.nix b/src/modules/languages/rust.nix index 3aaff26f9..22182dae1 100644 --- a/src/modules/languages/rust.nix +++ b/src/modules/languages/rust.nix @@ -3,16 +3,44 @@ let cfg = config.languages.rust; - fenix = config.lib.getInput { - name = "fenix"; - url = "github:nix-community/fenix"; - attribute = "languages.rust.version"; + rust-overlay = config.lib.getInput { + name = "rust-overlay"; + url = "github:oxalica/rust-overlay"; + attribute = "languages.rust.input"; follows = [ "nixpkgs" ]; }; + + # https://github.com/nix-community/fenix/blob/cdfd7bf3e3edaf9e3f6d1e397d3ee601e513613c/lib/combine.nix + combine = name: paths: + pkgs.symlinkJoin { + inherit name paths; + postBuild = '' + for file in $(find $out/bin -xtype f -maxdepth 1); do + install -m755 $(realpath "$file") $out/bin + + if [[ $file =~ /rustfmt$ ]]; then + continue + fi + + ${lib.optionalString pkgs.stdenv.isLinux '' + if isELF "$file"; then + patchelf --set-rpath $out/lib "$file" || true + fi + ''} + + ${lib.optionalString pkgs.stdenv.isDarwin '' + install_name_tool -add_rpath $out/lib "$file" || true + ''} + done + + for file in $(find $out/lib -name "librustc_driver-*"); do + install $(realpath "$file") "$file" + done + ''; + }; in { imports = [ - (lib.mkRenamedOptionModule [ "languages" "rust" "version" ] [ "languages" "rust" "channel" ]) (lib.mkRenamedOptionModule [ "languages" "rust" "packages" ] [ "languages" "rust" "toolchain" ]) ]; @@ -34,8 +62,8 @@ in default = [ ]; defaultText = lib.literalExpression ''[ ]''; description = '' - List of extra [targets](https://github.com/nix-community/fenix#supported-platforms-and-targets) - to install. Defaults to only the native target. + List of extra [targets](https://doc.rust-lang.org/nightly/rustc/platform-support.html) + to install. Defaults to only the native target. ''; }; @@ -46,6 +74,16 @@ in description = "The rustup toolchain to install."; }; + version = lib.mkOption { + type = lib.types.str; + default = "latest"; + defaultText = lib.literalExpression ''"latest"''; + description = '' + Which version of rust to use, this value could be `latest`,`1.81.0`, `2021-01-01`. + Only works when languages.rust.channel is NOT nixpkgs. + ''; + }; + rustflags = lib.mkOption { type = lib.types.str; default = ""; @@ -101,6 +139,17 @@ in The nixpkgs channel does not support cross-compiling with targets. Use the stable, beta, or nightly channels instead. For example: + languages.rust.channel = "stable"; + ''; + } + { + assertion = cfg.channel == "nixpkgs" -> (cfg.version == "latest"); + message = '' + Cannot use `languages.rust.channel = "nixpkgs"` with `languages.rust.version`. + + The nixpkgs channel does not contain all versions required, and is + therefore not supported to be used together. + languages.rust.channel = "stable"; ''; } @@ -154,21 +203,17 @@ in (lib.mkIf (cfg.channel != "nixpkgs") ( let - rustPackages = fenix.packages.${pkgs.stdenv.system}; - fenixChannel = - if cfg.channel == "nightly" - then "latest" - else cfg.channel; - toolchain = rustPackages.${fenixChannel}; + toolchain = (rust-overlay.lib.mkRustBin { } pkgs.buildPackages)."${cfg.channel}"."${cfg.version}"; + filteredToolchain = (lib.filterAttrs (n: _: builtins.elem n toolchain._manifest.profiles.complete) toolchain); in { languages.rust.toolchain = - (builtins.mapAttrs (_: pkgs.lib.mkDefault) toolchain); + (builtins.mapAttrs (_: pkgs.lib.mkDefault) filteredToolchain); packages = [ - (rustPackages.combine ( - (map (c: toolchain.${c}) cfg.components) ++ - (map (t: rustPackages.targets.${t}.${fenixChannel}.rust-std) cfg.targets) + (combine "rust-mixed" ( + (map (c: cfg.toolchain.${c}) (cfg.components ++ [ "rust-std" ])) ++ + (map (t: toolchain._components.${t}.rust-std) cfg.targets) )) ]; } diff --git a/tests/rust/devenv.nix b/tests/rust/devenv.nix index fa7a5b7f6..cc282eacd 100644 --- a/tests/rust/devenv.nix +++ b/tests/rust/devenv.nix @@ -2,9 +2,9 @@ languages.rust.enable = true; languages.rust.mold.enable = false; enterTest = '' - if [ -n "$RUSTFLAGS" ]; then - echo "RUSTFLAGS is set, but it should not be" - exit 1 + if [ -n "''${RUSTFLAGS:-}" ]; then + echo "RUSTFLAGS is set, but it should not be" + exit 1 fi ''; }