44 lines
1.1 KiB
Nix
44 lines
1.1 KiB
Nix
{ depot, pkgs, lib, ... }:
|
|
{ name, src, crateName ? "", depsHash, crate2nixArgs ? {} }:
|
|
let
|
|
inherit (depot.third_party) crate2nix;
|
|
keepFiles = [ ./Cargo.toml ./Cargo.lock ];
|
|
deps = pkgs.stdenv.mkDerivation {
|
|
inherit src;
|
|
name = "${name}-deps";
|
|
|
|
buildInputs = [ crate2nix ];
|
|
|
|
buildPhase = ''
|
|
mkdir /tmp/cargo
|
|
export CARGO_HOME=/tmp/cargo
|
|
|
|
mkdir /tmp/gen
|
|
cp -R $src/* /tmp/gen
|
|
|
|
cd /tmp/gen
|
|
${crate2nix}/bin/crate2nix generate
|
|
|
|
mkdir $out
|
|
cp /tmp/gen/Cargo.nix $out/Cargo.nix
|
|
cat >$out/default.nix <<EOF
|
|
{ nixpkgs ? import <nixpkgs> {} }:
|
|
let cargo_nix = nixpkgs.callPackage ./Cargo.nix { inherit nixpkgs; };
|
|
in cargo_nix.${if crateName == "" then "rootCrate" else "workspaceMembers.${crateName}"}.build
|
|
EOF
|
|
'';
|
|
|
|
installPhase = "true";
|
|
|
|
outputHash = depsHash;
|
|
outputHashMode = "recursive";
|
|
};
|
|
merged = pkgs.runCommand "${name}-merged" {
|
|
inherit src deps;
|
|
} ''
|
|
mkdir $out
|
|
cp -R $src/* $out/
|
|
cp $deps/default.nix $deps/Cargo.nix $out/
|
|
'';
|
|
in
|
|
import merged ({ nixpkgs = pkgs; } // crate2nixArgs)
|