89 lines
2.4 KiB
Nix
89 lines
2.4 KiB
Nix
{
|
|
description = "Rust Dev environment";
|
|
|
|
inputs = {
|
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
|
flake-utils.url = "github:numtide/flake-utils";
|
|
rust-overlay = {
|
|
url = "github:oxalica/rust-overlay";
|
|
inputs = {
|
|
nixpkgs.follows = "nixpkgs";
|
|
flake-utils.follows = "flake-utils";
|
|
};
|
|
};
|
|
};
|
|
|
|
outputs = { self, nixpkgs, flake-utils, rust-overlay }:
|
|
flake-utils.lib.eachDefaultSystem (system:
|
|
let
|
|
overlays = [ (import rust-overlay) ];
|
|
pkgs = import nixpkgs {
|
|
inherit system overlays;
|
|
};
|
|
|
|
rustVersion = pkgs.rust-bin.stable.latest.default;
|
|
|
|
# Packages required for rustlings
|
|
rustPackages = with pkgs; [
|
|
# Rust toolchain with extensions
|
|
(rustVersion.override {
|
|
extensions = [ "rust-src" "rust-analyzer" "clippy" "rustfmt" ];
|
|
})
|
|
|
|
# Build essentials
|
|
pkg-config
|
|
openssl.dev
|
|
|
|
# Development tools
|
|
rustlings
|
|
cargo-edit
|
|
cargo-watch
|
|
cargo-expand
|
|
cargo-audit
|
|
|
|
# IDE integration helpers
|
|
rust-analyzer
|
|
|
|
# Windows compatibility (for cross-compilation)
|
|
pkgsCross.mingwW64.buildPackages.gcc
|
|
];
|
|
|
|
# Shell environment variables
|
|
shellEnv = {
|
|
RUST_SRC_PATH = "${rustVersion}/lib/rustlib/src/rust/library";
|
|
RUSTFLAGS = "-C link-arg=-fuse-ld=gold";
|
|
RUST_BACKTRACE = "1";
|
|
PKG_CONFIG_PATH = "${pkgs.openssl.dev}/lib/pkgconfig";
|
|
};
|
|
|
|
in
|
|
{
|
|
devShells.default = pkgs.mkShell {
|
|
buildInputs = rustPackages;
|
|
|
|
shellHook = ''
|
|
echo "Rust development environment loaded!"
|
|
echo "rustc version: $(rustc --version)"
|
|
echo "cargo version: $(cargo --version)"
|
|
echo "rustlings version: $(rustlings --version)"
|
|
echo ""
|
|
echo "You can start rustlings with: rustlings watch"
|
|
|
|
mkdir -p .cargo
|
|
if [ ! -f .cargo/config.toml ]; then
|
|
cat > .cargo/config.toml << EOF
|
|
[build]
|
|
rustflags = ["-C", "link-arg=-fuse-ld=gold"]
|
|
|
|
[target.x86_64-pc-windows-gnu]
|
|
linker = "x86_64-w64-mingw32-gcc"
|
|
EOF
|
|
fi
|
|
'';
|
|
|
|
inherit (shellEnv) RUST_SRC_PATH RUSTFLAGS RUST_BACKTRACE PKG_CONFIG_PATH;
|
|
};
|
|
}
|
|
);
|
|
}
|