sloth-flake.nvim/flakeModule.nix

68 lines
1.7 KiB
Nix
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

{config, ...}: {
config.flake.flakeModules.default = {
lib,
flake-parts-lib,
...
}: let
inherit (lib) attrsToList listToAttrs mkOption types;
inherit (flake-parts-lib) mkPerSystemOption;
topConfig = config;
in {
options.perSystem = mkPerSystemOption ({
pkgs,
config,
...
}: let
cfg = config.sloth;
sLib = cfg.lib;
packageModule = types.submodule ({config, ...}: {
options = {
module = mkOption {
description = "module used to create your neovim package";
type = types.deferredModule;
};
modules = mkOption {
description = "modules used to create your neovim package";
type = with types; listOf attrs;
default = [config.module];
};
specialArgs = mkOption {
description = "specialArgs to follow to your modules";
type = types.attrs;
default = {};
};
};
});
buildPackage = {
name,
value,
}: {
inherit name;
value = sLib.mkNeovimPkg {inherit (value) modules specialArgs;};
};
packagesList = map buildPackage (attrsToList cfg.packages);
in {
options.sloth = {
lib = mkOption {
type = types.attrs;
description = "sloths lib";
default = topConfig.flake.mkLib {inherit pkgs;};
defaultText = "mkLib {inherit pkgs;}";
};
packages = mkOption {
description = "neovim package to create with sloth";
default = {};
type = with types; attrsOf packageModule;
};
};
config.packages = listToAttrs packagesList;
});
};
}