-
-
Notifications
You must be signed in to change notification settings - Fork 292
/
_shared.nix
99 lines (93 loc) · 2.4 KB
/
_shared.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
{
# The nixvim flake
self,
# Extra args for the `evalNixvim` call that produces the type for `programs.nixvim`
evalArgs ? { },
# 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",
}:
{
pkgs,
lib,
config,
...
}:
let
inherit (lib)
listToAttrs
map
mkIf
mkMerge
mkOption
optionalAttrs
setAttrByPath
;
cfg = config.programs.nixvim;
nixvimConfiguration = config.lib.nixvim.modules.evalNixvim (
evalArgs
// {
modules = evalArgs.modules or [ ] ++ [
# Use global packages by default in nixvim's submodule
# TODO: `useGlobalPackages` option and/or deprecate using host packages?
{
_file = ./_shared.nix;
nixpkgs.pkgs = lib.mkDefault pkgs;
}
];
}
);
extraFiles = lib.filter (file: file.enable) (lib.attrValues cfg.extraFiles);
in
{
_file = ./_shared.nix;
options.programs.nixvim = lib.mkOption {
inherit (nixvimConfiguration) type;
default = { };
};
# TODO: Added 2024-07-24; remove after 24.11
imports = [
(lib.mkRenamedOptionModule [ "nixvim" "helpers" ] [ "lib" "nixvim" ])
];
config = mkMerge [
{
# Make our lib available to the host modules
# NOTE: user-facing so we must include the legacy `pkgs` argument
lib.nixvim = lib.mkDefault (
import ../lib {
inherit lib;
flake = self;
}
);
# Make nixvim's "extended" lib available to the host's module args
_module.args.nixvimLib = lib.mkDefault config.lib.nixvim.extendedLib;
}
# Propagate nixvim's assertions to the host modules
(lib.mkIf cfg.enable { inherit (cfg) warnings assertions; })
# Propagate extraFiles to the host modules
(optionalAttrs (filesOpt != null) (
mkIf (cfg.enable && !cfg.wrapRc) (
setAttrByPath filesOpt (
listToAttrs (
map (
{ target, finalSource, ... }:
{
name = filesPrefix + target;
value = {
source = finalSource;
};
}
) extraFiles
)
// {
${filesPrefix + initName}.source = cfg.build.initFile;
}
)
)
))
];
}