Skip to content

Commit 9003cd9

Browse files
committed
introduce language.rust
1 parent 7e3c703 commit 9003cd9

2 files changed

Lines changed: 55 additions & 0 deletions

File tree

modules_extra/language/rust.nix

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{ lib, config, pkgs, ... }:
2+
let
3+
cfg = config.language.rust;
4+
in
5+
with lib;
6+
{
7+
options.language.rust = {
8+
packageSet = mkOption {
9+
# FIXME: how to make the selection possible in TOML?
10+
type = types.attrs;
11+
default = pkgs.rustPackages;
12+
defaultText = "pkgs.rustPlatform";
13+
description = "Which rust package set to use";
14+
};
15+
16+
tools = mkOption {
17+
type = types.listOf types.str;
18+
default = [
19+
"rustc"
20+
"cargo"
21+
"clippy"
22+
"rustfmt"
23+
];
24+
description = "Which rust tools to pull from the platform package set";
25+
};
26+
};
27+
28+
config = {
29+
env = [{
30+
# Used by tools like rust-analyzer
31+
name = "RUST_SRC_PATH";
32+
value = toString cfg.packageSet.rustPlatform.rustLibSrc;
33+
}];
34+
35+
devshell.packages = map (tool: cfg.packageSet.${tool}) cfg.tools;
36+
};
37+
}

tests/extra/language.rust.nix

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{ pkgs, devshell, runTest }:
2+
{
3+
# Basic test
4+
simple =
5+
let
6+
shell = devshell.mkShell {
7+
imports = [ ../../modules_extra/language/rust.nix ];
8+
devshell.name = "language-rust-simple";
9+
};
10+
in
11+
runTest "simple" { } ''
12+
# Load the devshell
13+
source ${shell}
14+
15+
# Has a rust compiler
16+
type -p rustc
17+
'';
18+
}

0 commit comments

Comments
 (0)