Media Library Step 1: Configuring the Back End
To create a development environment, we're going to use Nix, and build a flake.nix file that will install everything automatically for us.
Tip
Nix is optional here. If you prefer, you can install the Rust tools globally and simply use them directly.
Setting up a Nix Flake
If you decide to us Nix, follow these instructions:
-
In the command shell, create a folder fory our app and move into it.
-
Create an empty file called flake.nix.
-
Add the following to the file:
{
description = "A Rust development shell";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
{
devShells.default = pkgs.mkShell {
buildInputs = with pkgs; [
# Rust toolchain
rustc
cargo
# Common development tools
clippy
rustfmt
];
};
}
);
}
This will give you all the tools you need. Then in the same folder add a file called .envrc with this single line in it:
use flake
Next, if you're not already in the folder, switch into it.
You'll be presented with a messgae to activate direnv; go ahead and type:
direnv allow
Creating the initial cargo files
While still in the app's directory, let's create a new Cargo.toml file by typing:
cargo init
Then, using your favorite editor, update the dependencies section of the Cargo.toml file to look like this:
[package]
name = "rust_starter_project"
version = "0.1.0"
edition = "2024"
[dependencies]
axum = { version = "0.7", features = ["multipart"] }
tokio = { version = "1.0", features = ["full"] }
tower-http = { version = "0.5", features = ["cors"] }
golem-base-sdk = { git = "https://github.com/Golem-Base/rust-sdk.git" }
image = { version = "0.25", default-features = false, features = ["jpeg", "png"] }
serde_json = "1.0"
serde = "1.0"
alloy-primitives = "1.3.1"
hex = "0.4.3"
dotenvy = "0.15"
dirs = "6.0"
bytes = "1.10"
Next, add a folder called "src" under your main app's folder:
mkdir src
That's it! Our app is ready for the code.
Head to Step 2.