# 2. Getting Started > **Reference:** Donis Marshall, *Programming with Rust* (2024) — Chapter 2 > **Phase:** 1 (Basics & Tooling) | **Code:** *(add crate/file link as you go)* ## 1. Mental Model (My Own Words) - **Core idea:** Getting a working Rust toolchain, compiling with `rustc` vs. managing projects with `cargo`, and understanding the entry point (`main`), libraries, comments, and CLI arguments. - **Installing Rust on NixOS (instead of `rustup`):** - On macOS/Windows/traditional Linux, `rustup` downloads toolchains into `~/.cargo/bin` and switches between `stable`, `beta`, and `nightly`. - On NixOS, **Home Manager** manages the global toolchain declaratively in `~/Config/home/dev.nix` (`cargo`, `rustc`, `rustfmt`, `clippy`, `rust-analyzer`, and `gcc` as linker, exposed in `/etc/profiles/per-user/$USER/bin/`). Installing `rustup` alongside Nix-managed binaries is redundant and risks `PATH` shadowing. - **Per-project overrides:** When a project needs a pinned Rust version or cross-compilation targets (what the book calls "Advanced Rustup"), use a per-project `flake.nix` `devShell` instead of `rustup toolchain`. - **User-installed binaries:** `~/.cargo/bin` stays on `PATH` for tools installed via `cargo install`. - **Remaining Chapter 2 topics to distill as I read:** - `rustc` direct compile vs. `cargo new` / `cargo build` / `cargo run` - Binary (`src/main.rs`) vs. Library (`src/lib.rs`) crates and published crates (`crates.io`) - `main()` signatures, doc comments (`///`), and `std::env::args()` ## 2. Break-It Experiments *Ideas to test in `cargo` as I work through the chapter:* - **Experiment 1 (`rustc` vs `cargo`):** Compile a standalone `hello.rs` with `rustc`, then create a Cargo package and compare what `Cargo.toml` / `target/` generate. - **Result / `rustc` message:** *(fill in)* - **Takeaway:** *(fill in)* - **Experiment 2 (Tooling checks):** Run `rustc --version`, `cargo --version`, `cargo clippy`, and `cargo fmt --check` on a tiny crate. - **Result:** *(fill in)* - **Takeaway:** *(fill in)* ## 3. Friction Log ("Gotchas") - **NixOS `clippy` binary name:** `which clippy` fails because the subcommand binary is `cargo-clippy`—always invoke it as `cargo clippy`. - *(Add compiler/Cargo gotchas here as you hit them.)* ## 4. Recall Prompts (Answer Without Looking) 1. Why do we avoid `rustup` on NixOS when Home Manager already provides `rustc` and `cargo`, and what replaces `rustup` for pinned per-project toolchains? 2. What is the difference between running `rustc main.rs` directly vs. `cargo run`? 3. Where do `cargo install` binaries live, and how does `PATH` find them?