This is a stub repository to develop using Rust, nix and Flakes.
This is aimed to people with basic knowledge of Flakes and moderate knowledge of Nix.
See the NixOS Wiki for more information about Flakes.
The relevant sections are Basic project usage
and Flake schema
.
-
Install direnv on your system by following the instructions provided on the project page.
Important: you can skip this step if you do not intend to use direnv as it's optional.direnv
is a tool that setups your shell with the required environment variables (and tools in the case of Nix) to hack on! -
Clone the project
$ git clone git@github.com:berbiche/sample-flake-rust Cloning into 'sample-flake-rust'... direnv: error .envrc is blocked.
If you have
direnv
installed and configured for your shell you will see the following error message:direnv: error /path/sample-flake-rust/.envrc is blocked. Run `direnv allow` to approve its content
-
If you installed
direnv
then allowdirenv
to setup your shell with the required dependencies to develop$ direnv allow direnv: loading /path/sample-flake-rust/.envrc direnv: using flake
Use nix shell
to spawn a shell with cargo
and all necessary dependencies.
Within this shell you can use cargo
commands as you normally would.
If your project requires external dependencies (outside of crates.io
) then use nix run '.#my-package'
to build and run your project.
-
nix shell
: Spawns a shell with all the required development dependencies. -
nix develop
: Spawns a shell with all the dependencies needed to build the Flake you specify. Defaults to thedefaultPackage
specified inflake.nix
. -
nix run
: Builds and runs the package specified. Defaults to thedefaultPackage
specified inflake.nix
.Example:
nix run '.#hello'
will run the packagehello
specified in yourflake.nix
. -
nix build
: Builds the package specified. DefaultsExample:
nix build '.#hello'
will build the packagehello
specified in yourflake.nix
. The resulting build will be available at./result/
- Q: I build multiple binaries, how do I manage that?
- A: I don't have the answer yet