Documentation Index
Fetch the complete documentation index at: https://flox-kanishk-copy-page-as-markdown.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
What do I need for a basic environment?
First we’ll show you the answer, and then we’ll explain. The full example environment can be found in the floxenvs repository. A manifest that provides you a Rust development environment would look like this:Rust development environment
rustup.
The main difference here is that the toolchain components are unbundled in
Flox,
so you’ll need to install cargo and rustc as independent packages.
Some common packages you’ll want to install are:
cargorustcrustfmtclippygccon Linux,clangon macOSlibiconvon macOSrustPlatform.rustLibSrcrust-analyzer
cargo is self-explanatory, it’s the default build tool for Rust.
However, all Flox packages automatically install all of their dependencies,
so cargo also installs rustc on its own.
If that’s the case, why do we need a rustc package?
The short answer is build scripts (build.rs files).
One of the ways that Flox makes environments deterministic and reproducible
is that packages don’t expose their dependencies to PATH,
so cargo doesn’t expose its rustc to PATH.
This is fine in most cases since you often don’t need to call rustc yourself,
but this becomes an issue for crates that contain build.rs build scripts that
manually invoke rustc.
However, even if your crate doesn’t have a build.rs,
it is very common for a transitive dependency to need to link to system
libraries such as openssl.
This is why we install a separate rustc package.
You may also find that you need to install a pkg-config package if some
system libraries aren’t found.
Build scripts are also why we install the gcc or clang package:
build scripts often call out to linkers in addition to rustc.
The libiconv package is necessary on macOS because the Rust standard library
links against it on macOS.
The rustPlatform.rustLibSrc provides the source code for std so that
rust-analyzer can provide diagnostics and documentation for standard library
code.
As a final step, you want to make sure that your Rust toolchain components
share the same exact versions of their dependencies,
so you’ll want to add them to a package group
(rust-toolchain in the example above).
Add the target directory to PATH
If you’re developing a binary instead of a library,
you may find it useful to add the target/debug or target/release
directories to your PATH for interactive testing.
That is very simple to do with the hook.on-activate section of the manifest:
mybin,
you could call it directly instead of via target/debug/mybin,
and it will automatically be kept up to date on every cargo build.
Add cargo aliases
The [profile] section allows you to add aliases to your development shell
that are available after activating your environment.
If you currently use make, just, or a .cargo/config.toml file to set
provide simple aliases in your development environment,
you may be able to remove those dependencies and just use the Flox manifest
instead:
How do I use nightly compilers?
Nightly compilers aren’t currently packaged in the Flox Catalog. If you need to use nightly compilers, you can use our Nix flake support to prepare a flake that provides a nightly compiler. You would need to prepare that flake, call itgithub:rust-dev/my-nightly,
and add it to the manifest as a flake package:
fenix to provide three different toolchains:
stable, which tracks the latest stable release of Rustnightly, which tracks the latest nightly release of Rustesp32-riscv-no-std, which provides a nightly toolchain with support for the ESP32-C3, a microprocessor based on the RISC-V architecture.
Build with Flox
Not only can you develop your software with Flox, but you can build it as well. See the builds concept page for more details.Manifest builds
Since the output of the build must be copied to the$out directory, you’ll need to copy the compiled executable out of the target directory and into $out.
There is an unstable environment variable in Cargo that will allow you to set the output directory of the build, but we’ll stick to stable features here:
macOS builds require libiconv
Rust executables built for macOS link against thelibiconv library, which is used for some Unicode operations.
This library is provided by macOS, and the large majority of Rust packages on macOS link against this library already, so this is not a dependency introduced by building via Flox.
For reproducibility you must include this package as a dependency rather than depending on being able to locate the library on the system at runtime.
If you build rust applications on macOS, add the following to the manifest under [install]:
manifest.toml
Linux builds require GCC
On Linux, Rust executables link againstlibgcc for stack unwinding.
libgcc is provided as part of the gcc package, which means that gcc needs to be available to your package at runtime on Linux.
This happens by default if the gcc package is installed in the toplevel (default) package group, i.e. there is no pkg-group set.
manifest.toml
runtime-packages is set for this package, gcc must be included in the list of included packages.
manifest.toml
NoteDepending on the
gcc package at runtime includes libgcc, the compiler, its manpages, etc when in reality the package only depends on libgcc at runtime on Linux. This limitation will be addressed in the future.Vendoring dependencies in pure builds
As discussed in the pure builds of the Builds concept page, pure builds run in a sandbox without network access on Linux. A pure build can be run as a multi-stage build where the first step vendors dependencies. An example is shown below:Nix expression builds
To build a project usingbuildRustPackage which will import your existing dependency file: