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

Merge legacy fetchGit-builtin with the generic fetchTree-function #3549

Merged
merged 2 commits into from Jul 29, 2020

Conversation

Ma27
Copy link
Member

@Ma27 Ma27 commented Apr 29, 2020

The original idea was to implement a git-fetcher in Nix's core that
supports content hashes[1]. In #3549[2] it has been suggested to
actually use fetchTree for this since it's a fairly generic wrapper
over the new fetcher-API[3] and already supports content-hashes.

This patch implements a new git-fetcher based on fetchTree by
incorporating the following changes:

  • Removed the original fetchGit-implementation and replaced it with an
    alias on the fetchTree implementation.

  • Ensured that the git-fetcher from libfetchers always computes a
    content-hash and returns an "empty" revision on dirty trees (the
    latter one is needed to retain backwards-compatibility).

  • The hash-mismatch error in the fetcher-API exits with code 102 as it
    usually happens whenever a hash-mismatch is detected by Nix.

  • Removed the flakes-feature-flag: I didn't see a reason why this API
    is so tightly coupled to the flakes-API and at least fetchGit should
    remain usable without any feature-flags.

  • It's only possible to specify a narHash for a git-tree if either a
    ref or a rev is given[4].

  • It's now possible to specify an URL without a protocol. If it's missing,
    file:// is automatically added as it was the case in the original
    fetchGit-implementation.

[1] #3216
[2] #3549 (comment)
[3] #3459
[4] #3216 (comment)


cc @edolstra @globin @xbreak @FRidh

@Ma27
Copy link
Member Author

Ma27 commented May 6, 2020

@domenkozar would you mind taking a look at this? :)

@domenkozar domenkozar requested a review from edolstra May 7, 2020 07:20
@edolstra
Copy link
Member

edolstra commented May 7, 2020

The reason for not adding a narHash flag to fetchGit is that we now have a more general builtin function fetchTree, which should already support narHash. So fetchGit / fetchMercurial are kind of legacy function that we keep for backward compatibility.

@Ma27
Copy link
Member Author

Ma27 commented May 7, 2020

The reason for not adding a narHash flag to fetchGit is that we now have a more general builtin function fetchTree, which should already support narHash. So fetchGit / fetchMercurial are kind of legacy function that we keep for backward compatibility.

I see. When I filed this patch, I wasn't' sure whether it's intended that fetchGit exists on its own. Should I modify this to use fetchTree entirely?

This would still require some modifications in the git-fetcher and the wrapper in fetchTree that passes arguments to the fetcher API.

@edolstra
Copy link
Member

edolstra commented May 7, 2020

Yes, please. All the other changes (like returning 102) look good to me.

Ma27 added a commit to Ma27/nix that referenced this pull request May 8, 2020
The original idea was to implement a git-fetcher in Nix's core that
supports content hashes[1]. In NixOS#3549[2] it has been suggested to
actually use `fetchTree` for this since it's a fairly generic wrapper
over the new fetcher-API[3] and already supports content-hashes.

This patch implements a new git-fetcher based on `fetchTree` by
incorporating the following changes:

* Removed the original `fetchGit`-implementation and replaced it with an
  alias on the `fetchTree` implementation.

* Ensured that the `git`-fetcher from `libfetchers` always computes a
  content-hash and returns an "empty" revision on dirty trees (the
  latter one is needed to retain backwards-compatibility).

* The hash-mismatch error in the fetcher-API exits with code 102 as it
  usually happens whenever a hash-mismatch is detected by Nix.

* Removed the `flakes`-feature-flag: I didn't see a reason why this API
  is so tightly coupled to the flakes-API and at least `fetchGit` should
  remain usable without any feature-flags.

* It's only possible to specify a `narHash` for a `git`-tree if either a
  `ref` or a `rev` is given[4].

* It's now possible to specify an URL without a protocol. If it's missing,
  `file://` is automatically added as it was the case in the original
  `fetchGit`-implementation.

[1] NixOS#3216
[2] NixOS#3549 (comment)
[3] NixOS#3459
[4] NixOS#3216 (comment)
@Ma27 Ma27 changed the title Add support for narHash in builtins.fetchGit Merge legacy fetchGit-builtin with the generic fetchTree-function May 8, 2020
@Ma27 Ma27 requested review from edolstra and domenkozar May 8, 2020 21:49
@Ma27
Copy link
Member Author

Ma27 commented May 8, 2020

Rebased onto latest master and merged fetchTree and fetchGit into a single C++-function using the fetcher-API. More details can be found in the new commit-message.

@globin since you were quite interested in this and I had to change a lot, you may want to take another look at this :)

@Ma27
Copy link
Member Author

Ma27 commented May 18, 2020

ping @domenkozar @edolstra

@domenkozar
Copy link
Member

I'll leave it up to Eelco for final review.

@edolstra
Copy link
Member

edolstra commented Jun 2, 2020

Would you mind rebasing this on the flakes branch? I made some changes to the fetcher API there. (In particular Input is now basically just a set of attributes.)

@Ma27
Copy link
Member Author

Ma27 commented Jun 2, 2020

Yes, already on it :)

Ma27 added a commit to Ma27/nix that referenced this pull request Jun 4, 2020
The original idea was to implement a git-fetcher in Nix's core that
supports content hashes[1]. In NixOS#3549[2] it has been suggested to
actually use `fetchTree` for this since it's a fairly generic wrapper
over the new fetcher-API[3] and already supports content-hashes.

This patch implements a new git-fetcher based on `fetchTree` by
incorporating the following changes:

* Removed the original `fetchGit`-implementation and replaced it with an
  alias on the `fetchTree` implementation.

* Ensured that the `git`-fetcher from `libfetchers` always computes a
  content-hash and returns an "empty" revision on dirty trees (the
  latter one is needed to retain backwards-compatibility).

* The hash-mismatch error in the fetcher-API exits with code 102 as it
  usually happens whenever a hash-mismatch is detected by Nix.

* Removed the `flakes`-feature-flag: I didn't see a reason why this API
  is so tightly coupled to the flakes-API and at least `fetchGit` should
  remain usable without any feature-flags.

* It's only possible to specify a `narHash` for a `git`-tree if either a
  `ref` or a `rev` is given[4].

* It's now possible to specify an URL without a protocol. If it's missing,
  `file://` is automatically added as it was the case in the original
  `fetchGit`-implementation.

[1] NixOS#3216
[2] NixOS#3549 (comment)
[3] NixOS#3459
[4] NixOS#3216 (comment)
@Ma27 Ma27 changed the base branch from master to flakes June 4, 2020 00:46
@Ma27
Copy link
Member Author

Ma27 commented Jun 4, 2020

@edolstra rebased onto flakes :)

@Ma27
Copy link
Member Author

Ma27 commented Jun 10, 2020

@edolstra as this still applies properly to flakes and the tests were passing locally, anything else to do to get this merged? :)

src/libexpr/primops/fetchTree.cc Outdated Show resolved Hide resolved
src/libexpr/primops/fetchTree.cc Show resolved Hide resolved
src/libexpr/primops/fetchTree.cc Show resolved Hide resolved
src/libexpr/primops/fetchTree.cc Show resolved Hide resolved
src/libexpr/primops/fetchTree.cc Outdated Show resolved Hide resolved
src/libfetchers/git.cc Outdated Show resolved Hide resolved
src/libexpr/primops/fetchTree.cc Outdated Show resolved Hide resolved
Ma27 added a commit to Ma27/nix that referenced this pull request Jun 19, 2020
The original idea was to implement a git-fetcher in Nix's core that
supports content hashes[1]. In NixOS#3549[2] it has been suggested to
actually use `fetchTree` for this since it's a fairly generic wrapper
over the new fetcher-API[3] and already supports content-hashes.

This patch implements a new git-fetcher based on `fetchTree` by
incorporating the following changes:

* Removed the original `fetchGit`-implementation and replaced it with an
  alias on the `fetchTree` implementation.

* Ensured that the `git`-fetcher from `libfetchers` always computes a
  content-hash and returns an "empty" revision on dirty trees (the
  latter one is needed to retain backwards-compatibility).

* The hash-mismatch error in the fetcher-API exits with code 102 as it
  usually happens whenever a hash-mismatch is detected by Nix.

