【问题标题】:create nix store path with .cargo/registry by running 'cargo' using nix (mkDerivation or similar)通过使用 nix(mkDerivation 或类似)运行“cargo”,使用 .cargo/registry 创建 nix 存储路径
【发布时间】:2019-02-08 13:24:34
【问题描述】:

老套路

我在 nix 中有这段代码来生成 .cargo 缓存:

myVendoredSrc = pkgs.stdenv.mkDerivation {
    name = "myVendoredSrc";
    # i renamed .cargo into cargo to make this work
    src = /home/joachim/cargo;
    phases = [ "unpackPhase" "installPhase" ];
    installPhase = ''
      mkdir -p $out/.cargo
      cp -R registry $out/.cargo
    '';
  };

我在 nix-build 项目中使用这个货物缓存,如下所示:

  buildenv = import ./artiq-dev.nix {
    extraProfile = ''
      export HOME=${myVendoredSrc}
    '';
    # --no-compile-gateware to disable vivado build
    runScript = "python -m artiq.gateware.targets.kasli -V satellite --no-compile-gateware";
  };

这稍后会调用cargo build 并使用缓存而不需要连接到互联网。

在nixpkgs中有fetchcargo,见https://github.com/alexcrichton/cargo-vendor

问题

想法:弄清楚如何在我自己的 nix 文件中使用 <nixpkgs>/pkgs/build-support/rust/fetchcargo.nix...

我之前尝试过的

请不要提示我使用carnix(我尝试构建它并不能很好地工作,我还发现我不能将它用于这个项目)或buildRustPackagebuildRustCrate (同样的原因,这不能用于我正在处理的项目,因为它是一个交叉编译器设置,它是从创建多个环境变量的 python 脚本设置的)

【问题讨论】:

    标签: rust nix


    【解决方案1】:

    这是我最终想出的代码:

    let 
      pkgs = import <nixpkgs> {};
      fetchcargo = import <nixpkgs/pkgs/build-support/rust/fetchcargo.nix> {
        inherit (pkgs) stdenv cacert git rust cargo-vendor;
      };
      myVendoredSrcFetchCargo = fetchcargo rec {
        name = "myVendoredSrcFetchCargo";
        sourceRoot = null;
        srcs = null;
        src = ../artiq/firmware;
        cargoUpdateHook = "";
        patches = [];
        sha256 = "1xzjn9i4rkd9124v2gbdplsgsvp1hlx7czdgc58n316vsnrkbr86";
      };
    
      myVendoredSrc = pkgs.stdenv.mkDerivation {
        name = "myVendoredSrc";
        src = myVendoredSrcFetchCargo;
        phases = [ "unpackPhase" "installPhase" ];
        installPhase = ''
          mkdir -p $out/.cargo/registry
          cat > $out/.cargo/config << EOF
            [source.crates-io]
            registry = "https://github.com/rust-lang/crates.io-index"
            replace-with = "vendored-sources"
            [source."https://github.com/m-labs/libfringe"]
            git = "https://github.com/m-labs/libfringe"
            rev = "b8a6d8f"
            replace-with = "vendored-sources"
            [source.vendored-sources]
            directory = "$out/.cargo/registry"
          EOF
          cp -R * $out/.cargo/registry
        '';
      };
    
      buildenv = import ./artiq-dev.nix { inherit pkgs; };
    
    in pkgs.stdenv.mkDerivation {
      name = "artiq-board";
      src = null;
      phases = [ "buildPhase" "installPhase" ];
      buildPhase = 
        ''
        ${buildenv}/bin/artiq-dev -c "HOME=${myVendoredSrc} python -m artiq.gateware.targets.kasli -V satellite --no-compile-gateware"
        '';
      installPhase =
        ''
        mkdir $out
        #cp artiq_kasli/satellite/gateware/top.bit $out
        cp artiq_kasli/satellite/software/bootloader/bootloader.bin $out
        cp artiq_kasli/satellite/software/satman/satman.{elf,fbi} $out
        '';
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-06
      • 2021-12-20
      • 2017-05-20
      • 1970-01-01
      • 2013-12-19
      • 2014-06-21
      • 1970-01-01
      • 2023-02-02
      相关资源
      最近更新 更多