wrappers: make _shared.nix return a module

This commit is contained in:
Matt Sturgeon 2024-07-08 05:00:44 +01:00
parent 97fa47376b
commit cfa44bbb66
No known key found for this signature in database
GPG key ID: 4F91844CED1A8299
4 changed files with 75 additions and 38 deletions

View file

@ -1,37 +1,65 @@
helpers:
{
# Our helpers
helpers,
# Option path where extraFiles should go
filesOpt ? null,
# Filepath prefix to apply to extraFiles
filesPrefix ? "nvim/",
# Filepath to use when adding `cfg.initPath` to `filesOpt`
# Is prefixed with `filesPrefix`
initName ? "init.lua",
}:
{ lib, config, ... }:
let
inherit (lib)
isAttrs
listToAttrs
map
mkIf
mkMerge
mkOption
mkOptionType
optionalAttrs
setAttrByPath
;
cfg = config.programs.nixvim;
extraFiles = lib.filter (file: file.enable) (lib.attrValues cfg.extraFiles);
in
{
helpers = mkOption {
type = mkOptionType {
name = "helpers";
description = "Helpers that can be used when writing nixvim configs";
check = isAttrs;
options = {
nixvim.helpers = mkOption {
type = mkOptionType {
name = "helpers";
description = "Helpers that can be used when writing nixvim configs";
check = isAttrs;
};
description = "Use this option to access the helpers";
};
description = "Use this option to access the helpers";
default = helpers;
};
# extraFiles, but nested under "nvim/" for use in etc/xdg config
configFiles = listToAttrs (
map (
{ target, source, ... }:
{
name = "nvim/" + target;
value = {
inherit source;
};
}
) extraFiles
);
config = mkMerge [
# Make our lib available to the host modules
{ nixvim.helpers = lib.mkDefault helpers; }
# Propagate extraFiles to the host modules
(optionalAttrs (filesOpt != null) (
mkIf (!cfg.wrapRc) (
setAttrByPath filesOpt (
listToAttrs (
map (
{ target, source, ... }:
{
name = filesPrefix + target;
value = {
inherit source;
};
}
) extraFiles
)
// {
${filesPrefix + initName}.source = cfg.initPath;
}
)
)
))
];
}