crane/examples/build-std/flake.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

85 lines
2.8 KiB
Nix
Raw Normal View History

{
description = "Build a cargo project while also compiling the standard library";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
crane.url = "github:ipetkov/crane";
flake-utils.url = "github:numtide/flake-utils";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, crane, flake-utils, rust-overlay, ... }:
flake-utils.lib.eachSystem [ "x86_64-linux" ] (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ (import rust-overlay) ];
};
rustToolchainFor = p: p.rust-bin.selectLatestNightlyWith (toolchain: toolchain.default.override {
extensions = [ "rust-src" ];
targets = [ "x86_64-unknown-linux-gnu" ];
});
rustToolchain = rustToolchainFor pkgs;
# NB: we don't need to overlay our custom toolchain for the *entire*
# pkgs (which would require rebuidling anything else which uses rust).
# Instead, we just want to update the scope that crane will use by appending
# our specific toolchain there.
craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchainFor;
src = craneLib.cleanCargoSource ./.;
my-crate = craneLib.buildPackage {
inherit src;
strictDeps = true;
cargoVendorDir = craneLib.vendorMultipleCargoDeps {
inherit (craneLib.findCargoFiles src) cargoConfigs;
cargoLockList = [
./Cargo.lock
# Unfortunately this approach requires IFD (import-from-derivation)
# otherwise Nix will refuse to read the Cargo.lock from our toolchain
# (unless we build with `--impure`).
#
# Another way around this is to manually copy the rustlib `Cargo.lock`
# to the repo and import it with `./path/to/rustlib/Cargo.lock` which
# will avoid IFD entirely but will require manually keeping the file
# up to date!
Update internal flake.lock (#679) * test/flake.lock: Update Flake lock file updates: • Updated input 'advisory-db': 'github:rustsec/advisory-db/0e7413f7941015a388b58730a53bf2529f50ab14' (2024-07-23) → 'github:rustsec/advisory-db/201638b35a3e85b7794e84cc73f876d7a2b7ad51' (2024-08-16) • Updated input 'crane': 'github:ipetkov/crane/0081e9c447f3b70822c142908f08ceeb436982b8' (2024-07-23) → 'github:ipetkov/crane/4c6c77920b8d44cd6660c1621dea6b3fc4b4c4f4' (2024-08-06) • Updated input 'fenix': 'github:nix-community/fenix/31cd6d83e0e3900f10053daf33bd878792946282' (2024-07-24) → 'github:nix-community/fenix/73b4e46c0f6e93b104f5a9c9573bd2ad0e319061' (2024-08-18) • Updated input 'fenix/rust-analyzer-src': 'github:rust-lang/rust-analyzer/eb5da56d839ae0a9e9f50774fa3eb78eb0964550' (2024-07-23) → 'github:rust-lang/rust-analyzer/fa003262474185fd62168379500fe906b331824b' (2024-08-17) • Updated input 'nixpkgs': 'github:NixOS/nixpkgs/2e19d60f8f7ad31c7991ac040e7b24c4f1a59bbe' (2024-07-24) → 'github:NixOS/nixpkgs/38fb99e12ff992a05641086dba26d1a5849929d1' (2024-08-18) • Updated input 'nixpkgs-darwin': 'github:NixOS/nixpkgs/ea73e7ae9dea53d112cb08fb78f4e00d1f686c54' (2024-07-22) → 'github:NixOS/nixpkgs/1cbd3d585263dc620c483e138d352a39b9f0e3ec' (2024-08-17) • Updated input 'rust-overlay': 'github:oxalica/rust-overlay/a6afdaab4a47d6ecf647a74968e92a51c4a18e5a' (2024-07-24) → 'github:oxalica/rust-overlay/456e78a55feade2c3bc6d7bc0bf5e710c9d86120' (2024-08-18) * examples/build-std: fix build
2024-08-18 21:36:20 +03:00
"${rustToolchain.passthru.availableComponents.rust-src}/lib/rustlib/src/rust/library/Cargo.lock"
];
};
cargoExtraArgs = "-Z build-std --target x86_64-unknown-linux-gnu";
buildInputs = [
# Add additional build inputs here
];
};
in
{
checks = {
inherit my-crate;
};
packages.default = my-crate;
2023-09-03 20:33:10 +03:00
devShells.default = craneLib.devShell {
# Inherit inputs from checks.
checks = self.checks.${system};
# Extra inputs can be added here; cargo and rustc are provided by default
# from the toolchain that was specified earlier.
packages = [
];
};
});
}