aboutsummaryrefslogtreecommitdiff
path: root/default.nix
blob: 31a58da662b60d7d598472760029d05c7b00bcc2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
{ pkgs, lockfile }:
let
  resolved-deps =
    (builtins.fromTOML (builtins.readFile lockfile)).package;
in {
  inherit resolved-deps;
  env = {
    vendor = let
      make-checkout = { name, version, checksum ? null, ... }:
        if checksum == null then
          null
        else
          let
            crate = builtins.fetchurl {
              url = "https://crates.io/api/v1/crates/${name}/${version}/download";
              name = "download-${name}-${version}";
              sha256 = checksum;
            };
          in
            pkgs.runCommand "download-${name}" { } ''
              mkdir $out
              tar -xzf ${crate} -C $out
              echo '{"package":"${checksum}","files":{}}' > $out/${name}-${version}/.cargo-checksum.json
            '';
    in pkgs.symlinkJoin {
      name = "cargo2nix-vendored-dependencies";
      paths = map make-checkout resolved-deps;
    };
    cargo-config = pkgs.writeText "cargo-config" ''
      [source.crates-io]
      replace-with = "vendored-sources"

      [source.vendored-sources]
      directory = "vendor"
    '';
  };
}