nix-community / fenix

Rust toolchains and rust-analyzer nightly for Nix [maintainer=@figsoda]
Mozilla Public License 2.0
608 stars 39 forks source link

How to use the Rust book? #113

Closed LoganBarnett closed 11 months ago

LoganBarnett commented 11 months ago

When I have rustup installed as its own package (fenix doesn't seem to supply it?) I get this outcome when trying to bring up the docs:

$ rustup doc --book  
info: `rust-docs` not installed in toolchain `stable-aarch64-apple-darwin`
info: To install, try `rustup component add --toolchain stable-aarch64-apple-darwin rust-docs`
error: unable to view documentation which is not installed

However when I remove rustup (since fenix is trying to be a rustup replacement), I don't have rustup available at all. I do think I have the right component(s) added. How should I go about doing an equivalent of rustup doc --book?

This is my overlay:

self: super: {
  fenix = (super.fenix or {}) //
    (super.callPackage
      (super.fetchFromGitHub {
        owner = "nix-community";
        repo = "fenix";
        # Commit from 2023-07-18.
        rev = "cb4ed6a92123dd8e3befdf0fbed27c9ebb8e7176";
        hash = "sha256-jK8m0FKjlI99iOOdor87yOjDHt8QsL/J/eMeCOzHJMM=";
      })
      { }
    );
}

In my packages list:

  (pkgs.fenix.complete.withComponents [
    "cargo"
    "clippy"
    "rust-docs"
    "rust-std"
    "rustfmt"
    "rust-src"
  ])

I don't necessarily need complete or any other toolchain as far as I know - I'm just trying to rule out overly aggressive pruning that might remove what I'm trying to add.

Thanks for all the work on this project!

Edit: The hash suddenly became relevant again, fixed to reflect that. Should be immaterial to the ticket though :)

figsoda commented 11 months ago

There is currently no CLI for fenix, so you would need to manually open the html file or write your wrapper. The book is in share/doc/rust/html/book/index.html of the rust-docs component, so you can either use just the component itself or with the toolchain you created with withComponents

LoganBarnett commented 11 months ago

Thanks so much! That's the missing piece I needed.

For posterity, I used fd to find the package in my nix store. There were actually quite a few matches, but I just took the first dir that showed up.

Example:

$ fd rust-docs /nix/store
/nix/store/p3f6gyn7lcmxpplvs4yd0fyjyh5la0rr-rust-docs-nightly-complete-2023-03-03/
/nix/store/gbrrv2fxgp7pb1hfnd23bvjmrkrcmlfs-rust-docs-nightly-default-2023-03-03.drv
/nix/store/bjzjg8451qzap2fj6gim92bpx5v4c7ah-rust-docs-nightly-x86_64-apple-darwin.tar.gz.drv
/nix/store/s6ac37206z94f7lp7207nx9jmcw9rya7-rust-docs-nightly-complete-2023-07-18.drv
/nix/store/ji2ncgziys0ynkggfncqn5zw6482ckdi-rust-docs-nightly-default-2023-03-03/
/nix/store/4fl71cyh75lszmh1dnwzrzfwb6wk8y3f-rust-docs-nightly-x86_64-apple-darwin.tar.gz
/nix/store/v14kwi8glwc4xvryfqvj3sy4nay7i5ca-rust-docs-nightly-default-2023-07-18/
/nix/store/791h39cfbgi06m3mimy2ymd6fc04bhhf-rust-docs-nightly-complete-2023-07-18/
/nix/store/0nxsralp42vi3dqkfkfry5f6zzswic2v-rust-docs-nightly-complete-2023-03-03.drv
/nix/store/bf5k7c5xkihb3c1x2s3arnfchnsmhfn3-rust-docs-nightly-x86_64-apple-darwin.tar.gz.drv
^C

Then append the path @figsoda provided to the end of that, and on macOS, it's just open. I forget what the X windows equivalent is in Linux.

$ open /nix/store/p3f6gyn7lcmxpplvs4yd0fyjyh5la0rr-rust-docs-nightly-complete-2023-03-03/share/doc/rust/html/book/index.html

Since this is all I need, I'm closing this ticket. Thanks again!