Skip to content

Commit

Permalink
add buildRustPackage
Browse files Browse the repository at this point in the history
  • Loading branch information
srid committed May 26, 2024
1 parent cefde14 commit 8683adb
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
38 changes: 38 additions & 0 deletions en/buildRustPackage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# `buildRustPackage`

See official documentation on this function [here](https://github.com/NixOS/nixpkgs/blob/master/doc/languages-frameworks/rust.section.md).

{#override}
## Overriding Rust derivation

Due to the complexity of `buildRustPackage` you cannot *merely* use `overrideAttrs` to override a Rust derivation. For version changes in particular, you must also override the `cargoDeps` attribute ([see here](https://discourse.nixos.org/t/is-it-possible-to-override-cargosha256-in-buildrustpackage/4393/3)).

For example, to override `pkgs.just` to [a later release][just-zulip],


```nix
self: super: {
just = super.just.overrideAttrs (oa: rec {
name = "${oa.pname}-${version}";
version = "1.27.0";
src = super.fetchFromGitHub {
owner = "casey";
repo = oa.pname;
rev = "refs/tags/${version}";
hash = "sha256-xyiIAw8PGMgYPtnnzSExcOgwG64HqC9TbBMTKQVG97k=";
};
# Overriding `cargoHash` has no effect; we must override the resultant
# `cargoDeps` and set the hash in its `outputHash` attribute.
cargoDeps = oa.cargoDeps.overrideAttrs (super.lib.const {
name = "${name}-vendor.tar.gz";
inherit src;
outputHash = "sha256-jMurOCr9On+sudgCzIBrPHF+6jCE/6dj5E106cAL2qw=";
});
doCheck = false;
});
}
```


[just-zulip]: https://nixos.zulipchat.com/#narrow/stream/420166-offtopic/topic/just.20recipe.20grouping/near/440732100
10 changes: 7 additions & 3 deletions en/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ There are several ways to provide packaging and [[dev|development enviornment]]
Here's a simple template to begin with:
- https://github.com/srid/rust-nix-template

## `buildRustPackage`

If you just want to package a Rust program, use [[buildRustPackage]]#.

## Crane

You may also be interested in using [crane] for advanced projects. Some example projects that do this:

| Project | Description |
| --- | --- |
| Project | Description |
| ----------------------------------------------- | ------------- |
| https://github.com/srid/dioxus-desktop-template | A desktop app |
| https://github.com/srid/nixci | A CLI app |
| https://github.com/srid/nixci | A CLI app |

[crane]: https://crane.dev/

0 comments on commit 8683adb

Please sign in to comment.