From d722e2175ef826cd60f05608fb7d58aa82261549 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 5 Jul 2019 01:01:18 +0200 Subject: [PATCH] Include cargo dependencies in the Nix tarball --- nix-rust/local.mk | 4 +++- release.nix | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/nix-rust/local.mk b/nix-rust/local.mk index c69e3b9ea..ce88fa51b 100644 --- a/nix-rust/local.mk +++ b/nix-rust/local.mk @@ -4,4 +4,6 @@ libnixrust_LDFLAGS_USE := -L$(d)/target/release -lnixrust -ldl libnixrust_LDFLAGS_USE_INSTALLED := $(libnixrust_LDFLAGS_USE) $(d)/target/release/libnixrust.a: $(wildcard $(d)/src/*.rs) $(d)/Cargo.toml - $(trace-gen) cd nix-rust && RUSTC_BOOTSTRAP=1 cargo build --release && touch target/release/libnixrust.a + $(trace-gen) cd nix-rust && CARGO_HOME=$$(if [[ -d vendor ]]; then echo vendor; fi) cargo build --release -Z offline && touch target/release/libnixrust.a + +dist-files += $(d)/vendor diff --git a/release.nix b/release.nix index 1d7c2e2d6..64aa35e11 100644 --- a/release.nix +++ b/release.nix @@ -10,6 +10,43 @@ let jobs = rec { + # Create a "vendor" directory that contains the crates listed in + # Cargo.lock, and include it in the Nix tarball. This allows Nix + # to be built without network access. + vendoredCrates = + let + lockFile = builtins.fromTOML (builtins.readFile nix-rust/Cargo.lock); + + files = map (pkg: import { + url = "https://crates.io/api/v1/crates/${pkg.name}/${pkg.version}/download"; + sha256 = lockFile.metadata."checksum ${pkg.name} ${pkg.version} (registry+https://github.com/rust-lang/crates.io-index)"; + }) (builtins.filter (pkg: pkg.source or "" == "registry+https://github.com/rust-lang/crates.io-index") lockFile.package); + + in pkgs.runCommand "cargo-vendor-dir" {} + '' + mkdir -p $out/vendor + + cat > $out/vendor/config < "$dir/.cargo-checksum.json" + + mv "$dir" $out/vendor/ + rmdir $out/vendor/tmp + '') files)} + ''; + tarball = with pkgs; @@ -38,6 +75,8 @@ let distPhase = '' + cp -prd ${vendoredCrates}/vendor/ nix-rust/vendor/ + runHook preDist make dist mkdir -p $out/tarballs