forked from nix-community/nixvim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfiles.nix
112 lines (105 loc) · 3.04 KB
/
files.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
100
101
102
103
104
105
106
107
108
109
110
111
112
{
lib,
helpers,
pkgs,
config,
...
}:
let
fileTypeModule =
{
name,
config,
options,
topConfig,
...
}:
{
options = {
enable = lib.mkOption {
type = lib.types.bool;
default = true;
description = ''
Whether this file should be generated.
This option allows specific files to be disabled.
'';
};
target = lib.mkOption {
type = lib.types.str;
defaultText = lib.literalMD "the attribute name";
description = ''
Name of symlink, relative to nvim config.
'';
};
text = lib.mkOption {
type = with lib.types; nullOr lines;
default = null;
description = "Text of the file.";
};
source = lib.mkOption {
type = lib.types.path;
description = "Path of the source file.";
};
finalSource = lib.mkOption {
type = lib.types.path;
description = "Path to the final source file.";
readOnly = true;
visible = false;
internal = true;
};
};
config =
let
derivationName = "nvim-" + lib.replaceStrings [ "/" ] [ "-" ] name;
in
{
target = lib.mkDefault name;
source = lib.mkIf (config.text != null) (
# mkDerivedConfig uses the option's priority, and calls our function with the option's value.
# This means our `source` definition has the same priority as `text`.
lib.mkDerivedConfig options.text (pkgs.writeText derivationName)
);
finalSource =
# Byte compile lua files if performance.byteCompileLua option is enabled
if
lib.hasSuffix ".lua" config.target
&& topConfig.performance.byteCompileLua.enable
&& topConfig.performance.byteCompileLua.configs
then
if lib.isDerivation config.source then
# Source is a derivation
helpers.byteCompileLuaDrv config.source
else
# Source is a path or string
helpers.byteCompileLuaFile derivationName config.source
else
config.source;
};
};
fileType = lib.types.submoduleWith {
shorthandOnlyDefinesConfig = true;
modules = [ fileTypeModule ];
specialArgs.topConfig = config;
};
# TODO: Added 2024-07-07, remove after 24.11
# Before we had a fileType, we used types.str.
coercedFileType = helpers.transitionType lib.types.str (text: { inherit text; }) fileType;
in
{
options = {
extraFiles = lib.mkOption {
type = lib.types.attrsOf coercedFileType;
description = "Extra files to add to the runtime path";
default = { };
example = lib.literalExpression ''
{
"ftplugin/nix.lua".text = '''
vim.opt.tabstop = 2
vim.opt.shiftwidth = 2
vim.opt.expandtab = true
''';
}
'';
};
};
}