mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 00:25:42 +02:00
wrappers: make _shared.nix
return a module
This commit is contained in:
parent
97fa47376b
commit
cfa44bbb66
4 changed files with 75 additions and 38 deletions
|
@ -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, ... }:
|
{ lib, config, ... }:
|
||||||
let
|
let
|
||||||
inherit (lib)
|
inherit (lib)
|
||||||
isAttrs
|
isAttrs
|
||||||
listToAttrs
|
listToAttrs
|
||||||
map
|
map
|
||||||
|
mkIf
|
||||||
|
mkMerge
|
||||||
mkOption
|
mkOption
|
||||||
mkOptionType
|
mkOptionType
|
||||||
|
optionalAttrs
|
||||||
|
setAttrByPath
|
||||||
;
|
;
|
||||||
cfg = config.programs.nixvim;
|
cfg = config.programs.nixvim;
|
||||||
extraFiles = lib.filter (file: file.enable) (lib.attrValues cfg.extraFiles);
|
extraFiles = lib.filter (file: file.enable) (lib.attrValues cfg.extraFiles);
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
helpers = mkOption {
|
options = {
|
||||||
|
nixvim.helpers = mkOption {
|
||||||
type = mkOptionType {
|
type = mkOptionType {
|
||||||
name = "helpers";
|
name = "helpers";
|
||||||
description = "Helpers that can be used when writing nixvim configs";
|
description = "Helpers that can be used when writing nixvim configs";
|
||||||
check = isAttrs;
|
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
|
config = mkMerge [
|
||||||
configFiles = listToAttrs (
|
# 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 (
|
map (
|
||||||
{ target, source, ... }:
|
{ target, source, ... }:
|
||||||
{
|
{
|
||||||
name = "nvim/" + target;
|
name = filesPrefix + target;
|
||||||
value = {
|
value = {
|
||||||
inherit source;
|
inherit source;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
) extraFiles
|
) extraFiles
|
||||||
);
|
)
|
||||||
|
// {
|
||||||
|
${filesPrefix + initName}.source = cfg.initPath;
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
))
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,6 @@ let
|
||||||
types
|
types
|
||||||
;
|
;
|
||||||
helpers = getHelpers pkgs false;
|
helpers = getHelpers pkgs false;
|
||||||
shared = import ./_shared.nix helpers args;
|
|
||||||
cfg = config.programs.nixvim;
|
cfg = config.programs.nixvim;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
|
@ -36,9 +35,10 @@ in
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
nixvim.helpers = shared.helpers;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
imports = [ (import ./_shared.nix { inherit helpers; }) ];
|
||||||
|
|
||||||
config = mkIf cfg.enable (mkMerge [
|
config = mkIf cfg.enable (mkMerge [
|
||||||
{
|
{
|
||||||
environment.systemPackages = [
|
environment.systemPackages = [
|
||||||
|
|
|
@ -15,11 +15,7 @@ let
|
||||||
types
|
types
|
||||||
;
|
;
|
||||||
helpers = getHelpers pkgs false;
|
helpers = getHelpers pkgs false;
|
||||||
shared = import ./_shared.nix helpers args;
|
|
||||||
cfg = config.programs.nixvim;
|
cfg = config.programs.nixvim;
|
||||||
files = shared.configFiles // {
|
|
||||||
"nvim/init.lua".source = cfg.initPath;
|
|
||||||
};
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options = {
|
options = {
|
||||||
|
@ -38,9 +34,18 @@ in
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
nixvim.helpers = shared.helpers;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
imports = [
|
||||||
|
(import ./_shared.nix {
|
||||||
|
inherit helpers;
|
||||||
|
filesOpt = [
|
||||||
|
"xdg"
|
||||||
|
"configFile"
|
||||||
|
];
|
||||||
|
})
|
||||||
|
];
|
||||||
|
|
||||||
config = mkIf cfg.enable (mkMerge [
|
config = mkIf cfg.enable (mkMerge [
|
||||||
{
|
{
|
||||||
home.packages = [
|
home.packages = [
|
||||||
|
@ -48,7 +53,6 @@ in
|
||||||
cfg.printInitPackage
|
cfg.printInitPackage
|
||||||
] ++ (lib.optional cfg.enableMan self.packages.${pkgs.stdenv.hostPlatform.system}.man-docs);
|
] ++ (lib.optional cfg.enableMan self.packages.${pkgs.stdenv.hostPlatform.system}.man-docs);
|
||||||
}
|
}
|
||||||
(mkIf (!cfg.wrapRc) { xdg.configFile = files; })
|
|
||||||
{
|
{
|
||||||
inherit (cfg) warnings assertions;
|
inherit (cfg) warnings assertions;
|
||||||
home.sessionVariables = mkIf cfg.defaultEditor { EDITOR = "nvim"; };
|
home.sessionVariables = mkIf cfg.defaultEditor { EDITOR = "nvim"; };
|
||||||
|
|
|
@ -16,11 +16,7 @@ let
|
||||||
types
|
types
|
||||||
;
|
;
|
||||||
helpers = getHelpers pkgs false;
|
helpers = getHelpers pkgs false;
|
||||||
shared = import ./_shared.nix helpers args;
|
|
||||||
cfg = config.programs.nixvim;
|
cfg = config.programs.nixvim;
|
||||||
files = shared.configFiles // {
|
|
||||||
"nvim/sysinit.lua".source = cfg.initPath;
|
|
||||||
};
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options = {
|
options = {
|
||||||
|
@ -39,9 +35,19 @@ in
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
nixvim.helpers = shared.helpers;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
imports = [
|
||||||
|
(import ./_shared.nix {
|
||||||
|
inherit helpers;
|
||||||
|
filesOpt = [
|
||||||
|
"environment"
|
||||||
|
"etc"
|
||||||
|
];
|
||||||
|
initName = "sysinit.lua";
|
||||||
|
})
|
||||||
|
];
|
||||||
|
|
||||||
config = mkIf cfg.enable (mkMerge [
|
config = mkIf cfg.enable (mkMerge [
|
||||||
{
|
{
|
||||||
environment.systemPackages = [
|
environment.systemPackages = [
|
||||||
|
@ -49,14 +55,13 @@ in
|
||||||
cfg.printInitPackage
|
cfg.printInitPackage
|
||||||
] ++ (lib.optional cfg.enableMan self.packages.${pkgs.stdenv.hostPlatform.system}.man-docs);
|
] ++ (lib.optional cfg.enableMan self.packages.${pkgs.stdenv.hostPlatform.system}.man-docs);
|
||||||
}
|
}
|
||||||
(mkIf (!cfg.wrapRc) {
|
|
||||||
environment.etc = files;
|
|
||||||
environment.variables."VIM" = "/etc/nvim";
|
|
||||||
})
|
|
||||||
{
|
{
|
||||||
inherit (cfg) warnings assertions;
|
inherit (cfg) warnings assertions;
|
||||||
programs.neovim.defaultEditor = cfg.defaultEditor;
|
programs.neovim.defaultEditor = cfg.defaultEditor;
|
||||||
environment.variables.EDITOR = mkIf cfg.defaultEditor (lib.mkOverride 900 "nvim");
|
environment.variables = {
|
||||||
|
VIM = mkIf (!cfg.wrapRc) "/etc/nvim";
|
||||||
|
EDITOR = mkIf cfg.defaultEditor (lib.mkOverride 900 "nvim");
|
||||||
|
};
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue