-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrust.nix
77 lines (67 loc) · 2.34 KB
/
rust.nix
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
{ config, lib, pkgs, inputs, ... }:
let
inherit (inputs.self.lib) toTOML;
cargoConfig = {
install.root = "${config.home.homeDirectory}/.local";
build.target-dir = "${config.xdg.cacheHome}/cargo/target";
target."${pkgs.rust.toRustTarget pkgs.stdenv.hostPlatform}".linker = gcc-lld;
};
# Seems it reject missing fields.
# https://github.com/rustsec/rustsec/blob/5058319167c0a86eae7bf25ebc820a8eefeb1c55/cargo-audit/audit.toml.example
cargoAudit = {
database = {
path = "${config.xdg.cacheHome}/cargo/advisory-db";
url = "https://github.com/RustSec/advisory-db.git";
fetch = true;
stale = false;
};
};
# `--no-rosegment` is required for flamegraph
# https://github.com/flamegraph-rs/flamegraph#cargo-flamegraph
gcc-lld = pkgs.writeShellScript "gcc-lld" ''
export PATH="${pkgs.llvmPackages_latest.bintools}/bin''${PATH:+:}$PATH"
exec ${lib.getExe pkgs.gcc} -fuse-ld=lld -Wl,--no-rosegment "$@"
'';
in {
home.packages = with pkgs; with inputs.rust-overlay.packages.${pkgs.system}; [
(lib.hiPrio rust-nightly.availableComponents.rustfmt)
(rust.override {
extensions = [
"rust-src"
];
targets = [
"aarch64-apple-darwin"
"riscv64gc-unknown-linux-gnu"
"wasm32-unknown-unknown"
"x86_64-pc-windows-msvc"
];
})
cargo-audit
cargo-bloat
cargo-flamegraph
cargo-hack
cargo-insta
cargo-license
cargo-machete
cargo-outdated
cargo-show-asm
];
# Setup cargo directories.
# https://doc.rust-lang.org/cargo/commands/cargo.html?highlight=cargo_home#files
home.sessionVariables."CARGO_HOME" = "${pkgs.runCommandLocal "cargo-home" {
cargoConfig = toTOML cargoConfig;
cargoAudit = toTOML cargoAudit;
} ''
mkdir -p $out
ln -st $out "${config.xdg.cacheHome}"/cargo/{registry,git}
ln -st $out "${config.xdg.configHome}"/cargo/credentials.toml
echo -n "$cargoConfig" >$out/config.toml
echo -n "$cargoAudit" >$out/audit.toml
''}";
home.activation.setupCargoDirectories = lib.hm.dag.entryAfter [ "writeBoundary" ] ''
$DRY_RUN_CMD mkdir -p "${config.xdg.configHome}"/cargo "${config.xdg.cacheHome}"/cargo/{registry,git}
if [[ ! -e "${config.xdg.configHome}"/cargo/credentials.toml ]]; then
$DRY_RUN_CMD touch -a "${config.xdg.configHome}"/cargo/credentials.toml
fi
'';
}