Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/edolstra/import-cargo
A function for fetching the crates listed in a Cargo lock file
https://github.com/edolstra/import-cargo
Last synced: 3 months ago
JSON representation
A function for fetching the crates listed in a Cargo lock file
- Host: GitHub
- URL: https://github.com/edolstra/import-cargo
- Owner: edolstra
- Created: 2019-07-05T14:55:00.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-04-04T20:34:27.000Z (almost 3 years ago)
- Last Synced: 2024-08-03T01:37:47.632Z (6 months ago)
- Language: Nix
- Homepage:
- Size: 5.86 KB
- Stars: 51
- Watchers: 6
- Forks: 12
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# `import-cargo`
Simple [flake](https://www.tweag.io/blog/2020-05-25-flakes/) to import all dependencies from
a [`Cargo.lock`](https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html)
as [fixed-output derivation](https://nixos.org/nix/manual/#fixed-output-drvs) using the
checksum and URL from the lockfile.## Usage
This example demonstrates how to build a local Cargo project with a
`flake.nix`:``` nix
{
description = "My Rust project";inputs = {
nixpkgs.url = github:NixOS/nixpkgs/nixos-20.03;
import-cargo.url = github:edolstra/import-cargo;
};outputs = { self, nixpkgs, import-cargo }: let
inherit (import-cargo.builders) importCargo;
in {
defaultPackage.x86_64-linux =
with import nixpkgs { system = "x86_64-linux"; };
stdenv.mkDerivation {
name = "testrust";
src = self;nativeBuildInputs = [
# setupHook which makes sure that a CARGO_HOME with vendored dependencies
# exists
(importCargo { lockFile = ./Cargo.lock; inherit pkgs; }).cargoHome# Build-time dependencies
rustc cargo
];buildPhase = ''
cargo build --release --offline
'';installPhase = ''
install -Dm775 ./target/release/testrust $out/bin/testrust
'';};
};
}
```