summary refs log tree commit diff
path: root/pkgs/build-support/rust/import-cargo-lock.nix
diff options
context:
space:
mode:
authorDaniƫl de Kok <me@danieldk.eu>2021-09-20 18:05:08 +0200
committerGitHub <noreply@github.com>2021-09-20 18:05:08 +0200
commit24b50743482e51ad36da9368fafb5a0fe6f1ab27 (patch)
treeecbe9ffc3ea957c98794b392882bda560e49f124 /pkgs/build-support/rust/import-cargo-lock.nix
parentfa365932af1d9cbfd2398dd8abfd8738aeda67df (diff)
parentd3018c4522053afbb58cc067d4b9dec17bc034c1 (diff)
downloadnixpkgs-24b50743482e51ad36da9368fafb5a0fe6f1ab27.tar
nixpkgs-24b50743482e51ad36da9368fafb5a0fe6f1ab27.tar.gz
nixpkgs-24b50743482e51ad36da9368fafb5a0fe6f1ab27.tar.bz2
nixpkgs-24b50743482e51ad36da9368fafb5a0fe6f1ab27.tar.lz
nixpkgs-24b50743482e51ad36da9368fafb5a0fe6f1ab27.tar.xz
nixpkgs-24b50743482e51ad36da9368fafb5a0fe6f1ab27.tar.zst
nixpkgs-24b50743482e51ad36da9368fafb5a0fe6f1ab27.zip
Merge pull request #137395 from dermetfan/cargo-lock-restricted
importCargoLock: introduce alternative parameter `lockFileContents`
Diffstat (limited to 'pkgs/build-support/rust/import-cargo-lock.nix')
-rw-r--r--pkgs/build-support/rust/import-cargo-lock.nix28
1 files changed, 23 insertions, 5 deletions
diff --git a/pkgs/build-support/rust/import-cargo-lock.nix b/pkgs/build-support/rust/import-cargo-lock.nix
index 3973aff398a..fe070e9638d 100644
--- a/pkgs/build-support/rust/import-cargo-lock.nix
+++ b/pkgs/build-support/rust/import-cargo-lock.nix
@@ -2,11 +2,16 @@
 
 {
   # Cargo lock file
-  lockFile
+  lockFile ? null
+
+  # Cargo lock file contents as string
+, lockFileContents ? null
 
   # Hashes for git dependencies.
 , outputHashes ? {}
-}:
+} @ args:
+
+assert (lockFile == null) != (lockFileContents == null);
 
 let
   # Parse a git source into different components.
@@ -22,7 +27,13 @@ let
         sha = builtins.elemAt parts 4;
       } // lib.optionalAttrs (type != null) { inherit type value; };
 
-  packages = (builtins.fromTOML (builtins.readFile lockFile)).package;
+  # shadows args.lockFileContents
+  lockFileContents =
+    if lockFile != null
+    then builtins.readFile lockFile
+    else args.lockFileContents;
+
+  packages = (builtins.fromTOML lockFileContents).package;
 
   # There is no source attribute for the source package itself. But
   # since we do not want to vendor the source package anyway, we can
@@ -144,10 +155,17 @@ let
       ''
       else throw "Cannot handle crate source: ${pkg.source}";
 
-  vendorDir = runCommand "cargo-vendor-dir" {} ''
+  vendorDir = runCommand "cargo-vendor-dir" (lib.optionalAttrs (lockFile == null) {
+    inherit lockFileContents;
+    passAsFile = [ "lockFileContents" ];
+  }) ''
     mkdir -p $out/.cargo
 
-    ln -s ${lockFile} $out/Cargo.lock
+    ${
+      if lockFile != null
+      then "ln -s ${lockFile} $out/Cargo.lock"
+      else "cp $lockFileContentsPath $out/Cargo.lock"
+    }
 
     cat > $out/.cargo/config <<EOF
     [source.crates-io]