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

fetchgit{,hub}: add tag argument #355973

Merged
merged 2 commits into from
Dec 5, 2024
Merged

fetchgit{,hub}: add tag argument #355973

merged 2 commits into from
Dec 5, 2024

Conversation

Atemu
Copy link
Member

@Atemu Atemu commented Nov 14, 2024

It's become a common pattern to use rev = "refs/tags/${version}" rather than just rev = version to ensure that the tag gets fetched rather than a branch that has the same name. This is done using boilerplate though, so let's add a simple abstraction for fetching tags instead.

The first two commits are from #355685 which should be merged first. Please review those separately.

This should be backported as it's a non-breaking addition and because people will likely want to make use of this in changes which they want to backport.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 25.05 Release Notes (or backporting 24.11 and 25.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@github-actions github-actions bot added the 8.has: documentation This PR adds or changes documentation label Nov 14, 2024
@Atemu Atemu marked this pull request as ready for review November 14, 2024 22:48
@nix-owners nix-owners bot requested a review from philiptaron November 14, 2024 22:50
It's become a common pattern to use `rev = "refs/tags/${version}"` rather than
just `rev = version` to ensure that the tag gets fetched rather than a branch
that has the same name. This has so far been done using boilerplate though, so
let's add a simple abstraction to fetch a tag instead.
@Atemu
Copy link
Member Author

Atemu commented Nov 18, 2024

#355685 is now in master.

@Atemu Atemu requested a review from drupol November 18, 2024 07:21
@Atemu Atemu added 9.needs: port to stable A PR needs a backport to the stable release. and removed backport release-24.05 labels Nov 18, 2024
@Atemu
Copy link
Member Author

Atemu commented Nov 18, 2024

This will not apply to 24.05 cleanly because of the docs but I will backport the functionality if no breakage is detected on unstable after this is merged. There really shouldn't be any but just to be sure.

Copy link
Contributor

@philiptaron philiptaron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like this direction, but the implementation (done with defaults) means it's possible for a user to specify both a tag and a rev, and the derivation will silently pick the rev.

Instead, how about implementing this with a let block, so that the derivation-creating function is in charge of exactly how and in what circumstances rev and tag interact?

pkgs/build-support/fetchgit/default.nix Outdated Show resolved Hide resolved
@Atemu
Copy link
Member Author

Atemu commented Nov 18, 2024

I feel like that is a contrived example, do you expect that to actually happen? This seems to be a theoretical concern to me, not a practical one.

@wegank wegank added the 12.approvals: 1 This PR was reviewed and approved by one reputable person label Nov 19, 2024
@Atemu Atemu requested a review from philiptaron November 21, 2024 20:36
@Atemu
Copy link
Member Author

Atemu commented Nov 28, 2024

I think I'd like to go ahead with this and self-merge unless someone objects within the next week or so.

@sikmir
Copy link
Member

sikmir commented Dec 11, 2024

What about fetchsourcehut? Would be good to add tag as well.

@Atemu
Copy link
Member Author

Atemu commented Dec 11, 2024

#355973 (comment)

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/fetchgit-hub-add-tag-argument/56710/6

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/how-to-properly-package-a-executable-file/57184/25

@Atemu
Copy link
Member Author

Atemu commented Dec 12, 2024

I wasn't too clear on this: please feel absolutely free to port tag support to other VCS fetechers yourself. I likely won't be the one to do it.

This would also be a good first PR as it that's not very coplicated to do or verify.

@mweinelt
Copy link
Member

One nit: after setting the tag attribute I cannot get it from src anymore and src.rev = null, so it cannot be reused for meta.changelog anymore.

@Atemu
Copy link
Member Author

Atemu commented Dec 12, 2024

#362692

@SuperSandro2000
Copy link
Member

This idea is so good, we should have had it earlier 👍🏼 🥰

@philiptaron
Copy link
Contributor

I wasn't too clear on this: please feel absolutely free to port tag support to other VCS fetchers yourself. I likely won't be the one to do it.

This would also be a good first PR as it that's not very complicated to do or to verify.

And if anyone does decide to take this on, please add me as a reviewer! I'd love to help you get it to merged. 🖥️ 🚀

@ambroisie ambroisie mentioned this pull request Dec 14, 2024
13 tasks
@donovanglover donovanglover mentioned this pull request Dec 21, 2024
13 tasks
@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/community-team-updates/56458/11

@Artturin
Copy link
Member

Exposed an issue with using finalAttrs.src in meta #367739

@emilazy
Copy link
Member

emilazy commented Dec 27, 2024

It seems like it would be best for this to expose the appropriate rev?

@Atemu
Copy link
Member Author

Atemu commented Dec 27, 2024

We could do that (PRs welcome) but you really shouldn't be depending on src.rev to begin with IMHO.

@emilazy
Copy link
Member

emilazy commented Dec 27, 2024

I think meta.changelog using it is fine personally (see #336454 for previous discussion), but I recognize I may be in a minority there. Just seems like we shouldn’t break the interface when using tag. Not sure if I’ll have time to send a PR or not. I worry a bit about the amount of duplication this will cause across forge fetchers; feels like we ought to have some kind of wrapper that handles the common arguments.

@PerchunPak
Copy link
Member

It seems like it would be best for this to expose the appropriate rev?

You couldn't use src.rev for (e.g.) meta.changelog in that case, as it would equal to refs/heads/.... I think the current approach prevents such misuses, even though it is a bit unintuitive.

@emilazy
Copy link
Member

emilazy commented Dec 27, 2024

Sure you could; https://github.com/NixOS/nixpkgs/blob/refs/tags/24.11-pre/README.md works fine and is fact better than the alternative for precisely the same reason we want to use refs/tags/* in fetchers. (https://github.com/NixOS/nixpkgs/blob/refs/heads/master/README.md also works, but isn’t relevant to the fetcher use case).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: fetch 8.has: documentation This PR adds or changes documentation 9.needs: port to stable A PR needs a backport to the stable release. 10.rebuild-darwin: 1-10 10.rebuild-linux: 1-10 12.approvals: 3+ This PR was reviewed and approved by three or more reputable people backport release-24.11 Backport PR automatically
Projects
None yet
Development

Successfully merging this pull request may close these issues.