···2323 { name = "sources"; description = "source filtering functions"; }
2424 { name = "cli"; description = "command-line serialization functions"; }
2525 { name = "gvariant"; description = "GVariant formatted string serialization functions"; }
2626+ { name = "customisation"; description = "Functions to customise (derivation-related) functions, derivatons, or attribute sets"; }
2627 ];
2728 };
2829
+69-19
lib/customisation.nix
···1313 scenarios (e.g. in ~/.config/nixpkgs/config.nix). For instance,
1414 if you want to "patch" the derivation returned by a package
1515 function in Nixpkgs to build another version than what the
1616- function itself provides, you can do something like this:
1717-1818- mySed = overrideDerivation pkgs.gnused (oldAttrs: {
1919- name = "sed-4.2.2-pre";
2020- src = fetchurl {
2121- url = ftp://alpha.gnu.org/gnu/sed/sed-4.2.2-pre.tar.bz2;
2222- hash = "sha256-MxBJRcM2rYzQYwJ5XKxhXTQByvSg5jZc5cSHEZoB2IY=";
2323- };
2424- patches = [];
2525- });
1616+ function itself provides.
26172718 For another application, see build-support/vm, where this
2819 function is used to build arbitrary derivations inside a QEMU
···35263627 You should in general prefer `drv.overrideAttrs` over this function;
3728 see the nixpkgs manual for more information on overriding.
2929+3030+ Example:
3131+ mySed = overrideDerivation pkgs.gnused (oldAttrs: {
3232+ name = "sed-4.2.2-pre";
3333+ src = fetchurl {
3434+ url = ftp://alpha.gnu.org/gnu/sed/sed-4.2.2-pre.tar.bz2;
3535+ hash = "sha256-MxBJRcM2rYzQYwJ5XKxhXTQByvSg5jZc5cSHEZoB2IY=";
3636+ };
3737+ patches = [];
3838+ });
3939+4040+ Type:
4141+ overrideDerivation :: Derivation -> ( Derivation -> AttrSet ) -> Derivation
3842 */
3943 overrideDerivation = drv: f:
4044 let
···5559 injects `override` attribute which can be used to override arguments of
5660 the function.
57616262+ Please refer to documentation on [`<pkg>.overrideDerivation`](#sec-pkg-overrideDerivation) to learn about `overrideDerivation` and caveats
6363+ related to its use.
6464+6565+ Example:
5866 nix-repl> x = {a, b}: { result = a + b; }
59676068 nix-repl> y = lib.makeOverridable x { a = 1; b = 2; }
···6573 nix-repl> y.override { a = 10; }
6674 { override = «lambda»; overrideDerivation = «lambda»; result = 12; }
67756868- Please refer to "Nixpkgs Contributors Guide" section
6969- "<pkg>.overrideDerivation" to learn about `overrideDerivation` and caveats
7070- related to its use.
7676+ Type:
7777+ makeOverridable :: (AttrSet -> a) -> AttrSet -> a
7178 */
7279 makeOverridable = f: lib.setFunctionArgs
7380 (origArgs: let
···105112 `autoArgs`. This function is intended to be partially
106113 parameterised, e.g.,
107114115115+ ```nix
108116 callPackage = callPackageWith pkgs;
109117 pkgs = {
110118 libfoo = callPackage ./foo.nix { };
111119 libbar = callPackage ./bar.nix { };
112120 };
121121+ ```
113122114123 If the `libbar` function expects an argument named `libfoo`, it is
115124 automatically passed as an argument. Overrides or missing
116125 arguments can be supplied in `args`, e.g.
117126127127+ ```nix
118128 libbar = callPackage ./bar.nix {
119129 libfoo = null;
120130 enableX11 = true;
121131 };
132132+ ```
133133+134134+ <!-- TODO: Apply "Example:" tag to the examples above -->
135135+136136+ Type:
137137+ callPackageWith :: AttrSet -> ((AttrSet -> a) | Path) -> AttrSet -> a
122138 */
123139 callPackageWith = autoArgs: fn: args:
124140 let
···129145 # This includes automatic ones and ones passed explicitly
130146 allArgs = builtins.intersectAttrs fargs autoArgs // args;
131147132132- # A list of argument names that the function requires, but
148148+ # a list of argument names that the function requires, but
133149 # wouldn't be passed to it
134150 missingArgs = lib.attrNames
135151 # Filter out arguments that have a default value
···176192177193 /* Like callPackage, but for a function that returns an attribute
178194 set of derivations. The override function is added to the
179179- individual attributes. */
195195+ individual attributes.
196196+197197+ Type:
198198+ callPackagesWith :: AttrSet -> ((AttrSet -> AttrSet) | Path) -> AttrSet -> AttrSet
199199+ */
180200 callPackagesWith = autoArgs: fn: args:
181201 let
182202 f = if lib.isFunction fn then fn else import fn;
···193213194214195215 /* Add attributes to each output of a derivation without changing
196196- the derivation itself and check a given condition when evaluating. */
216216+ the derivation itself and check a given condition when evaluating.
217217+218218+ Type:
219219+ extendDerivation :: Bool -> Any -> Derivation -> Derivation
220220+ */
197221 extendDerivation = condition: passthru: drv:
198222 let
199223 outputs = drv.outputs or [ "out" ];
···227251 /* Strip a derivation of all non-essential attributes, returning
228252 only those needed by hydra-eval-jobs. Also strictly evaluate the
229253 result to ensure that there are no thunks kept alive to prevent
230230- garbage collection. */
254254+ garbage collection.
255255+256256+ Type:
257257+ hydraJob :: (Derivation | Null) -> (Derivation | Null)
258258+ */
231259 hydraJob = drv:
232260 let
233261 outputs = drv.outputs or ["out"];
···265293 called with the overridden packages. The package sets may be
266294 hierarchical: the packages in the set are called with the scope
267295 provided by `newScope` and the set provides a `newScope` attribute
268268- which can form the parent scope for later package sets. */
296296+ which can form the parent scope for later package sets.
297297+298298+ Type:
299299+ makeScope :: (AttrSet -> ((AttrSet -> a) | Path) -> AttrSet -> a) -> (AttrSet -> AttrSet) -> AttrSet
300300+ */
269301 makeScope = newScope: f:
270302 let self = f self // {
271303 newScope = scope: newScope (self // scope);
···287319 { inherit otherSplices keep extra f; };
288320289321 /* Like makeScope, but aims to support cross compilation. It's still ugly, but
290290- hopefully it helps a little bit. */
322322+ hopefully it helps a little bit.
323323+324324+ Type:
325325+ makeScopeWithSplicing' ::
326326+ { splicePackages :: Splice -> AttrSet
327327+ , newScope :: AttrSet -> ((AttrSet -> a) | Path) -> AttrSet -> a
328328+ }
329329+ -> { otherSplices :: Splice, keep :: AttrSet -> AttrSet, extra :: AttrSet -> AttrSet }
330330+ -> AttrSet
331331+332332+ Splice ::
333333+ { pkgsBuildBuild :: AttrSet
334334+ , pkgsBuildHost :: AttrSet
335335+ , pkgsBuildTarget :: AttrSet
336336+ , pkgsHostHost :: AttrSet
337337+ , pkgsHostTarget :: AttrSet
338338+ , pkgsTargetTarget :: AttrSet
339339+ }
340340+ */
291341 makeScopeWithSplicing' =
292342 { splicePackages
293343 , newScope