Skip to content

Conversation

joshheinrichs-shopify
Copy link
Contributor

Motivation

This adds support for fetching trees / blobs to fetchGit / fetchTree, making it possible to fetch the source for specific subfolders of a repo. This is especially useful in a monorepo setting as it enables fetching the source for a particular project, and also avoids needless rebuilds if that project hasn't changed.

Context

Robert suggested that this might be possible at NixCon. I did an some initial poking at this a few weeks ago, and Ericson provided some good suggestions on how to approach this for real[1]. I deviated slightly from his suggestions and put some awareness of blobs + trees into GitRepo.getRevCount and GitRepo.getLastModified as they're ultimately only called from GitInputScheme which currently doesn't have any visibility into the types of objects.

A few things of note:

  • When using this via fetchGit, shallow is required as there's no history to fetch.
  • Since .gitattributes isn't available, submodules and lfs have no effect.
  • When fetching blobs and trees, revCount and lastModified are omitted from the resulting attribute set as those attributes only really make sense for commits (or things that point at commits like annotated tags).

I've opted to not add documentation as it's pretty succinct currently and I didn't want to bloat it with a relatively niche use case, but I can if that's desired. The existing documentation in fetchTree kind of implies that fetching tree objects could work[2].

[1] #13962
[2]

Fetch a Git tree and copy it to the Nix store.


Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

@github-actions github-actions bot added with-tests Issues related to testing. PRs with tests have some priority fetching Networking with the outside (non-Nix) world, input locking labels Sep 23, 2025
This makes it possible to fetch the source for specific folders / files,
provided it's supported by the remote and you know the hash of the
object. This is especially useful for monorepos if you just want to grab
the source for a specific directory.

When using this via fetchGit, shallow is required as there's no history
to fetch. Since .gitattributes isn't available, submodules and lfs have
no effect.

When fetching blobs and trees, revCount and lastModified are omitted
from the resulting attribute set as those attributes only really make
sense for commits (or things that point at commits like annotated tags).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fetching Networking with the outside (non-Nix) world, input locking with-tests Issues related to testing. PRs with tests have some priority
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant