Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: bake git into PATH at runtime #45

Merged
merged 2 commits into from
Dec 16, 2022
Merged

fix: bake git into PATH at runtime #45

merged 2 commits into from
Dec 16, 2022

Conversation

hraban
Copy link
Contributor

@hraban hraban commented Dec 14, 2022

This way you can run it on a fresh nixos install with flakes enabled but without git globally installed.

Demo:

$ nix run github:seppeljordan/nix-prefetch-github -- hraban opus
Traceback (most recent call last):
  File "/nix/store/83nszrlr1dj1lbnjyry24ji3drf90ik0-python3.10-nix-prefetch-github-5.2.2-dev/bin/.nix-prefetch-github-wrapped", line 9, in <module>
    sys.exit(main())
  File "/nix/store/83nszrlr1dj1lbnjyry24ji3drf90ik0-python3.10-nix-prefetch-github-5.2.2-dev/lib/python3.10/site-packages/nix_prefetch_github/cli/fetch_github.py", line 9, in main
    controller.process_arguments(sys.argv[1:])
  File "/nix/store/83nszrlr1dj1lbnjyry24ji3drf90ik0-python3.10-nix-prefetch-github-5.2.2-dev/lib/python3.10/site-packages/nix_prefetch_github/controller/nix_prefetch_github_controller.py", line 29, in process_arguments
    self._use_case.prefetch_github_repository(
  File "/nix/store/83nszrlr1dj1lbnjyry24ji3drf90ik0-python3.10-nix-prefetch-github-5.2.2-dev/lib/python3.10/site-packages/nix_prefetch_github/use_cases/prefetch_github_repository.py", line 38, in prefetch_github_repository
    prefetch_result = self.prefetcher.prefetch_github(
  File "/nix/store/83nszrlr1dj1lbnjyry24ji3drf90ik0-python3.10-nix-prefetch-github-5.2.2-dev/lib/python3.10/site-packages/nix_prefetch_github/prefetch.py", line 33, in prefetch_github
    revision = self._detect_revision(repository, rev)
  File "/nix/store/83nszrlr1dj1lbnjyry24ji3drf90ik0-python3.10-nix-prefetch-github-5.2.2-dev/lib/python3.10/site-packages/nix_prefetch_github/prefetch.py", line 67, in _detect_revision
    revision_index = self.revision_index_factory.get_revision_index(repository)
  File "/nix/store/83nszrlr1dj1lbnjyry24ji3drf90ik0-python3.10-nix-prefetch-github-5.2.2-dev/lib/python3.10/site-packages/nix_prefetch_github/revision_index_factory.py", line 23, in get_revision_index
    RevisionIndexImpl, self.list_remote_factory.get_list_remote(repository)
  File "/nix/store/83nszrlr1dj1lbnjyry24ji3drf90ik0-python3.10-nix-prefetch-github-5.2.2-dev/lib/python3.10/site-packages/nix_prefetch_github/list_remote_factory.py", line 14, in get_list_remote
    returncode, output = self.command_runner.run_command(
  File "/nix/store/83nszrlr1dj1lbnjyry24ji3drf90ik0-python3.10-nix-prefetch-github-5.2.2-dev/lib/python3.10/site-packages/nix_prefetch_github/command/command_runner.py", line 25, in run_command
    process = subprocess.Popen(
  File "/nix/store/zdba9frlxj2ba8ca095win3nphsiiqhb-python3-3.10.8/lib/python3.10/subprocess.py", line 971, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/nix/store/zdba9frlxj2ba8ca095win3nphsiiqhb-python3-3.10.8/lib/python3.10/subprocess.py", line 1847, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'git'

$ nix run github:hraban/nix-prefetch-github/fix/git-path -- hraban opus
{
    "owner": "hraban",
    "repo": "opus",
    "rev": "eeacdbcb92d065418ad40f65e8a30e0d0a88885d",
    "sha256": "ljRop2Nlt0Ip+sYaQutiMOP8Sl05iKdGQdqcIuA6FpU="
}

@seppeljordan
Copy link
Owner

Hi, thanks for your submission. What you propose sounds interesting. Can you think of any drawbacks to the change that you made?

nix/nix-prefetch-github.nix Outdated Show resolved Hide resolved
@hraban
Copy link
Contributor Author

hraban commented Dec 16, 2022

No this is idiomatic Nix:

nixpkgs $ rg wrapProgram | wc -l
1558

https://nixos.org/manual/nixpkgs/stable/#fun-makeWrapper

(I did see there the recommendation to use --suffix rather than --prefix which is a good idea, so you can always override the dependent program in a downstream deriv by using --prefix yourself. I didn't know that--that's fixed.)

@seppeljordan
Copy link
Owner

@hraban
Thank you for your contribution. I will merge this when the tests succeed. Unfortunately there are some tests in the test suite the depend on Github being available from the test runner and in the last attempt to run the tests there must have been a network issue. I tested your changeset locally and all went well.

@seppeljordan seppeljordan merged commit 067dd7a into seppeljordan:master Dec 16, 2022
@hraban
Copy link
Contributor Author

hraban commented Dec 16, 2022

I just tried your master branch from a nixos without global git installed and it worked:

$ nix run github:seppeljordan/nix-prefetch-github -- hraban opus
{
    "owner": "hraban",
    "repo": "opus",
    "rev": "eeacdbcb92d065418ad40f65e8a30e0d0a88885d",
    "sha256": "ljRop2Nlt0Ip+sYaQutiMOP8Sl05iKdGQdqcIuA6FpU="
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants