-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathrust.nix
More file actions
88 lines (87 loc) · 2.47 KB
/
rust.nix
File metadata and controls
88 lines (87 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
{
lib,
config,
pkgs,
...
}:
let
cfg = config.language.rust;
in
{
options.language.rust = with lib; {
packageSet = mkOption {
# FIXME: how to make the selection possible in TOML?
type = types.attrs;
default = pkgs.rustPackages;
defaultText = "pkgs.rustPlatform";
description = "Which rust package set to use";
};
tools = mkOption {
type = types.listOf types.str;
default = [
"rustc"
"cargo"
"clippy"
"rustfmt"
];
description = "Which rust tools to pull from the platform package set";
};
enableDefaultToolchain = mkOption {
type = types.bool;
default = true;
defaultText = "true";
description = "Enable the default rust toolchain coming from nixpkgs";
};
};
config = {
devshell.packages =
if cfg.enableDefaultToolchain then (map (tool: cfg.packageSet.${tool}) cfg.tools) else [ ];
env = [
{
# On darwin for example enables finding of libiconv
name = "LIBRARY_PATH";
# append in case it needs to be modified
eval = "$DEVSHELL_DIR/lib";
}
{
# some *-sys crates require additional includes
name = "CFLAGS";
# append in case it needs to be modified
eval = "\"-I $DEVSHELL_DIR/include ${lib.optionalString pkgs.stdenv.isDarwin "-iframework $DEVSHELL_DIR/Library/Frameworks"}\"";
}
]
++ lib.optionals pkgs.stdenv.isDarwin [
{
# On darwin for example required for some *-sys crate compilation
name = "RUSTFLAGS";
# append in case it needs to be modified
eval = "\"-L framework=$DEVSHELL_DIR/Library/Frameworks\"";
}
{
# rustdoc uses a different set of flags
name = "RUSTDOCFLAGS";
# append in case it needs to be modified
eval = "\"-L framework=$DEVSHELL_DIR/Library/Frameworks\"";
}
{
name = "PATH";
prefix =
let
inherit (pkgs) xcbuild;
in
lib.makeBinPath [
xcbuild
"${xcbuild}/Toolchains/XcodeDefault.xctoolchain"
];
}
]
# fenix provides '.rust-src' in the 'complete' toolchain configuration
++ lib.optionals (cfg.enableDefaultToolchain && cfg.packageSet ? rust-src) [
{
# rust-analyzer may use this to quicker find the rust source
name = "RUST_SRC_PATH";
value = "${cfg.packageSet.rust-src}/lib/rustlib/src/rust/library";
}
];
};
}