nix icon indicating copy to clipboard operation
nix copied to clipboard

feat: support managing submodules via inputs.self

Open tomberek opened this issue 2 years ago • 19 comments

Provides special handling for inputs.self. If submodule is set to true, will re-call getFlake as if the original reference was set. The intended behavior is for CLI management of the parameter overrides any direct flake.nix settings.

Thanks to: @x10an14, @aaronchall, @mrene

Motivation

  • https://github.com/NixOS/nix/pull/4922
  • https://github.com/NixOS/nix/pull/5284
  • https://github.com/NixOS/nix/pull/4423
  • https://github.com/NixOS/nix/pull/5434
  • https://gist.github.com/mstone/4218e6fa9ef98e5153f543fb8e7b4743

Context

Provides a mechanism for inputs.self.submodules to control the availability of submodules in a local flake.

Checklist for maintainers

  • [x] test with remote resources (@kranzes)
  • [ ] provide check/error for that this logic won't work with "github:"

Maintainers: tick if completed or explain if not relevant

  • [ ] agreed on idea
  • [ ] agreed on implementation strategy
  • [x] tests, as appropriate
    • functional tests - tests/**.sh
    • unit tests - src/*/tests
    • integration tests - tests/nixos/*
  • [x] documentation in the manual
  • [ ] code and comments are self-explanatory
  • [x] commit message explains why the change was made
  • [ ] new feature or incompatible change: updated release notes

tomberek avatar Feb 19 '23 11:02 tomberek

Hm, it seems pretty ugly to add a git-specific submodules field to inputs.self. IMHO the better solution would be to enable submodules by default (after we've implemented efficient submodules support on the lazy-trees branch).

edolstra avatar Feb 20 '23 13:02 edolstra

Hm, it seems pretty ugly to add a git-specific submodules field to inputs.self. IMHO the better solution would be to enable submodules by default (after we've implemented efficient submodules support on the lazy-trees branch).

Yeah it isn't fancy. We just implemented it overnight in a call yesterday. We're not even sure if this is even a good idea to have. The thing is that the git-specific submodules inputs field already exists, it's just take effect in the CLI. That's what this PR does, it makes it function as you expect. This isn't an addition of a new feature, it is a fix of an already existing functionality.

Kranzes avatar Feb 20 '23 14:02 Kranzes

Triaged in the Nix team meeting:

  • @edolstra: prefer to enable submodules by default
    • right now they are extremly inefficient, but may want to make it work with lazy trees
  • @thufschmitt: wouldn't hurt to have a feature to forcibly enable them
    • @edolstra: this would change the flake language, requires us to continue supporting this eventually
  • @tomberek: often in practice people use submodule for private dependencies
  • @fricklerhandwerk: how high on our global priority list is this?
  • to discuss

fricklerhandwerk avatar Feb 24 '23 12:02 fricklerhandwerk

@edolstra: prefer to enable submodules by default

I believe that used to be the case but it was reverted because it was fetching when people didn't want it.

Kranzes avatar Feb 24 '23 12:02 Kranzes

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

https://discourse.nixos.org/t/2023-02-24-nix-team-meeting-minutes-35/25757/1

nixos-discourse avatar Feb 24 '23 13:02 nixos-discourse

@edolstra: prefer to enable submodules by default

I believe that used to be the case but it was reverted because it was fetching when people didn't want it.

To be clear it was because of their inefficiency https://github.com/NixOS/nix/issues/5280. But that sounds like a perfect application of lazy trees as mentioned.

Kha avatar Feb 24 '23 15:02 Kha

To chime in, I've seen C++ projects before where certain submodules are optional except for special cases like testing. While enabling by default would be helpful, I can also imagine a feature like .?submodules=extern/X,extern/Y being useful to keep clones efficient. This wouldn't fit neatly with always including submodules. I don't know how this fits in with flakes though as generally you'd want the flake to cover every case (incl. testing) so it may be very niche, or be on a per output level.

Either way, this feature as implemented in this PR or submodules by default would be incredibly useful for me.

JakeHillion avatar Mar 18 '23 13:03 JakeHillion

I think we should consider closing this, because the non-libgit fetching has too many problems and a more elegant replacement is in progress in #6530. We'd better make some progress on that, because we should neither develop a dead end, nor let fetcher development be blocked for a year.

roberth avatar Mar 18 '23 13:03 roberth

Discussed in the Nix team meeting:

We recommend instead to build a Nix language function that re-fetches an input by adding ?submodules=true. This is dirty but avoids changing Nix itself. We plan on delivering a principled solution eventually anyway, and the soft implementation is a good-enough stopgap.

Complete discussion
  • @Ericson2314: it would make sense if we implemented libgit first
  • @roberth: it's a good mechanism, but we don't have a need for it yet
  • @edolstra: the real problem is that it changes the interface by adding inputs.self, and we'd have to continue supporting that in the future
    • especially if it hardcodes submodules default to false
    • @thufschmitt: don't think the default is a problem
    • @fricklerhandwerk: is anything speaking against treating that addition as "extra-experimental" in isolation, even if we currently have no means of expressing it in the code?
      • @thufschmitt: that's the problem, there is no way of enforcing it whatsoever
      • @edolstra: in principle since flakes are experimental, we can change it arbitrarily, but ideally we shouldn't have to change the interface if it can be avoided
  • @thufschmitt: since submodules is false by default, one would have to specify the parameter to build the top-level flakes every time
    • would it make sense set it true for the top-level flake by default?
    • @edolstra: no, that would be very expensive
  • @edolstra: it's convenient to the user, but architecturally questionable to do the double-fetching
    • @roberth: with lazy trees this will become super cheap
  • @thufschmitt: couldn't we instead build a Nix language function that re-fetches an input by adding ?submodules=true?
    • this is dirty but avoids changing Nix itself
    • we will deliver a principled solution eventually, and this is good enough as a stopgap
  • decision: postponed

fricklerhandwerk avatar Mar 20 '23 12:03 fricklerhandwerk

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

https://discourse.nixos.org/t/2023-03-20-nix-team-meeting-minutes-42/26615/1

nixos-discourse avatar Mar 22 '23 20:03 nixos-discourse

What's the status here? I'd really like not to have to specify ?submodules=1 on the command-line every time.

NorfairKing avatar Jan 24 '24 12:01 NorfairKing

fetchTree will fetch submodules lazily in the upcoming release, 2.20. We'll have very little reason to disable submodules by default...

EDIT: added to team discussion queue for Friday.

roberth avatar Jan 24 '24 17:01 roberth

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

https://discourse.nixos.org/t/get-nix-flake-to-include-git-submodule/30324/13

nixos-discourse avatar Feb 22 '24 12:02 nixos-discourse

Is this available on nix version 2.20 onwards? I would very much like an example of how I can build a derivation using a local submodule

amfaber avatar Mar 27 '24 09:03 amfaber

@amfaber , not a contributor/maintainer, but it doesn't seem like it based on the release notes

znd4 avatar Mar 28 '24 14:03 znd4

Is this available on nix version 2.20 onwards?

It is not.

We'll have very little reason to disable submodules by default...

We're still exploring the solution space for efficiently fetching from a forge such as GitHub, which can return a tarball as a significantly quicker operation, so it's hard to tell whether changing the default setting would make sense.

I do think we'll need a configurable inputs.self regardless.

roberth avatar Mar 28 '24 16:03 roberth

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

https://discourse.nixos.org/t/get-nix-flake-to-include-git-submodule/30324/14

nixos-discourse avatar Mar 30 '24 10:03 nixos-discourse

Lack of support for submodules for current(self) repo makes packaging most of our software not viable using Nix Flakes. I'm really hoping we can get support of submodules for self in Nix.

jakubgs avatar Mar 30 '24 11:03 jakubgs

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

https://discourse.nixos.org/t/handling-git-submodules-in-flakes-from-nix-2-18-to-2-22-nar-hash-mismatch-issues/45118/1

nixos-discourse avatar May 09 '24 03:05 nixos-discourse

Any update on this?

AshleyYakeley avatar Jul 19 '24 20:07 AshleyYakeley