yep, more dotfiles
1{ config
2, lib
3, pkgs
4, ...
5}:
6
7let
8 cfg = config.local.fragment.rust;
9
10 toml-format = pkgs.formats.toml { };
11in
12{
13 options.local.fragment.rust.enable = lib.mkEnableOption ''
14 Rust related
15 '';
16
17 config = lib.mkIf cfg.enable {
18 # Honor the XDG specification
19 home.sessionVariables = {
20 CARGO_HOME = "${config.xdg.dataHome}/cargo";
21 RUSTUP_HOME = "${config.xdg.dataHome}/rustup";
22 };
23
24 # Add global cargo binaries to PATH
25 home.sessionPath = [ "${config.home.sessionVariables.CARGO_HOME}/bin" ];
26
27 # cargo config
28 home.file."${config.home.sessionVariables.CARGO_HOME}/config.toml".source =
29 let
30 clang = lib.getExe pkgs.llvmPackages.clang;
31 mold = lib.getExe pkgs.mold;
32
33 get-crates-io-token = pkgs.writeShellScript "get-crates-io-token" "cat ${config.age.secrets.api-crates-io.path}";
34 in
35 toml-format.generate "cargo-config" {
36 registry.global-credential-providers = [ "cargo:token-from-stdout ${get-crates-io-token}" ];
37
38 source = {
39 local-mirror.registry = "sparse+http://local.crates.io:8080/index/";
40 # crates-io.replace-with = "local-mirror";
41 };
42
43 target = {
44 x86_64-unknown-linux-gnu = {
45 linker = clang;
46 rustflags = [ "-Clink-arg=--ld-path=${mold}" "-Ctarget-cpu=native" ];
47 };
48 x86_64-apple-darwin.rustflags = [ "-Ctarget-cpu=native" ];
49 aarch64-apple-darwin.rustflags = [ "-Ctarget-cpu=native" ];
50 };
51
52 unstable.gc = true;
53 };
54 };
55}
56