HOME TOC REPO
1   ===============================================================================
2   Nix OS Module                                    nixCats.module
3                                     nixCats.module.mkNixosModules
4                                      nixCats.module.mkHomeModules
5   
6   We create the module by exporting the following in our flake outputs.
7   
8   <mkNixosModules> {
9       defaultPackageName = "nixCats";
10      luaPath = "${./.}";
11      inherit nixpkgs dependencyOverlays
12        categoryDefinitions packageDefinitions extra_pkg_config;
13  };
14  
15  <mkHomeModules> {
16      defaultPackageName = "nixCats";
17      luaPath = "${./.}";
18      inherit nixpkgs dependencyOverlays
19        categoryDefinitions packageDefinitions extra_pkg_config;
20  };
21  
22  where dependencyOverlays is a set of system names
23  with lists of overlays in each item. Such that
24  the lists would be accessed via dependencyOverlays.${system}
25  
26  If you do not have a luaPath, you may pass it a keepLua builder.
27  utils.mkNixosModules exports a nixos module with the following options,
28  and utils.mkHomeModules exports a home-manager module with the SAME EXACT options
29  as the nixos module has for system, but for the user managed by home-manager.
30  
31  IMPORTANT
32  By default, the module inherits pkgs.config from the system's pkgs object,
33  and its overlays AND the flake's overlays and nixCats config,
34  as well as the flake's nixpkgs source (by default).
35  It will inherit things from your system,
36  but your system will not inherit things from nixCats,
37  other than the packages themselves in config.${defaultPackageName}.out
38  
39  
40    options = with lib; {
41  
42      # Set these with ${defaultPackageName} in your configuration.nix
43      ${defaultPackageName} = {
44  
45        nixpkgs_version = mkOption {
46          default = null;
47          type = types.nullOr (types.anything);
48          description = ''
49            a different nixpkgs import to use. By default will use the one from the flake, or `pkgs.path`.
50          '';
51          example = ''
52            nixpkgs_version = inputs.nixpkgs
53          '';
54        };
55  
56        addOverlays = mkOption {
57          default = [];
58          type = (types.listOf types.anything);
59          description = ''
60            A list of overlays to make available to any nixCats package from this module but not to your system.
61            Will have access to system overlays regardless of this setting.
62          '';
63          example = (lib.literalExpression ''
64            addOverlays = [ (self: super: { nvimPlugins = { pluginDerivationName = pluginDerivation; }; }) ]
65          '');
66        };
67  
68        enable = mkOption {
69          default = false;
70          type = types.bool;
71          description = "Enable the ${defaultPackageName} module";
72        };
73  
74        dontInstall = mkOption {
75          default = false;
76          type = types.bool;
77          description = ''
78            If true, do not output to packages list,
79            output only to config.${defaultPackageName}.out
80          '';
81        };
82  
83        luaPath = mkOption {
84          default = luaPath;
85          type = types.oneOf [ types.str types.path ];
86          description = (literalExpression ''
87            The path to your nvim config directory in the store.
88            In the base nixCats flake, this is "${./.}".
89          '');
90          example = (literalExpression "${./.}/userLuaConfig");
91        };
92  
93        packageNames = mkOption {
94          default = if packageDefinitions ? defaultPackageName then [ "${defaultPackageName}" ] else [];
95          type = (types.listOf types.str);
96          description = ''A list of packages from packageDefinitions to include'';
97          example = ''
98            packageNames = [ "nixCats" ]
99          '';
100       };
101 
102       categoryDefinitions = {
103         existing = mkOption {
104           default = "replace";
105           type = types.enum [ "replace" "merge" "discard" ];
106           description = ''
107             the merge strategy to use for categoryDefinitions inherited from the package this module was based on
108             choose between "replace", "merge" or "discard"
109             replace uses utils.mergeCatDefs
110             merge uses utils.deepmergeCats
111             discard does not inherit
112             see :help nixCats.flake.outputs.exports for more info on the merge strategy options
113           '';
114         };
115         replace = mkOption {
116           default = null;
117           type = types.nullOr (catDef "replace");
118           description = (literalExpression ''
119             see :help nixCats.flake.outputs.categories
120             uses utils.mergeCatDefs to recursively update old categories with new values
121             see :help nixCats.flake.outputs.exports for more info on the merge strategy options
122           '');
123           example = ''
124             # see :help nixCats.flake.outputs.categories
125             categoryDefinitions.replace = { pkgs, settings, categories, name, ... }@packageDef: { }
126           '';
127         };
128         merge = mkOption {
129           default = null;
130           type = types.nullOr (catDef "merge");
131           description = ''
132             see :help nixCats.flake.outputs.categories
133             uses utils.deepmergeCats to recursively update and merge category lists if duplicates are defined
134             see :help nixCats.flake.outputs.exports for more info on the merge strategy options
135           '';
136           example = ''
137             # see :help nixCats.flake.outputs.categories
138             categoryDefinitions.merge = { pkgs, settings, categories, name, ... }@packageDef: { }
139           '';
140         };
141       };
142 
143       packageDefinitions = {
144         existing = mkOption {
145           default = "replace";
146           type = types.enum [ "replace" "merge" "discard" ];
147           description = ''
148             the merge strategy to use for packageDefinitions inherited from the package this module was based on
149             choose between "replace", "merge" or "discard"
150             replace uses utils.mergeCatDefs
151             merge uses utils.deepmergeCats
152             discard does not inherit
153             see :help nixCats.flake.outputs.exports for more info on the merge strategy options
154           '';
155         };
156         merge = mkOption {
157           default = null;
158           description = ''
159             VERY IMPORTANT when setting aliases for each package,
160             they must not be the same as ANY other neovim package for that user.
161             It will cause a build conflict.
162 
163             You can have as many nixCats installed per user as you want,
164             as long as you obey that rule.
165 
166             for information on the values you may return,
167             see :help nixCats.flake.outputs.settings
168             and :help nixCats.flake.outputs.categories
169           '';
170           type = with types; nullOr (attrsOf (catDef "merge"));
171           example = ''
172             nixCats.packages = { 
173               nixCats = { pkgs, ... }: {
174                 settings = {
175                   wrapRc = true;
176                   configDirName = "nixCats-nvim";
177                   # nvimSRC = inputs.neovim;
178                   aliases = [ "vim" "nixCats" ];
179                 };
180                 categories = {
181                   generalBuildInputs = true;
182                   markdown = true;
183                   gitPlugins = true;
184                   general = true;
185                   custom = true;
186                   neonixdev = true;
187                   debug = false;
188                   test = true;
189                   lspDebugMode = false;
190                   themer = true;
191                   colorscheme = "onedark";
192                 };
193               };
194             }
195           '';
196         };
197         replace = mkOption {
198           default = null;
199           description = ''
200             VERY IMPORTANT when setting aliases for each package,
201             they must not be the same as ANY other neovim package for that user.
202             It will cause a build conflict.
203 
204             You can have as many nixCats installed per user as you want,
205             as long as you obey that rule.
206 
207             for information on the values you may return,
208             see :help nixCats.flake.outputs.settings
209             and :help nixCats.flake.outputs.categories
210           '';
211           type = with types; nullOr (attrsOf (catDef "replace"));
212           example = ''
213             nixCats.packages = { 
214               nixCats = { pkgs, ... }: {
215                 settings = {
216                   wrapRc = true;
217                   configDirName = "nixCats-nvim";
218                   # nvimSRC = inputs.neovim;
219                   aliases = [ "vim" "nixCats" ];
220                 };
221                 categories = {
222                   generalBuildInputs = true;
223                   markdown = true;
224                   gitPlugins = true;
225                   general = true;
226                   custom = true;
227                   neonixdev = true;
228                   debug = false;
229                   test = true;
230                   lspDebugMode = false;
231                   themer = true;
232                   colorscheme = "onedark";
233                 };
234               };
235             }
236           '';
237         };
238       };
239 
240       # in addition, the nixos module also has per-user options if desired.
241 
242       users = mkOption {
243         default = {};
244         description = ''
245           same as system config but per user instead
246         '';
247         type = with types; attrsOf (submodule {
248           options = {
249             enable = mkOption {
250               default = false;
251               type = types.bool;
252               description = "Enable the ${defaultPackageName} module for a user";
253             };
254 
255             luaPath = mkOption {
256               default = luaPath;
257               type = types.str;
258               description = ''
259                 The path to your nvim config directory in the store.
260                 In the base nixCats flake, this is "''${./.}".
261               '';
262               example = ''"''${./.}/userLuaConfig"'';
263             };
264 
265             # the same options but per user....
266             # Not shown here because its the same.
267           };
268         });
269       };
270     };
271   };
272 
273 
274 I have condensed it here, but notice at the end it outputs
275 all the same options for each user when in a nixosModule as well?
276 
277 in addition, there are some config values that can be used to reference the
278 configs made in the module
279 
280   config.${defaultPackageName}.out.packages.<PACKAGE_NAME>
281 
282 
283 and if using the nixos module there is ALSO
284 
285   config.${defaultPackageName}.out.users.<USER_NAME>.packages.<PACKAGE_NAME>
286 
287 ---------------------------------------------------------------------------------------
288 vim:tw=78:ts=8:ft=help:norl: