Skip to content

mkPackageOption helper with defaultText #1950

Closed
@MattSturgeon

Description

@MattSturgeon

Nixpkgs has lib.mkPackageOption (documentation, noogle, source) which takes a "pkgs path" and produces an option with an appropriate default and literalExpression defaultText.

# e.g.
lib.mkPackageOption pkgs "hello" { }
# is like
lib.mkOption {
  type = lib.types.package;
  default = pkgs.hello;
  defaultText = lib.literalExpression "pkgs.hello";
  description = "The hello package to use.";
}

We should use this where possible, and copy the implementation in our nullable version.

We could do this in a non-breaking way by having our nullable helper check the pkg arg type; lists and strings can be pkgs-paths while derivations should be actual packages.

Eventually, we could warn when a derivation is passed in to hunt down any remaining call sites, but I see this more as something that can improve future code rather than something we should be in a hurry to migrate existing code to.

TODO:

  • Add support to mkVimPlugin and mkNeovimPlugin
    lib/*-plugins: initial support for lib.mkPackageOption #2139
  • Implement fancier support (i.e. adding the option within mkNeovimPlugin, using an imported module)
  • Migrate all plugins defaultPackage
  • Remove the deprecated helpers (mkPackageOption & mkPluginPackageOption)

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationenhancementNew feature or requesttech debtRelated to technical debt and/or refactoring

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions