Unverified Commit 6a7c026b authored by github-actions[bot]'s avatar github-actions[bot] Committed by GitHub
Browse files

Merge master into staging-next

parents 772c3bbb 2387a37f
Loading
Loading
Loading
Loading
+10 −8
Original line number Diff line number Diff line
@@ -76,19 +76,22 @@ rec {
     Type:
       makeOverridable :: (AttrSet -> a) -> AttrSet -> a
  */
  makeOverridable = f: lib.setFunctionArgs
    (origArgs: let
  makeOverridable = f:
    let
      # Creates a functor with the same arguments as f
      mirrorArgs = lib.mirrorFunctionArgs f;
    in
    mirrorArgs (origArgs:
    let
      result = f origArgs;

      # Creates a functor with the same arguments as f
      copyArgs = g: lib.setFunctionArgs g (lib.functionArgs f);
      # Changes the original arguments with (potentially a function that returns) a set of new attributes
      overrideWith = newArgs: origArgs // (if lib.isFunction newArgs then newArgs origArgs else newArgs);

      # Re-call the function but with different arguments
      overrideArgs = copyArgs (newArgs: makeOverridable f (overrideWith newArgs));
      overrideArgs = mirrorArgs (newArgs: makeOverridable f (overrideWith newArgs));
      # Change the result of the function call by applying g to it
      overrideResult = g: makeOverridable (copyArgs (args: g (f args))) origArgs;
      overrideResult = g: makeOverridable (mirrorArgs (args: g (f args))) origArgs;
    in
      if builtins.isAttrs result then
        result // {
@@ -102,8 +105,7 @@ rec {
        lib.setFunctionArgs result (lib.functionArgs result) // {
          override = overrideArgs;
        }
      else result)
    (lib.functionArgs f);
      else result);


  /* Call the package function in the file `fn` with the required
+1 −1
Original line number Diff line number Diff line
@@ -74,7 +74,7 @@ let
      importJSON importTOML warn warnIf warnIfNot throwIf throwIfNot checkListOfEnum
      info showWarnings nixpkgsVersion version isInOldestRelease
      mod compare splitByAndCompare
      functionArgs setFunctionArgs isFunction toFunction
      functionArgs setFunctionArgs isFunction toFunction mirrorFunctionArgs
      toHexString toBaseDigits inPureEvalMode;
    inherit (self.fixedPoints) fix fix' converge extends composeExtensions
      composeManyExtensions makeExtensible makeExtensibleWithCustomName;
+0 −3
Original line number Diff line number Diff line
@@ -241,7 +241,4 @@ Arguments:
## To update in the future

Here's a list of places in the library that need to be updated in the future:
- > The file set library is currently somewhat limited but is being expanded to include more functions over time.

  in [the manual](../../doc/functions/fileset.section.md)
- If/Once a function exists that can optionally include a path depending on whether it exists, the error message for the path not existing in `_coerce` should mention the new function
+1 −1
Original line number Diff line number Diff line
@@ -188,7 +188,7 @@ in {
            - Set `root` to ${toString fileset._internalBase} or any directory higher up. This changes the layout of the resulting store path.
            - Set `fileset` to a file set that cannot contain files outside the `root` (${toString root}). This could change the files included in the result.''
    else
      builtins.seq sourceFilter
      seq sourceFilter
      cleanSourceWith {
        name = "source";
        src = root;
+34 −0
Original line number Diff line number Diff line
@@ -448,6 +448,40 @@ rec {
  isFunction = f: builtins.isFunction f ||
    (f ? __functor && isFunction (f.__functor f));

  /*
    `mirrorFunctionArgs f g` creates a new function `g'` with the same behavior as `g` (`g' x == g x`)
    but its function arguments mirroring `f` (`lib.functionArgs g' == lib.functionArgs f`).

    Type:
      mirrorFunctionArgs :: (a -> b) -> (a -> c) -> (a -> c)

    Example:
      addab = {a, b}: a + b
      addab { a = 2; b = 4; }
      => 6
      lib.functionArgs addab
      => { a = false; b = false; }
      addab1 = attrs: addab attrs + 1
      addab1 { a = 2; b = 4; }
      => 7
      lib.functionArgs addab1
      => { }
      addab1' = lib.mirrorFunctionArgs addab addab1
      addab1' { a = 2; b = 4; }
      => 7
      lib.functionArgs addab1'
      => { a = false; b = false; }
  */
  mirrorFunctionArgs =
    # Function to provide the argument metadata
    f:
    let
      fArgs = functionArgs f;
    in
    # Function to set the argument metadata to
    g:
    setFunctionArgs g fArgs;

  /*
    Turns any non-callable values into constant functions.
    Returns callable values as is.
Loading