英文:
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'm trying to create a flake for the peer to peer web browser, agregore ( https://github.com/AgregoreWeb/agregore-browser ). It's my first flake and I'm having major difficulties.
[Here'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 = "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 = ./.;
};
Logs produced:
@nix { "action": "setPhase", "phase": "unpackPhase" }
unpacking sources
unpacking source archive /nix/store/va0hnynmqf8h29f580sb6h7d3z9kxcpm-1q603n538l>
source root is 1q603n538laqf3nvkgb5mdr6am8apbda-source
@nix { "action": "setPhase", "phase": "patchPhase" }
patching sources
@nix { "action": "setPhase", "phase": "configurePhase" }
configuring
no configure script, doing nothing
@nix { "action": "setPhase", "phase": "buildPhase" }
building
fatal: not a git repository (or any of the parent directories): .git
I've tried inserting commands like ls .git/ > out.txt
into the buildPhase, and this produces ls: cannot access '.git/': 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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论