Rust: Difference between revisions
imported>Asymmetric |
imported>Asymmetric →FAQ: Add instructions using makeRustPlatform |
||
Line 253: | Line 253: | ||
Note that you need to use a <code>nix-shell</code> environment. Installing the Nix packages <code>openssl</code> or <code>sqlite</code> globally under <code>systemPackages</code> in NixOS or in <code>nix-env</code> [https://nixos.wiki/wiki/FAQ/I_installed_a_library_but_my_compiler_is_not_finding_it._Why%3F is discouraged] and doesn't always work (<code>pkg-config</code> may not be able to locate the libraries). | Note that you need to use a <code>nix-shell</code> environment. Installing the Nix packages <code>openssl</code> or <code>sqlite</code> globally under <code>systemPackages</code> in NixOS or in <code>nix-env</code> [https://nixos.wiki/wiki/FAQ/I_installed_a_library_but_my_compiler_is_not_finding_it._Why%3F is discouraged] and doesn't always work (<code>pkg-config</code> may not be able to locate the libraries). | ||
=== Building with a different Rust version than the one in Nixpkgs === | |||
The following uses the [https://github.com/nix-community/fenix fenix] overlay and <code>makeRustPlatform</code> to build a crate with Rust nightly: | |||
<syntaxHighlight lang=nix> | |||
{ | |||
inputs = { | |||
fenix = { | |||
url = "github:nix-community/fenix"; | |||
inputs.nixpkgs.follows = "nixpkgs"; | |||
}; | |||
flake-utils.url = "github:numtide/flake-utils"; | |||
nixpkgs.url = "nixpkgs/nixos-unstable"; | |||
}; | |||
outputs = { self, fenix, flake-utils, nixpkgs }: | |||
flake-utils.lib.eachDefaultSystem (system: | |||
let pkgs = nixpkgs.legacyPackages.${system}; in | |||
{ | |||
defaultPackage = (pkgs.makeRustPlatform { | |||
inherit (fenix.packages.${system}.minimal) cargo rustc; | |||
}).buildRustPackage { | |||
pname = "hello"; | |||
version = "0.1.0"; | |||
src = ./.; | |||
cargoSha256 = nixpkgs.lib.fakeSha256; | |||
}; | |||
}); | |||
} | |||
</syntaxHighlight> |