The last rust flake I will ever create (wink)
Find a file
2026-01-26 11:00:01 +00:00
.forgejo/workflows ci: re-enable ci 2026-01-24 11:04:48 +01:00
nix Merge pull request 'feat(build): add options for arguments passed only to dependencies or the binary derivation' (#13) from distinct-args into main 2026-01-26 11:00:01 +00:00
.gitignore feat: add .gitignore 2025-08-06 16:00:13 +02:00
flake.lock chore(update): 1.92 -> 1.93 2026-01-24 11:03:58 +01:00
flake.nix chore: update rust 1.90.0 -> 1.92.0 2025-12-23 09:45:46 +01:00
README.md feat(build): add options for arguments passed only to dependencies or the binary derivation 2026-01-26 11:48:22 +01:00
renovate.json chore: init repo with basic rust packages 2025-08-01 13:28:19 +02:00

nix-rust

Note: this documentations is work in progress. It mainly expalins the basics but you stil have to look into the nix code.

This projekt tries to simplify the rust toolchain for nix. It provides:

  • a build option (lib.buildRustPackage) which wraps around crane
  • a shell option (lib.mkRustShell) which provides the same rust toolchain as the builder

Additionally it provides pre-made toolchains for different use-cases:

  • android
  • wasm
  • esp targets
  • ariel

Usage

Add this projekt as a flake input:

# flake.nix
{
    inputs = {
        nix-rust.url = "git+https://git.solarpunk.social/solarpunk-kollektiv-dd/nix-rust.git";
        nix-rust.inputs.nixpkgs.follows = "nixpkgs";
    };
}

Now you can use the lib functions from nix-rust in your code.

Create a devShell

You can use nix-rust.lib.shell.mkRustShell to create a rust devShell.

# flake.nix
{
    outputs.devShells.default."x86_64-linux" = rust-nix.shell.mkRustShell {
        system = "x86_64-linux";
        base = "nativeWithOpenssl";
    };
}
Option Description Default
system nixpkgs system for this devShell "x86_64-linux"
extraDescription additionaly devShell description ""
extraPackages additionaly packages accessibly in the devShell (besides the rust toolchain) []
extraShellHook bash code to execute on shell-enter ""
base The base devShell to use. These are a combination of two parts "", where toolchain is one of native,android,wasm and tooling is one of Base,WithOpenssl,BevyX11,BevyWayland. Note that not every combination necessarily makes sense. "nativeBase"
name Name of the devShell. If set to null, the default devShell name will be used null
extraRpathPackages Packages that should be available as libaries to rust extraPackages

Create a package

You can use nix-rust.lib.build.buildRustPackage to create a nix package out of your rust code.

# flake.nix
{
    outputs.packages.default."x86_64-linux" = nix-rust.build.buildRustPackage {
        inherit pkgs;
        name = "my-programm";
        src = ./.;

        cargoLock = ./Cargo.lock;
        cargoToml = ./Cargo.toml; # version will be derived from TOML
    };
}
Option Description Default
pkgs nixpkgs to use no default
src Rust source code no default
cargoToml Nix path to a cargo.toml containing the project name & version no default
rust nix-rust rust toolchain to use nix-rust.packages.${system}.buildRust
version Version of the package version from cargo.toml (if specified)
pname Name of the package project name from cargo.toml (if specified)
binaryArgs Arguments that should be passed only to craneLib.buildDepsOnly { }
dependencyArgs Arguments that should be passed only to craneLib.buildPackage { }

Additionally options will be passed to craneLib.buildPackage.