Skip to content

Commit e93ca35

Browse files
authored
Merge pull request #2011 from cachix/fix-rust-hooks-with-custom-toolchain
rust: expose `toolchainPackage` and use it correctly override git hooks
2 parents ee0fd5c + 9e8d80b commit e93ca35

File tree

3 files changed

+51
-5
lines changed

3 files changed

+51
-5
lines changed

docs/reference/options.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15648,6 +15648,23 @@ null or package
1564815648

1564915649

1565015650

15651+
## languages.rust.toolchainPackage
15652+
15653+
15654+
15655+
The aggregated toolchain package, which includes the configured components and targets.
15656+
This is automatically set based on the channel and components configuration.
15657+
15658+
15659+
15660+
*Type:*
15661+
package
15662+
15663+
*Declared by:*
15664+
- [https://github.com/cachix/devenv/blob/main/src/modules/languages/rust.nix](https://github.com/cachix/devenv/blob/main/src/modules/languages/rust.nix)
15665+
15666+
15667+
1565115668
## languages.rust.version
1565215669

1565315670

docs/supported-languages/rust.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,20 @@ null or package
229229

230230

231231

232+
### languages\.rust\.toolchainPackage
233+
234+
235+
236+
The aggregated toolchain package, which includes the configured components and targets\.
237+
This is automatically set based on the channel and components configuration\.
238+
239+
240+
241+
*Type:*
242+
package
243+
244+
245+
232246
### languages\.rust\.version
233247

234248

src/modules/languages/rust.nix

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ in
9494
defaultText = lib.literalExpression "nixpkgs";
9595
description = "Rust component packages. May optionally define additional components, for example `miri`.";
9696
};
97+
98+
toolchainPackage = lib.mkOption {
99+
type = lib.types.package;
100+
description = ''
101+
The aggregated toolchain package, which includes the configured components and targets.
102+
This is automatically set based on the channel and components configuration.
103+
'';
104+
};
97105
};
98106

99107
config = lib.mkIf cfg.enable (lib.mkMerge [
@@ -163,14 +171,20 @@ in
163171
CFLAGS = lib.optionalString pkgs.stdenv.isDarwin "-iframework ${config.devenv.profile}/Library/Frameworks";
164172
};
165173

166-
git-hooks.tools.cargo = mkOverrideTools cfg.toolchain.cargo or null;
167-
git-hooks.tools.rustfmt = mkOverrideTools cfg.toolchain.rustfmt or null;
168-
git-hooks.tools.clippy = mkOverrideTools cfg.toolchain.clippy or null;
174+
git-hooks.tools.cargo = mkOverrideTools cfg.toolchainPackage;
175+
git-hooks.tools.rustfmt = mkOverrideTools cfg.toolchainPackage;
176+
git-hooks.tools.clippy = mkOverrideTools cfg.toolchainPackage;
169177
}
170178
)
171179

172180
(lib.mkIf (cfg.channel == "nixpkgs") {
173-
packages = builtins.map (c: cfg.toolchain.${c} or (throw "toolchain.${c}")) cfg.components;
181+
languages.rust.toolchainPackage = lib.mkDefault (
182+
pkgs.symlinkJoin {
183+
name = "rust-toolchain-${cfg.channel}";
184+
paths = builtins.map (c: cfg.toolchain.${c} or (throw "toolchain.${c}")) cfg.components;
185+
}
186+
);
187+
packages = [ cfg.toolchainPackage ];
174188
})
175189

176190
(lib.mkIf (cfg.channel != "nixpkgs") (
@@ -245,7 +259,8 @@ in
245259
in
246260
{
247261
languages.rust.toolchain = builtins.mapAttrs (_: lib.mkDefault) toolchainComponents;
248-
packages = [ profile ];
262+
languages.rust.toolchainPackage = lib.mkDefault profile;
263+
packages = [ cfg.toolchainPackage ];
249264
}
250265
))
251266
]);

0 commit comments

Comments
 (0)