Unverified Commit 7e24b361 authored by Anselm Schüler's avatar Anselm Schüler
Browse files

lib/options: refactor mkPackageOption

parent 55ab538a
Loading
Loading
Loading
Loading
+13 −13
Original line number Diff line number Diff line
@@ -201,21 +201,21 @@ rec {
      }:
      let
        name' = if isList name then last name else name;
      in mkOption ({
        type = with lib.types; (if nullable then nullOr else lib.id) package;
        description = "The ${name'} package to use."
          + (if extraDescription == "" then "" else " ") + extraDescription;
      } // (if default != null then let
        default' = if isList default then default else [ default ];
        defaultPath = concatStringsSep "." default';
        defaultText = concatStringsSep "." default';
        defaultValue = attrByPath default'
          (throw "${defaultPath} cannot be found in ${pkgsText}") pkgs;
      in {
          (throw "${defaultText} cannot be found in ${pkgsText}") pkgs;
        defaults = if default != null then {
          default = defaultValue;
        defaultText = literalExpression ("${pkgsText}." + defaultPath);
      } else if nullable then {
          defaultText = literalExpression ("${pkgsText}." + defaultText);
        } else optionalAttrs nullable {
          default = null;
      } else { }) // lib.optionalAttrs (example != null) {
        };
      in mkOption (defaults // {
        description = "The ${name'} package to use."
          + (if extraDescription == "" then "" else " ") + extraDescription;
        type = with lib.types; (if nullable then nullOr else lib.id) package;
      } // optionalAttrs (example != null) {
        example = literalExpression
          (if isList example then "${pkgsText}." + concatStringsSep "." example else example);
      });