···306306 in if drv == null then null else
307307 deepSeq drv' drv';
308308309309- /* Make a set of packages with a common scope. All packages called
310310- with the provided `callPackage` will be evaluated with the same
311311- arguments. Any package in the set may depend on any other. The
312312- `overrideScope'` function allows subsequent modification of the package
313313- set in a consistent way, i.e. all packages in the set will be
314314- called with the overridden packages. The package sets may be
315315- hierarchical: the packages in the set are called with the scope
316316- provided by `newScope` and the set provides a `newScope` attribute
317317- which can form the parent scope for later package sets.
309309+ /**
310310+ Make an attribute set (a "scope") from functions that take arguments from that same attribute set.
311311+ See [](#ex-makeScope) for how to use it.
312312+313313+ # Inputs
314314+315315+ 1. `newScope` (`AttrSet -> ((AttrSet -> a) | Path) -> AttrSet -> a`)
316316+317317+ A function that takes an attribute set `attrs` and returns what ends up as `callPackage` in the output.
318318+319319+ Typical values are `callPackageWith` or the output attribute `newScope`.
320320+321321+ 2. `f` (`AttrSet -> AttrSet`)
322322+323323+ A function that takes an attribute set as returned by `makeScope newScope f` (a "scope") and returns any attribute set.
324324+325325+ This function is used to compute the fixpoint of the resulting scope using `callPackage`.
326326+ Its argument is the lazily evaluated reference to the value of that fixpoint, and is typically called `self` or `final`.
327327+328328+ See [](#ex-makeScope) for how to use it.
329329+ See [](#sec-functions-library-fixedPoints) for details on fixpoint computation.
330330+331331+ # Output
332332+333333+ `makeScope` returns an attribute set of a form called `scope`, which also contains the final attributes produced by `f`:
334334+335335+ ```
336336+ scope :: {
337337+ callPackage :: ((AttrSet -> a) | Path) -> AttrSet -> a
338338+ newScope = AttrSet -> scope
339339+ overrideScope = (scope -> scope -> AttrSet) -> scope
340340+ packages :: AttrSet -> AttrSet
341341+ }
342342+ ```
343343+344344+ - `callPackage` (`((AttrSet -> a) | Path) -> AttrSet -> a`)
345345+346346+ A function that
347347+348348+ 1. Takes a function `p`, or a path to a Nix file that contains a function `p`, which takes an attribute set and returns value of arbitrary type `a`,
349349+ 2. Takes an attribute set `args` with explicit attributes to pass to `p`,
350350+ 3. Calls `f` with attributes from the original attribute set `attrs` passed to `newScope` updated with `args, i.e. `attrs // args`, if they match the attributes in the argument of `p`.
351351+352352+ All such functions `p` will be called with the same value for `attrs`.
353353+354354+ See [](#ex-makeScope-callPackage) for how to use it.
355355+356356+ - `newScope` (`AttrSet -> scope`)
357357+358358+ Takes an attribute set `attrs` and returns a scope that extends the original scope.
359359+360360+ - `overrideScope` (`(scope -> scope -> AttrSet) -> scope`)
361361+362362+ Takes a function `g` of the form `final: prev: { # attributes }` to act as an overlay on `f`, and returns a new scope with values determined by `extends g f`.
363363+ See [](https://nixos.org/manual/nixpkgs/unstable/#function-library-lib.fixedPoints.extends) for details.
364364+365365+ This allows subsequent modification of the final attribute set in a consistent way, i.e. all functions `p` invoked with `callPackage` will be called with the modified values.
366366+367367+ - `packages` (`AttrSet -> AttrSet`)
368368+369369+ The value of the argument `f` to `makeScope`.
370370+371371+ - final attributes
372372+373373+ The final values returned by `f`.
374374+375375+ # Examples
376376+377377+ :::{#ex-makeScope .example}
378378+ # Create an interdependent package set on top of `pkgs`
379379+380380+ The functions in `foo.nix` and `bar.nix` can depend on each other, in the sense that `foo.nix` can contain a function that expects `bar` as an attribute in its argument.
381381+382382+ ```nix
383383+ let
384384+ pkgs = import <nixpkgs> { };
385385+ in
386386+ pkgs.lib.makeScope pkgs.newScope (self: {
387387+ foo = self.callPackage ./foo.nix { };
388388+ bar = self.callPackage ./bar.nix { };
389389+ })
390390+ ```
391391+392392+ evaluates to
318393319319- Type:
320320- makeScope :: (AttrSet -> ((AttrSet -> a) | Path) -> AttrSet -> a) -> (AttrSet -> AttrSet) -> AttrSet
394394+ ```nix
395395+ {
396396+ callPackage = «lambda»;
397397+ newScope = «lambda»;
398398+ overrideScope = «lambda»;
399399+ packages = «lambda»;
400400+ foo = «derivation»;
401401+ bar = «derivation»;
402402+ }
403403+ ```
404404+ :::
405405+406406+ :::{#ex-makeScope-callPackage .example}
407407+ # Using `callPackage` from a scope
408408+409409+ ```nix
410410+ let
411411+ pkgs = import <nixpkgs> { };
412412+ inherit (pkgs) lib;
413413+ scope = lib.makeScope lib.callPackageWith (self: { a = 1; b = 2; });
414414+ three = scope.callPackage ({ a, b }: a + b) { };
415415+ four = scope.callPackage ({ a, b }: a + b) { a = 2; };
416416+ in
417417+ [ three four ]
418418+ ```
419419+420420+ evaluates to
421421+422422+ ```nix
423423+ [ 3 4 ]
424424+ ```
425425+ :::
426426+427427+ # Type
428428+429429+ ```
430430+ makeScope :: (AttrSet -> ((AttrSet -> a) | Path) -> AttrSet -> a) -> (AttrSet -> AttrSet) -> scope
431431+ ```
321432 */
322433 makeScope = newScope: f:
323434 let self = f self // {