aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2019-07-05 01:01:18 +0200
committerEelco Dolstra <edolstra@gmail.com>2019-11-26 22:07:28 +0100
commitd722e2175ef826cd60f05608fb7d58aa82261549 (patch)
tree13eb9f32a6ee30e1222cbd77177a904978f4ef2c
parent0dbb249b36f1d058e63982d26746fde48911cce4 (diff)
Include cargo dependencies in the Nix tarball
-rw-r--r--nix-rust/local.mk4
-rw-r--r--release.nix39
2 files changed, 42 insertions, 1 deletions
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 <nix/fetchurl.nix> {
+ 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 <<EOF
+ [source.crates-io]
+ replace-with = "vendored-sources"
+
+ [source.vendored-sources]
+ directory = "vendor"
+ EOF
+
+ ${toString (builtins.map (file: ''
+ mkdir $out/vendor/tmp
+ tar xvf ${file} -C $out/vendor/tmp
+ dir=$(echo $out/vendor/tmp/*)
+
+ # Add just enough metadata to keep Cargo happy.
+ printf '{"files":{},"package":"${file.outputHash}"}' > "$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