nix 포크에서 개인 Git 저장소를 복제하는 방법

nix 포크에서 개인 Git 저장소를 복제하는 방법
{
  nixpkgs ? import <nixpkgs> {}
}:nixpkgs.pkgs.fetchgitPrivate {
        url = "ssh://[email protected]/trycatchchris/blog.git";
        rev = "0f5fe7ebf0724eb17aea4141e0cf3f1758a6d716";
        sha256 = "02951e82c1183aaf1ce4b9669bf9ae32e50c4c641550797eed37739cd4528b58";
      }

위의 nix 표현식이 있는데, 여기서 저장소는 개인용 git 저장소입니다.

내 사용자의 공개 키를 통해 이 저장소에 액세스할 수 있습니다.

정규적으로 시도하면 nix-build:

nix-build
trace: Please set your nix-path such that ssh-config-file points to a file that will allow ssh to access private repositories. The builder will not be able to see any running ssh agent sessions unless ssh-auth-sock is also set in the nix-path.

Note that the config file and any keys it points to must be readable by the build user, which depending on your nix configuration means making it readable by the build-users-group, the user of the running nix-daemon, or the user calling the nix command which started the build. Similarly, if using an ssh agent ssh-auth-sock must point to a socket the build user can access.

You may need StrictHostKeyChecking=no in the config file. Since ssh will refuse to use a group-readable private key, if using build-users you will likely want to use something like IdentityFile /some/directory/%u/key and have a directory for each build user accessible to that user.

these derivations will be built:
  /nix/store/hlnshdb0ckckih46cv66xj8pyqds6w7y-blog-0f5fe7e.drv
building '/nix/store/hlnshdb0ckckih46cv66xj8pyqds6w7y-blog-0f5fe7e.drv'...
exporting ssh://[email protected]/trycatchchris/blog.git (rev 0f5fe7ebf0724eb17aea4141e0cf3f1758a6d716) into /nix/store/mkinydhkdyg6dyw7fp399m90qw5bsbqd-blog-0f5fe7e
Initialized empty Git repository in /nix/store/mkinydhkdyg6dyw7fp399m90qw5bsbqd-blog-0f5fe7e/.git/
Can't open user config file /var/lib/empty/config: No such file or directory
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
Can't open user config file /var/lib/empty/config: No such file or directory
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
Unable to checkout 0f5fe7ebf0724eb17aea4141e0cf3f1758a6d716 from ssh://[email protected]/trycatchchris/blog.git.
builder for '/nix/store/hlnshdb0ckckih46cv66xj8pyqds6w7y-blog-0f5fe7e.drv' failed with exit code 1
error: build of '/nix/store/hlnshdb0ckckih46cv66xj8pyqds6w7y-blog-0f5fe7e.drv' failed

나는 SSH 프록시도 사용해 보았습니다.https://github.com/NixOS/nixpkgs/issues/4004#issuecomment-236434045):

ssh다음 내용으로 파일을 만듭니다 .

Host gitlab.com
  StrictHostKeyChecking No
  UserKnownHostsFile /dev/null
  IdentityFile /home/chris/.ssh/id_rsa

그리고 다음을 실행하세요:

nix-build -I ssh-config-file=$PWD/ssh           
these derivations will be built:
  /nix/store/ng4qdayni3a69b57kfmrvf4ba03ryfv9-blog-0f5fe7e.drv
building '/nix/store/ng4qdayni3a69b57kfmrvf4ba03ryfv9-blog-0f5fe7e.drv'...
exporting ssh://[email protected]/trycatchchris/blog.git (rev 0f5fe7ebf0724eb17aea4141e0cf3f1758a6d716) into /nix/store/mkinydhkdyg6dyw7fp399m90qw5bsbqd-blog-0f5fe7e
Initialized empty Git repository in /nix/store/mkinydhkdyg6dyw7fp399m90qw5bsbqd-blog-0f5fe7e/.git/
Can't open user config file /home/chris/temp/wiptemp/11/ssh: No such file or directory
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
Can't open user config file /home/chris/temp/wiptemp/11/ssh: No such file or directory
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
Unable to checkout 0f5fe7ebf0724eb17aea4141e0cf3f1758a6d716 from ssh://[email protected]/trycatchchris/blog.git.
builder for '/nix/store/ng4qdayni3a69b57kfmrvf4ba03ryfv9-blog-0f5fe7e.drv' failed with exit code 1
error: build of '/nix/store/ng4qdayni3a69b57kfmrvf4ba03ryfv9-blog-0f5fe7e.drv' failed

하지만 이것도 실패합니다... 위의 방법이나 다른 방법을 사용하여 개인 저장소를 어떻게 복제합니까?

답변1

{
  nixpkgs ? import <nixpkgs> {}
}:(import (builtins.fetchGit {
        url = "ssh://[email protected]/trycatchchris/blog.git";
        rev = "4d127272689a5bc172e82529132b91e5943bb16f";
      }) {})

() 위의 경우 builtins.fetchGit샌드박스 등을 설정하지 않고도 완벽하게 작동하는 것 같습니다(기본 ~/.ssh/id_rsa 키 사용).

Nix < v2.4를 사용하고 브랜치에 없는 커밋을 가져오는 경우 브랜치 이름과 함께 추가 속성을 master추가해야 합니다 . 예를 들면 다음과 같습니다.ref

{
            url = "ssh://[email protected]/trycatchchris/blog.git";
            rev = "4d127272689a5bc172e82529132b91e5943bb16f";
            ref = "branchNameGoesHere"; # here
          }

https://github.com/nix-community/naersk/pull/211

관련 정보