Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254{types, ...}: let usingNixpkgs = inputs: inputs.rustOverlay.packages == null;in { inputs.nixpkgs.from = {parent}: parent.nixpkgs; inputs.rustOverlay.from = {parent}: parent.rustOverlay;
options = { enable = { type = types.bool; default = false; };
channel = { type = types.enum "channel" ["stable" "beta" "nightly"]; default = "stable"; description = "The rust-overlay toolchain source. Requires rust-overlay."; };
version = { type = types.string; default = "latest"; description = '' "latest", a release ("1.81.0"), or a nightly date ("2021-01-01"). A non-"latest" value resolves a pinned rust-overlay toolchain on its own, regardless of what `channel` is set to. Requires rust-overlay. ''; };
targets = { type = types.listOf types.string; defaultFunc = {inputs}: [inputs.nixpkgs.pkgs.stdenv.hostPlatform.rust.rustcTarget]; description = "rust-std targets to install. Requires rust-overlay."; };
extraTargets = { type = types.listOf types.string; default = []; };
components = { type = types.listOf types.string; default = ["clippy" "rustfmt" "rust-analyzer"]; description = '' Extra rust-overlay extensions to install alongside the toolchain's always-present rustc/cargo/rust-std. Requires rust-overlay. ''; };
extraComponents = { type = types.listOf types.string; default = []; };
package = { type = types.derivation; defaultFunc = { inputs, options, }: let inherit (inputs.nixpkgs) lib; in if usingNixpkgs inputs then assert inputs.nixpkgs.lib.assertMsg ( options.channel == "stable" && options.version == "latest" && options.targets == [inputs.nixpkgs.pkgs.stdenv.hostPlatform.rust.rustcTarget] && options.extraTargets == [] && options.components == ["clippy" "rustfmt" "rust-analyzer"] && options.extraComponents == [] ) '' ezshell(rust): languages.rust.channel/version/targets/extraTargets/ components/extraComponents require a rust-overlay flake input. Add to your own flake.nix: rust-overlay.url = "github:oxalica/rust-overlay"; ezshell.inputs.rust-overlay.follows = "rust-overlay"; ''; # `makeRustPlatform`/`buildRustPackage` (see `rustPlatform`) need # `targetPlatforms`/`badTargetPlatforms` on whatever `rustc` they're # given, but `symlinkJoin` doesn't carry those over from its inputs. # rust-overlay's own aggregation falls back to nixpkgs' rustc for # these too (see oxalica/rust-overlay's lib/mk-aggregated.nix), so # we do the same here. (inputs.nixpkgs.pkgs.symlinkJoin { name = "ezshell-rust-toolchain"; paths = with inputs.nixpkgs.pkgs; [rustc cargo rustfmt clippy]; }) // {inherit (inputs.nixpkgs.pkgs.rustc) targetPlatforms badTargetPlatforms;} else let # A bare date means "nightly, as of this date" and anything else is # passed through as a release version. pick = if options.version != "latest" then { channel = if builtins.match "[0-9]{4}-[0-9]{2}-[0-9]{2}" options.version != null then "nightly" else "stable"; key = options.version; } else { inherit (options) channel; key = "latest"; }; in ( inputs.rustOverlay.packages.${ pick.channel }.${ pick.key } or (throw '' ezshell(rust): no rust-overlay toolchain found for channel "${pick.channel}", version "${pick.key}" — check that the version/date is spelled correctly and has been released. '') ) .minimal.override { extensions = lib.unique (options.components ++ options.extraComponents); targets = lib.unique (options.targets ++ options.extraTargets); }; };
rustPlatform = { type = types.attrs; defaultFunc = { inputs, options, }: inputs.nixpkgs.pkgs.makeRustPlatform { rustc = options.package; cargo = options.package; }; description = '' `pkgs.makeRustPlatform` built from the resolved `package` toolchain. This shouldn't be overriden. ''; };
lsp = { options = { enable = { type = types.bool; default = true; }; package = { type = types.derivation; description = '' defaults to nixpkgs' rust-analyzer without rust-overlay, or `options.package` with rust-overlay. ''; defaultFunc = { inputs, options, }: if usingNixpkgs inputs then inputs.nixpkgs.pkgs.rust-analyzer else options.package; }; }; };
extraPackages = { type = types.listOf types.derivation; default = []; };
hooks = { type = types.attrsOf types.hook; defaultFunc = { inputs, options, }: let hasComponent = name: usingNixpkgs inputs || builtins.elem name (options.components ++ options.extraComponents); in ( if hasComponent "rustfmt" then { rustfmt = { entry = "${options.package}/bin/rustfmt"; args = ["--check"]; files = "\\.rs$"; stages = ["pre-push"]; }; } else {} ) // ( if hasComponent "clippy" then { # cargo dispatches `clippy` to `cargo-clippy` via PATH clippy = { entry = "${options.package}/bin/cargo"; args = ["clippy" "--" "-D" "warnings"]; path = [options.package]; files = "\\.rs$"; pass_filenames = false; always_run = true; stages = ["pre-push"]; }; } else {} ); }; };
impl = { inputs, options, }: ( if !options.enable then {} else assert inputs.nixpkgs.lib.assertMsg ( usingNixpkgs inputs || !options.lsp.enable || builtins.elem "rust-analyzer" (options.components ++ options.extraComponents) ) '' ezshell(rust): languages.rust.lsp.enable is true, but "rust-analyzer" is in neither languages.rust.components nor languages.rust.extraComponents, so no rust-analyzer will actually be installed. Add "rust-analyzer" to `components`, or set `lsp.enable = false`. ''; { packages = [options.package] ++ ( # Under rust-overlay, `lsp.package` defaults to aliasing # `package` (already in the list above). Only add it # separately when it actually resolves to a different # derivation. if options.lsp.enable && options.lsp.package.outPath != options.package.outPath then [options.lsp.package] else [] ) ++ options.extraPackages;
hookPresets = builtins.listToAttrs ( map (name: { name = "rust-${name}"; value = options.hooks.${name}; }) (builtins.attrNames options.hooks) ); } ) // {inherit options;};
meta.maintainers = ["poacherGoneWild@proton.me"];}