From a9a1a4645814053935976406e25b5e4c43f60a02 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sun, 14 Nov 2021 15:53:00 +0300 Subject: Note recommended use of 'or' in override patterns This fixes #6 --- nix/nix-1p/README.md | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/nix/nix-1p/README.md b/nix/nix-1p/README.md index 6cc37634ed..bdb49c7def 100644 --- a/nix/nix-1p/README.md +++ b/nix/nix-1p/README.md @@ -549,7 +549,7 @@ like this: ```nix someProgram.overrideAttrs(old: { - configureFlags = old.configureFlags ++ ["--mimic-threaten-tag"]; + configureFlags = old.configureFlags or [] ++ ["--mimic-threaten-tag"]; }) ``` @@ -557,6 +557,13 @@ This pattern has a variety of applications of varying complexity. The top-level package set itself can have an `overlays` argument passed to it which may add new packages to the imported set. +Note the use of the `or` operator to default to an empty list if the +original flags do not include `configureFlags`. This is required in +case a package does not set any flags by itself. + +Since this can change in a package over time, it is useful to guard +against it using `or`. + For a slightly more advanced example, assume that we want to import `` but have the modification above be reflected in the imported package set: @@ -564,7 +571,7 @@ but have the modification above be reflected in the imported package set: let overlay = (self: super: { someProgram = super.someProgram.overrideAttrs(old: { - configureFlags = old.configureFlags ++ ["--mimic-threaten-tag"]; + configureFlags = old.configureFlags or [] ++ ["--mimic-threaten-tag"]; }); }); in import { overlays = [ overlay ]; } -- cgit 1.4.1