我正在尝试使用fetchgit从我实验室的私有GitLab服务器下载源存储库,该服务器目前已对其SSL证书进行自签名。

default.nix

with (import <nixpkgs> {});
{ test-pkg = callPackage ./test-pkg.nix {
    buildPythonPackage = python35Packages.buildPythonPackage;
    };
}


test-pkg.nix

{ buildPythonPackage,fetchgit }:

buildPythonPackage rec {
  pname = "test-pkg";
  version = "0.2.1";

  src = fetchgit {
    url = "https://gitlabserver/experiment-deployment/test-pkg";
    rev = "refs/tags/v${version}";
    sha256 = "43c2c9e5e7a16b6c88ba3088a9bfc82f7db8e13378be7c78d6c14a5f8ed05afd";
  };
}


调用nix-shell时导致错误

fatal: unable to access 'https://gitlabserver/experiment-deployment/test-pkg/': SSL certificate problem: self signed certificate


build-support/fetchgit看来,fetchgit是用mkDerivation制成的,所以我尝试使用fetchgit制作新的overrideAttrs。我传入git环境变量,以使git忽略SSL验证,期望该变量将在设置阶段初始化。

修订的default.nix

with (import <nixpkgs> {});
let fetchgit-no-verify = fetchgit.overrideAttrs { GIT_SSL_NO_VERIFY=true;} ;
in rec {
  test-pkg = callPackage ./test-pkg.nix {
    buildPythonPackage = python35Packages.buildPythonPackage;
    fetchgit = fetchgit-no-verify;
    };
}


我以为我在周末想到这一点时确实很聪明,却发现执行新错误时指出:

error: attribute 'overrideAttrs' missing, at [...]/default.nix:2:26


fetchgit中检查nix repl表示它是一个functor属性集。我花了点时间尝试进入overrideAttrs,但没有成功。再试一次,我发现git可以传递给fetchGit

修订后的default.nix

with (import <nixpkgs> {});
let git = git.overrideAttrs { GIT_SSL_NO_VERIFY=true;} ;
    fetchgit-no-verify = fetchgit.override { git=git-no-verify;} ;
in rec {
  test-pkg = callPackage ./test-pkg.nix {
    buildPythonPackage = python35Packages.buildPythonPackage;
    fetchgit = fetchgit-no-verify;
    };
}


但是新的错误:

 error: attempt to call something which is not a function but a set, at /nix/store/jmynn33vcn3mcscsch0zf46fz9wsw05y-nixpkgs-20.03pre193309.c4196cca9ac/nixpkgs/pkgs/stdenv/generic/make-derivation.nix:318:55


最后,谈到我的问题。有没有一种方法可以将环境变量添加到fetchgitgit派生?也许还有另一种连接方式-我错过了一些内置选项?我可以使用私有存储库,使用ssh并避免使用https,但是由于我们如何部署实验,我希望避免这种情况。

最佳答案

我能够用这个丑陋的东西来做这项工作。

default.nix

with (import <nixpkgs> {});
let fetchgit-no-verify = fetchgit // {
  __functor = self : args :
      (fetchgit.__functor self args).overrideAttrs (oldAttrs:{GIT_SSL_NO_VERIFY=true;});
  } ;
in rec {
  test-pkg = callPackage ./test-pkg.nix {
    buildPythonPackage = python35Packages.buildPythonPackage;
    fetchgit = fetchgit-no-verify;
    };
}


fetchgit-no-verify使用fetchgit函子集开头,并使用新函数覆盖__functor属性。新函子仅应用其参数,然后调用overrideAttrs

这行得通,但是我很高兴将答案提供给任何可以添加一些见识或提供其他解决方案的人。首先,我想知道fetchgit派生如何成为函子。这是callPackage做的吗?

10-07 12:54