Configure rustup toolchain, cargo credentials, and put dependencies under cargo.

This commit is contained in:
Tom Alexander 2025-02-01 15:45:58 -05:00
parent 64e735abbf
commit 3ed43b1b8a
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
2 changed files with 93 additions and 5 deletions

View File

@ -1,3 +1,6 @@
# MANUAL: rustup target add x86_64-unknown-linux-musl
# MANUAL: rustup target add wasm32-unknown-unknown
# MANUAL: rustup component add rustc-codegen-cranelift
{
config,
lib,
@ -5,6 +8,14 @@
...
}:
let
cargo_wrapped =
package: prog:
pkgs.writeShellScriptBin "${prog}" ''
export PATH="$PATH:${lib.makeBinPath [ pkgs.clang ]}"
exec ${package}/bin/${prog} "''${@}"
'';
in
{
imports = [ ];
@ -37,17 +48,89 @@
".cargo/config.toml" = {
source = ./files/cargo_config.toml;
};
# # TODO: Figure out what to do with credentials.
# ".cargo/credentials.toml" = {
# source = ./files/cargo_credentials.toml;
# };
".rustup/settings.toml" = {
source = ./files/rustup_settings.toml;
};
};
};
environment.persistence."/state" = lib.mkIf (!config.me.buildingIso) {
hideMounts = true;
users.talexander = {
directories = [
{
directory = ".rustup";
user = "talexander";
group = "talexander";
mode = "0755";
}
{
directory = ".cargo/registry";
user = "talexander";
group = "talexander";
mode = "0755";
}
];
};
};
systemd.services.link-rust-creds = {
# Contains credentials so it cannot be added to the nix store
enable = true;
description = "link-rust-creds";
wantedBy = [ "multi-user.target" ];
wants = [ "multi-user.target" ];
after = [ "multi-user.target" ];
# path = with pkgs; [
# zfs
# ];
unitConfig.DefaultDependencies = "no";
serviceConfig = {
Type = "oneshot";
RemainAfterExit = "yes";
};
script = ''
if [ -e /persist/manual/rust/cargo_credentials.toml ]; then
install --directory --owner talexander --group talexander --mode 0755 /home/talexander/.cargo
ln -s /persist/manual/rust/cargo_credentials.toml /home/talexander/.cargo/credentials.toml
fi
'';
preStop = ''
rm -f /home/talexander/.cargo/credentials.toml
'';
};
nixpkgs.overlays = [
(final: prev: {
rustup = pkgs.symlinkJoin {
name = "rustup";
paths =
(builtins.map (cargo_wrapped prev.rustup) [
"cargo"
"cargo-clippy"
"cargo-fmt"
"cargo-miri"
"clippy-driver"
"rls"
"rust-analyzer"
"rust-gdb"
"rust-gdbgui"
"rust-lldb"
"rustc"
"rustdoc"
"rustfmt"
"rustup"
])
++ [
prev.rustup
];
buildInputs = [ pkgs.makeWrapper ];
};
})
];
}
]
);
}
# TODO: Install clippy, cranelift, rust-src
# TODO: Install rust targets x86_64-unknown-linux-musl and wasm32-unknown-unknown

View File

@ -0,0 +1,5 @@
default_toolchain = "nightly-x86_64-unknown-linux-gnu"
profile = "default"
version = "12"
[overrides]