Skip to content

[RFC] Hash overriding of fetcher-constructed FODs? #459651

@ShamrockLee

Description

@ShamrockLee

Background

The adoption of fixed-point arguments (finalAttrs: { }) is enabling us to override fetcher arguments with standard <pkg>.overrideAttrs instead of custom, locally-added override.

Most fetchers support the hash argument to specify FOD hashes with SRI hashes or optionally an empty string, while current fetcher implementation typically exposes only the derivation attributes outputHash, and its siblings outputHashAlgo and outputHashMode to <pkg>.overrideAttrs.

There are another kind of fetchers which returns a wrapper of an FOD rather than the FOD itself. For instance, rustPlatform.fetchCargoVendor first creates the vendorStaging FOD and then return a derivation wrapping the FOD. I refer to them as "wrapped fetchers" in the following questions.

Questions

  1. Should we override fetcher hashes with <pkg>.overrideHash?
    • (+) Custom overriders (like overridePythonAttrs) are causing enough problems. The unified <pkg>.overrideAttrs is the way.
    • (-) Custom override for fetcher results inherently have an interface identical to the fetcher itself.
      • (+) We could also make <pkg>.overrideAttrs accept hash and push similar changes to unify significant part of the <fetched-pkg>.overrideAttrs arguments toward those used by the fetcher itself.
    • (-) <pkg>.overrideAttrs doesn't white-list the overriding arguments and is prone to typos.
      • (+) We can implement optional checks to white-list the attributes.
    • (-) For fetchers like fetchFromGitHub that dynamically switch between base fetchers (fetchgit and fetchzip), it is hard to implement the dynamic switching functionality for <pkg>.overrideAttrs.
  2. Should we make hash overridable with <pkg>.overrideAttrs, or should we keep overriding outputHash?
    • (-) Every FOD has outputHash. Its overriding functionality is 100% backward compatible and mostly available.
    • (+) Making hash overridable is more intuitive and consistent with fetchers' interfaces.
    • (+) Making hash overridable allows outputHash = if finalAttrs.hash == "" then lib.fakeHash else finalAttrs.hash, making it easy to determine the hash with hash = "" and make the hash algorithm future proof when specifying empty hashes.
    • (+) This exposes src.hash, which sounds more intuitive than src.outputHash.
      • (-) We already have src.outputHash.
  3. If we choose to override hash, should we also expose the hash attribute of wrapped fetchers's direct result attribute, or should we instruct the user to override the hash by overriding the inner FOD?
    • (-) Just instruct people to override the inner FOD, as they have to when overriding other attributes.
    • (+) hash is special to fetchers, and it's important to ensure src.overrideAttrs { hash = ...; } always work.

Related issues and PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    0.kind: enhancementAdd something new or improve an existing system.1.severity: significantNovel ideas, large API changes, notable refactorings, issues with RFC potential, etc.9.needs: community feedbackThis needs feedback from more community members.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions