Skip to content

Commit 4fb9933

Browse files
committed
modules, overlays, lib
fixes #10
1 parent a50860f commit 4fb9933

File tree

1 file changed

+74
-1
lines changed

1 file changed

+74
-1
lines changed

README.md

+74-1
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,80 @@ option to a path relative to the repository root:
197197
}
198198
```
199199

200+
## Conventions for NixOS modules, overlays and library functions
201+
202+
To make NixOS modules, overlays and library functions more discoverable,
203+
we propose to put them in their own namespace within the repository.
204+
This allows us to make them later searchable, when the indexer is ready.
205+
206+
Put all NixOS modules in the `modules` attribute of your repository:
207+
208+
```nix
209+
# default.nix
210+
modules = ./import modules;
211+
```
212+
213+
```nix
214+
# modules/default.nix
215+
{
216+
example-module = ./import example-module.nix;
217+
}
218+
```
219+
220+
An example can be found [here](https://github.com/Mic92/nur-packages/tree/master/modules).
221+
222+
The resulting module can be then added to `imports = [];` within `configuration.nix`:
223+
224+
```nix
225+
# /etc/nixos/configuration.nix
226+
{...}: {
227+
imports = [ nur.repos.mic92.modules.transocks ];
228+
}
229+
```
230+
231+
For overlays use the `overlays` attribute:
232+
233+
```nix
234+
# default.nix
235+
overlays = {
236+
hello-overlay = ./import hello-overlay;
237+
};
238+
```
239+
240+
```nix
241+
# hello-overlay/default.nix
242+
self: super: {
243+
hello = super.hello.overrideAttrs (old: {
244+
separateDebugInfo = true;
245+
});
246+
}
247+
```
248+
249+
The result can be used like this:
250+
251+
```nix
252+
nixpkgs = import <nixpkgs> {
253+
overlays = [
254+
nixpkgs.nur.repos.mpickering.overlays.haskell-plugins
255+
];
256+
};
257+
```
258+
259+
Put reusable nix functions that are intend for public use in the `lib` attribute:
260+
261+
```nix
262+
{ lib }:
263+
with lib;
264+
{
265+
lib = {
266+
hexint = x: hexvals.${toLower x};
267+
268+
hexvals = listToAttrs (imap (i: c: { name = c; value = i - 1; })
269+
(stringToCharacters "0123456789abcdef"));
270+
};
271+
}
272+
```
273+
200274
## Contribution guideline
201275

202276
- When adding packages to your repository make sure they build and set
@@ -230,4 +304,3 @@ cycles.
230304
## Roadmap
231305

232306
- Implement a search to find packages
233-
- Add not just packages but also modules/functions

0 commit comments

Comments
 (0)