nix buildPhase fails, "fatal: not a git repository", the .git dir isn't being copied into the build dir?

huangapple go评论55阅读模式
英文:

nix buildPhase fails, "fatal: not a git repository", the .git dir isn't being copied into the build dir?

问题

我正在尝试为点对点网络浏览器agregore创建一个flake https://github.com/AgregoreWeb/agregore-browser )。这是我的第一个flake,我遇到了很大的困难。

[这是完整的flake][1],我已经放在了上述agregore git仓库的克隆版中。我认为相关部分只是这样的:

```nix
packages.default = stdenv.mkDerivation {
  pname = "agregore";
  version = (builtins.fromJSON (builtins.readFile ./package.json)).version;
  buildInputs = [
    pkgs.git
    pkgs.nodejs
    pkgs.nodePackages.node-gyp
    pkgs.nodePackages.npm
    pkgs.yarn
  ];
  buildPhase = '';
    git submodule update --init --recursive
    yarn
  '';
  installPhase = '';
    mkdir -p $out/bin
    #TODO find the build output
    ln -s build/agregore $out/bin/agregore
  '';
  src = ./.;
};

生成的日志:

@nix { "action": "setPhase", "phase": "unpackPhase" }
解压源码
解压源码存档 /nix/store/va0hnynmqf8h29f580sb6h7d3z9kxcpm-1q603n538l
源码根目录是 1q603n538laqf3nvkgb5mdr6am8apbda-source
@nix { "action": "setPhase", "phase": "patchPhase" }
打补丁
@nix { "action": "setPhase", "phase": "configurePhase" }
配置中
没有配置脚本,什么也不做
@nix { "action": "setPhase", "phase": "buildPhase" }
构建中
致命错误: 不是 git 仓库(或者父目录中的任何一个): .git

我尝试在buildPhase中插入命令,比如 ls .git/ > out.txt,但会产生 ls: cannot access '.git/': No such file or directory 错误,因此它们实际上没有被复制到nix为此flake临时构建目录中(使用 build/ 而不是 .git/ 运行相同命令不会产生此错误)。我无法理解为什么会出现这种情况。

相同的命令 git submodule update --init --recursive 在原始项目目录中正常工作(我正在运行nixos),也在 nix develop 会话中正常工作,所以 .git 目录确实应该在那里?


<details>
<summary>英文:</summary>

I&#39;m trying to create a flake for the peer to peer web browser, agregore ( https://github.com/AgregoreWeb/agregore-browser ). It&#39;s my first flake and I&#39;m having major difficulties.

[Here&#39;s the full flake][1], which I have placed in a clone of the above agregore git repo. I think the relevant section is all just this:

```nix
packages.default = stdenv.mkDerivation {
  pname = &quot;agregore&quot;;
  version = (builtins.fromJSON (builtins.readFile ./package.json)).version;
  buildInputs = [
    pkgs.git
    pkgs.nodejs
    pkgs.nodePackages.node-gyp
    pkgs.nodePackages.npm
    pkgs.yarn
  ];
  buildPhase = &#39;&#39;
    git submodule update --init --recursive
    yarn
  &#39;&#39;;
  installPhase = &#39;&#39;
    mkdir -p $out/bin
    #TODO find the build output
    ln -s build/agregore $out/bin/agregore
  &#39;&#39;;
  src = ./.;
};

Logs produced:

@nix { &quot;action&quot;: &quot;setPhase&quot;, &quot;phase&quot;: &quot;unpackPhase&quot; }
unpacking sources
unpacking source archive /nix/store/va0hnynmqf8h29f580sb6h7d3z9kxcpm-1q603n538l&gt;
source root is 1q603n538laqf3nvkgb5mdr6am8apbda-source
@nix { &quot;action&quot;: &quot;setPhase&quot;, &quot;phase&quot;: &quot;patchPhase&quot; }
patching sources
@nix { &quot;action&quot;: &quot;setPhase&quot;, &quot;phase&quot;: &quot;configurePhase&quot; }
configuring
no configure script, doing nothing
@nix { &quot;action&quot;: &quot;setPhase&quot;, &quot;phase&quot;: &quot;buildPhase&quot; }
building
fatal: not a git repository (or any of the parent directories): .git

I've tried inserting commands like ls .git/ &gt; out.txt into the buildPhase, and this produces ls: cannot access &#39;.git/&#39;: No such file or directory, so they are indeed not being copied over to nix's temporary build directory for this flake (and running the same command with build/ instead of .git/ doesn't produce this error.). I can't understand why this would be.

The same command, git submodule update --init --recursive, works fine in the original project dir (and I'm running nixos btw), also within a nix develop session, so the .git directory really should to be there?

答案1

得分: 1

我相信mkDerivation默认情况下会从源代码中清除.git,因为在可重现的构建中包含它是不合适的(.git包含诸如对旧分支的悬挂引用等完全依赖于客户端的内容)。话虽如此,在我看来,git submodule update --init --recursive不应该出现在Nix代码中,因为Nix代码假设它在一个“合理”的源代码结构上运行。

英文:

I believe mkDerivation by default cleans .git from the source, because it's not appropriate to include it in a reproducible build (.git contains things like dangling references to old branches and the like which are completely client-specific). That said, in my opinion git submodule update --init --recursive doesn't really belong in the Nix code, because the Nix code assumes that it's operating on a "sane" source structure.

huangapple
  • 本文由 发表于 2023年6月8日 06:33:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/76427493.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定