mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-23 17:28:39 +02:00
modules/dependencies: introduce top-level (internal) __depPackages option
This commit is contained in:
parent
710f9cbd52
commit
6c4e2d9279
1 changed files with 95 additions and 63 deletions
|
@ -5,9 +5,71 @@
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
|
inherit (lib) types;
|
||||||
|
|
||||||
cfg = config.dependencies;
|
cfg = config.dependencies;
|
||||||
|
|
||||||
packages = {
|
mkDependencyOption = name: properties: {
|
||||||
|
enable = lib.mkEnableOption "Add ${name} to dependencies.";
|
||||||
|
|
||||||
|
package =
|
||||||
|
lib.mkPackageOption pkgs name properties
|
||||||
|
# Handle example manually so that we can embed the original attr-path within
|
||||||
|
# the literalExpression object. This simplifies testing the examples.
|
||||||
|
// lib.optionalAttrs (properties.example != null) {
|
||||||
|
example =
|
||||||
|
if properties.example._type or null == "literalExpression" then
|
||||||
|
properties.example
|
||||||
|
else
|
||||||
|
rec {
|
||||||
|
_type = "literalExpression";
|
||||||
|
text = "pkgs.${lib.showAttrPath path}";
|
||||||
|
path = lib.toList properties.example;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options = {
|
||||||
|
__depPackages = lib.mkOption {
|
||||||
|
type = types.attrsOf (
|
||||||
|
types.submodule {
|
||||||
|
options = {
|
||||||
|
default = lib.mkOption {
|
||||||
|
type = with types; either str (listOf str);
|
||||||
|
description = ''
|
||||||
|
Default name (or path) for this package.
|
||||||
|
'';
|
||||||
|
example = "git";
|
||||||
|
};
|
||||||
|
|
||||||
|
example = lib.mkOption {
|
||||||
|
type = with types; nullOr str;
|
||||||
|
description = ''
|
||||||
|
Example of another package to use instead of the default.
|
||||||
|
'';
|
||||||
|
example = "gitMinimal";
|
||||||
|
default = null;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
default = { };
|
||||||
|
internal = true;
|
||||||
|
visible = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
dependencies = lib.mapAttrs mkDependencyOption config.__depPackages;
|
||||||
|
};
|
||||||
|
|
||||||
|
config = {
|
||||||
|
extraPackages = lib.pipe cfg [
|
||||||
|
builtins.attrValues
|
||||||
|
(builtins.filter (p: p.enable))
|
||||||
|
(builtins.map (p: p.package))
|
||||||
|
];
|
||||||
|
|
||||||
|
__depPackages = {
|
||||||
bat.default = "bat";
|
bat.default = "bat";
|
||||||
codeium.default = "codeium";
|
codeium.default = "codeium";
|
||||||
coreutils = {
|
coreutils = {
|
||||||
|
@ -67,35 +129,5 @@ let
|
||||||
yq.default = "yq";
|
yq.default = "yq";
|
||||||
zk.default = "zk";
|
zk.default = "zk";
|
||||||
};
|
};
|
||||||
|
|
||||||
mkDependencyOption = name: properties: {
|
|
||||||
enable = lib.mkEnableOption "Add ${name} to dependencies.";
|
|
||||||
|
|
||||||
package =
|
|
||||||
lib.mkPackageOption pkgs name properties
|
|
||||||
# Handle example manually so that we can embed the original attr-path within
|
|
||||||
# the literalExpression object. This simplifies testing the examples.
|
|
||||||
// lib.optionalAttrs (properties ? example) {
|
|
||||||
example =
|
|
||||||
if properties.example._type or null == "literalExpression" then
|
|
||||||
properties.example
|
|
||||||
else
|
|
||||||
rec {
|
|
||||||
_type = "literalExpression";
|
|
||||||
text = "pkgs.${lib.showAttrPath path}";
|
|
||||||
path = lib.toList properties.example;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
in
|
|
||||||
{
|
|
||||||
options.dependencies = lib.mapAttrs mkDependencyOption packages;
|
|
||||||
|
|
||||||
config = {
|
|
||||||
extraPackages = lib.pipe cfg [
|
|
||||||
builtins.attrValues
|
|
||||||
(builtins.filter (p: p.enable))
|
|
||||||
(builtins.map (p: p.package))
|
|
||||||
];
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue