summary refs log tree commit diff
diff options
context:
space:
mode:
authorAnselm Schüler <mail@anselmschueler.com>2023-10-06 12:51:23 +0200
committerAnselm Schüler <mail@anselmschueler.com>2023-10-10 13:14:17 +0200
commit7e24b3619f6f7180988931d6743d2c7f2f5b8713 (patch)
treee0a25bdda92c6704ed8dd713458ac133d9d45226
parent55ab538abf0a476ad731ed7411063d966f832439 (diff)
downloadnixpkgs-7e24b3619f6f7180988931d6743d2c7f2f5b8713.tar
nixpkgs-7e24b3619f6f7180988931d6743d2c7f2f5b8713.tar.gz
nixpkgs-7e24b3619f6f7180988931d6743d2c7f2f5b8713.tar.bz2
nixpkgs-7e24b3619f6f7180988931d6743d2c7f2f5b8713.tar.lz
nixpkgs-7e24b3619f6f7180988931d6743d2c7f2f5b8713.tar.xz
nixpkgs-7e24b3619f6f7180988931d6743d2c7f2f5b8713.tar.zst
nixpkgs-7e24b3619f6f7180988931d6743d2c7f2f5b8713.zip
lib/options: refactor mkPackageOption
-rw-r--r--lib/options.nix26
1 files changed, 13 insertions, 13 deletions
diff --git a/lib/options.nix b/lib/options.nix
index 30fc61c22db..7821924873d 100644
--- a/lib/options.nix
+++ b/lib/options.nix
@@ -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 {
-        default = defaultValue;
-        defaultText = literalExpression ("${pkgsText}." + defaultPath);
-      } else if nullable then {
-        default = null;
-      } else { }) // lib.optionalAttrs (example != null) {
+          (throw "${defaultText} cannot be found in ${pkgsText}") pkgs;
+        defaults = if default != null then {
+          default = defaultValue;
+          defaultText = literalExpression ("${pkgsText}." + defaultText);
+        } else optionalAttrs nullable {
+          default = 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);
       });