* Removed the `flakes`-feature-flag: I didn't see a reason why this API
  is so tightly coupled to the flakes-API and at least `fetchGit` should
  remain usable without any feature-flags.

* It's only possible to specify a `narHash` for a `git`-tree if either a
  `ref` or a `rev` is given[4].

* It's now possible to specify an URL without a protocol. If it's missing,
  `file://` is automatically added as it was the case in the original
  `fetchGit`-implementation.

[1] NixOS#3216
[2] NixOS#3549 (comment)
[3] NixOS#3459
[4] NixOS#3216 (comment)
@Ma27 Ma27 requested a review from edolstra June 19, 2020 19:51
@Ma27
Copy link
Member Author

Ma27 commented Jun 19, 2020

@edolstra rebased onto latest flakes-branch and fixed most of your comments (I added an answer/comment to the review-comments I didn't address (yet)).

@Ericson2314
Copy link
Member

@edolstra Is there a rough ETA for merging the flakes branch? This change would be desirable for us too: if flakes will be merged soon that's fine, but if not, then maybe we could back-port something like the earlier master-targetted version of this one?

@edolstra
Copy link
Member

@Ericson2314 I can merge it after the RFC is merged.

@Ma27
Copy link
Member Author

Ma27 commented Jun 24, 2020

@edolstra may I ask why though? Those fetchers are even on non-flakes master atm.

Ma27 added a commit to Ma27/nix that referenced this pull request Jul 17, 2020
The original idea was to implement a git-fetcher in Nix's core that
supports content hashes[1]. In NixOS#3549[2] it has been suggested to
actually use `fetchTree` for this since it's a fairly generic wrapper
over the new fetcher-API[3] and already supports content-hashes.

This patch implements a new git-fetcher based on `fetchTree` by
incorporating the following changes:

* Removed the original `fetchGit`-implementation and replaced it with an
  alias on the `fetchTree` implementation.

* Ensured that the `git`-fetcher from `libfetchers` always computes a
  content-hash and returns an "empty" revision on dirty trees (the
  latter one is needed to retain backwards-compatibility).

* The hash-mismatch error in the fetcher-API exits with code 102 as it
  usually happens whenever a hash-mismatch is detected by Nix.

* Removed the `flakes`-feature-flag: I didn't see a reason why this API
  is so tightly coupled to the flakes-API and at least `fetchGit` should
  remain usable without any feature-flags.

* It's only possible to specify a `narHash` for a `git`-tree if either a
  `ref` or a `rev` is given[4].

* It's now possible to specify an URL without a protocol. If it's missing,
  `file://` is automatically added as it was the case in the original
  `fetchGit`-implementation.

[1] NixOS#3216
[2] NixOS#3549 (comment)
[3] NixOS#3459
[4] NixOS#3216 (comment)
@Ma27 Ma27 changed the base branch from flakes to master July 17, 2020 17:04
@Ma27
Copy link
Member Author

Ma27 commented Jul 17, 2020

@edolstra rebased conflicts against master. Is there anything else tbd to get this merged?

@Ma27
Copy link
Member Author

Ma27 commented Jul 26, 2020

@edolstra the RFC is closed now - anything else we'd have to wait for until you can merge this? :)

Ma27 added a commit to Ma27/nix that referenced this pull request Jul 27, 2020
The original idea was to implement a git-fetcher in Nix's core that
supports content hashes[1]. In NixOS#3549[2] it has been suggested to
actually use `fetchTree` for this since it's a fairly generic wrapper
over the new fetcher-API[3] and already supports content-hashes.

This patch implements a new git-fetcher based on `fetchTree` by
incorporating the following changes:

* Removed the original `fetchGit`-implementation and replaced it with an
  alias on the `fetchTree` implementation.

* Ensured that the `git`-fetcher from `libfetchers` always computes a
  content-hash and returns an "empty" revision on dirty trees (the
  latter one is needed to retain backwards-compatibility).

* The hash-mismatch error in the fetcher-API exits with code 102 as it
  usually happens whenever a hash-mismatch is detected by Nix.

* Removed the `flakes`-feature-flag: I didn't see a reason why this API
  is so tightly coupled to the flakes-API and at least `fetchGit` should
  remain usable without any feature-flags.

* It's only possible to specify a `narHash` for a `git`-tree if either a
  `ref` or a `rev` is given[4].

* It's now possible to specify an URL without a protocol. If it's missing,
  `file://` is automatically added as it was the case in the original
  `fetchGit`-implementation.

[1] NixOS#3216
[2] NixOS#3549 (comment)
[3] NixOS#3459
[4] NixOS#3216 (comment)
The original idea was to implement a git-fetcher in Nix's core that
supports content hashes[1]. In NixOS#3549[2] it has been suggested to
actually use `fetchTree` for this since it's a fairly generic wrapper
over the new fetcher-API[3] and already supports content-hashes.

This patch implements a new git-fetcher based on `fetchTree` by
incorporating the following changes:

* Removed the original `fetchGit`-implementation and replaced it with an
  alias on the `fetchTree` implementation.

* Ensured that the `git`-fetcher from `libfetchers` always computes a
  content-hash and returns an "empty" revision on dirty trees (the
  latter one is needed to retain backwards-compatibility).

* The hash-mismatch error in the fetcher-API exits with code 102 as it
  usually happens whenever a hash-mismatch is detected by Nix.

* Removed the `flakes`-feature-flag: I didn't see a reason why this API
  is so tightly coupled to the flakes-API and at least `fetchGit` should
  remain usable without any feature-flags.

* It's only possible to specify a `narHash` for a `git`-tree if either a
  `ref` or a `rev` is given[4].

* It's now possible to specify an URL without a protocol. If it's missing,
  `file://` is automatically added as it was the case in the original
  `fetchGit`-implementation.

[1] NixOS#3216
[2] NixOS#3549 (comment)
[3] NixOS#3459
[4] NixOS#3216 (comment)
@Ma27
Copy link
Member Author

Ma27 commented Jul 27, 2020

@edolstra resolved the merge conflict. Is there anything to discuss about the pending two comments you've left?

@@ -123,7 +129,7 @@ path2=$(nix eval --impure --raw --expr "(builtins.fetchGit file://$repo).outPath
# Using local path with branch other than 'master' should work when clean or dirty
path3=$(nix eval --impure --raw --expr "(builtins.fetchGit $repo).outPath")
# (check dirty-tree handling was used)
[[ $(nix eval --impure --raw --expr "(builtins.fetchGit $repo).rev") = 0000000000000000000000000000000000000000 ]]
[[ $(nix eval --impure --expr "(builtins.fetchGit $repo).rev or null") = null ]]
Copy link
Member

Choose a reason for hiding this comment

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

This breaks compatibility since there might be projects that expect that rev is always set. fetchGit (but not fetchTree) on dirty trees should continue to return 000....

Copy link
Member Author

Choose a reason for hiding this comment

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

so, partly revert my change to ensure fetchGit returns an empty rev here?

Copy link
Member

Choose a reason for hiding this comment

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

Yes please.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed. However I'm well-aware that my current fix is fairly ugly since I didn't manage to allocate a new attr to v in prim_fetchGit. If you have a better solution, please tell me :)

If a repo is dirty, it used to return a `rev` object with an "empty"
sha1 (0000000000000000000000000000000000000000). Please note that this
only applies for `builtins.fetchGit` and *not* for `builtins.fetchTree{
type = "git"; }`.
@edolstra edolstra merged commit 39311e7 into NixOS:master Jul 29, 2020
@edolstra
Copy link
Member

@Ma27 Merged, thanks for all your work on this!

@Ma27 Ma27 deleted the fetchgit-hash branch July 29, 2020 09:34
@Ma27
Copy link
Member Author

Ma27 commented Jul 29, 2020

You're welcome :)

I'm surprised though that there's now a failingtest although I ran make installcheck several times locally. Tonight I have time to look into this.

@Ma27
Copy link
Member Author

Ma27 commented Jul 29, 2020

For the macos issue I asked in #nixos-dev whether someone with the needed hardware can take a look.
nix-build -A checks.x86_64-linux repeatedly builds locally.

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

4 participants