lol
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

lib/options: nullable mkPackageOption

It is sometimes useful to allow setting a package option to `null` to
skip installing the package. See
https://github.com/nix-community/home-manager/pull/3668#issuecomment-1554044171
for example.

+14 -7
+14 -7
lib/options.nix
··· 155 155 # Name for the package, shown in option description 156 156 name: 157 157 { 158 + # Whether the package can be null, for example to disable installing a package altogether. 159 + nullable ? false, 158 160 # The attribute path where the default package is located (may be omitted) 159 161 default ? name, 160 162 # A string or an attribute path to use as an example (may be omitted) ··· 164 166 }: 165 167 let 166 168 name' = if isList name then last name else name; 169 + in mkOption ({ 170 + type = with lib.types; (if nullable then nullOr else lib.id) package; 171 + description = "The ${name'} package to use." 172 + + (if extraDescription == "" then "" else " ") + extraDescription; 173 + } // (if default != null then let 167 174 default' = if isList default then default else [ default ]; 168 175 defaultPath = concatStringsSep "." default'; 169 176 defaultValue = attrByPath default' 170 177 (throw "${defaultPath} cannot be found in pkgs") pkgs; 171 - in mkOption { 178 + in { 179 + default = defaultValue; 172 180 defaultText = literalExpression ("pkgs." + defaultPath); 173 - type = lib.types.package; 174 - description = "The ${name'} package to use." 175 - + (if extraDescription == "" then "" else " ") + extraDescription; 176 - ${if default != null then "default" else null} = defaultValue; 177 - ${if example != null then "example" else null} = literalExpression 181 + } else if nullable then { 182 + default = null; 183 + } else { }) // lib.optionalAttrs (example != null) { 184 + example = literalExpression 178 185 (if isList example then "pkgs." + concatStringsSep "." example else example); 179 - }; 186 + }); 180 187 181 188 /* Like mkPackageOption, but emit an mdDoc description instead of DocBook. */ 182 189 mkPackageOptionMD = pkgs: name: extra: