diff options
Diffstat (limited to 'nixpkgs/doc/using/overrides.chapter.md')
-rw-r--r-- | nixpkgs/doc/using/overrides.chapter.md | 54 |
1 files changed, 32 insertions, 22 deletions
diff --git a/nixpkgs/doc/using/overrides.chapter.md b/nixpkgs/doc/using/overrides.chapter.md index a1ef9afb0b69..8c6ed79076c2 100644 --- a/nixpkgs/doc/using/overrides.chapter.md +++ b/nixpkgs/doc/using/overrides.chapter.md @@ -13,13 +13,13 @@ It is used to override the arguments passed to a function. Example usages: ```nix -pkgs.foo.override { arg1 = val1; arg2 = val2; ... } +pkgs.foo.override { arg1 = val1; arg2 = val2; /* ... */ } ``` It's also possible to access the previous arguments. ```nix -pkgs.foo.override (previous: { arg1 = previous.arg1; ... }) +pkgs.foo.override (previous: { arg1 = previous.arg1; /* ... */ }) ``` <!-- TODO: move below programlisting to a new section about extending and overlays and reference it --> @@ -27,13 +27,15 @@ pkgs.foo.override (previous: { arg1 = previous.arg1; ... }) ```nix import pkgs.path { overlays = [ (self: super: { foo = super.foo.override { barSupport = true ; }; - })]}; + })];} ``` ```nix -mypkg = pkgs.callPackage ./mypkg.nix { - mydep = pkgs.mydep.override { ... }; - } +{ + mypkg = pkgs.callPackage ./mypkg.nix { + mydep = pkgs.mydep.override { /* ... */ }; + }; +} ``` In the first example, `pkgs.foo` is the result of a function call with some default arguments, usually a derivation. Using `pkgs.foo.override` will call the same function with the given new arguments. @@ -45,9 +47,11 @@ The function `overrideAttrs` allows overriding the attribute set passed to a `st Example usages: ```nix -helloBar = pkgs.hello.overrideAttrs (finalAttrs: previousAttrs: { - pname = previousAttrs.pname + "-bar"; -}); +{ + helloBar = pkgs.hello.overrideAttrs (finalAttrs: previousAttrs: { + pname = previousAttrs.pname + "-bar"; + }); +} ``` In the above example, "-bar" is appended to the pname attribute, while all other attributes will be retained from the original `hello` package. @@ -61,9 +65,11 @@ If only a one-argument function is written, the argument has the meaning of `pre Function arguments can be omitted entirely if there is no need to access `previousAttrs` or `finalAttrs`. ```nix -helloWithDebug = pkgs.hello.overrideAttrs { - separateDebugInfo = true; -}; +{ + helloWithDebug = pkgs.hello.overrideAttrs { + separateDebugInfo = true; + }; +} ``` In the above example, the `separateDebugInfo` attribute is overridden to be true, thus building debug info for `helloWithDebug`. @@ -87,14 +93,16 @@ The function `overrideDerivation` creates a new derivation based on an existing Example usage: ```nix -mySed = pkgs.gnused.overrideDerivation (oldAttrs: { - name = "sed-4.2.2-pre"; - src = fetchurl { - url = "ftp://alpha.gnu.org/gnu/sed/sed-4.2.2-pre.tar.bz2"; - hash = "sha256-MxBJRcM2rYzQYwJ5XKxhXTQByvSg5jZc5cSHEZoB2IY="; - }; - patches = []; -}); +{ + mySed = pkgs.gnused.overrideDerivation (oldAttrs: { + name = "sed-4.2.2-pre"; + src = fetchurl { + url = "ftp://alpha.gnu.org/gnu/sed/sed-4.2.2-pre.tar.bz2"; + hash = "sha256-MxBJRcM2rYzQYwJ5XKxhXTQByvSg5jZc5cSHEZoB2IY="; + }; + patches = []; + }); +} ``` In the above example, the `name`, `src`, and `patches` of the derivation will be overridden, while all other attributes will be retained from the original derivation. @@ -112,8 +120,10 @@ The function `lib.makeOverridable` is used to make the result of a function easi Example usage: ```nix -f = { a, b }: { result = a+b; }; -c = lib.makeOverridable f { a = 1; b = 2; }; +{ + f = { a, b }: { result = a+b; }; + c = lib.makeOverridable f { a = 1; b = 2; }; +} ``` The variable `c` is the value of the `f` function applied with some default arguments. Hence the value of `c.result` is `3`, in this example. |