query
On this page

invalidateFetcherByDrvHash

pkgs.testers.invalidateFetcherByDrvHash

Docs pulled from | This Revision | 35 minutes ago


or doc/build-helpers/testers.chapter.md


Noogle detected

Implementation

The following is the current implementation of this function.

invalidateFetcherByDrvHash =
    f: args:
    let
      optionalFix = if lib.isFunction args then lib.id else lib.fix;
      unsalted = f args;
      drvPath = unsalted.drvPath;
      # It's safe to discard the context, because we don't access the path.
      salt = builtins.unsafeDiscardStringContext (lib.substring 0 12 (baseNameOf drvPath));
      saltName = name: "${name}-salted-${salt}";
      getSaltedNames =
        args:
        if args.pname or null != null then
          { pname = saltName args.pname; }
        else
          { name = saltName args.name or "source"; };
      # New derivation incorporating the original drv hash in the name
      saltedByArgs = f (optionalFix (lib.extends (lib.toExtension getSaltedNames) (lib.toFunction args)));
      saltedByOverrideAttrs = unsalted.overrideAttrs (previousAttrs: getSaltedNames previousAttrs);
      saltedByOverrideAttrsForced = unsalted.overrideAttrs (previousAttrs: {
        name = saltName unsalted.name;
      });
      # Make sure we did change the derivation.
      # If the fetcher ignores `pname` and `name` and provide a broken `overrideAttrs`,
      # `invalidateFetcherByDrvHash` doesn't work.
      checked =
        if saltedByArgs.drvPath != drvPath then
          saltedByArgs
        else if saltedByOverrideAttrs.drvPath != drvPath then
          saltedByOverrideAttrs
        else if saltedByOverrideAttrsForced.drvPath != drvPath then
          saltedByOverrideAttrsForced
        else
          throw "invalidateFetcherByDrvHash: Neither adding pname/name to the fetcher args nor overriding with overrideAttrs change the result drvPath.";
    in
    checked;