summaryrefslogtreecommitdiff
path: root/3 Resources/Nix/NixOS Modules.md
blob: 1ab4c2514b2348d8b41e1cce9dd4a89e045127f2 (plain)
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
---
tags:
  - nix
  - nixos
references:
  - https://nixos.org/manual/nixos/unstable/#sec-writing-modules
  - https://nixos.org/manual/nixpkgs/stable/#module-system-lib-evalModules
  - https://nix.dev/tutorials/module-system/
  - llk
---
Extra care must be taken when writing systemd services using Exec* due to interpolation and such. `utils.escapeSystemdExecArg` and `utils.escapeSystemdExecArg` exist.

```nix
{
  options = {
    name = mkOption {
      type = type specification;
      default = default value;
      example = example value;
      description = "Description for use in the NixOS manual.";
    };
  };
}
```

**A list of submodules**
```nix
{
  options.mod = mkOption {
    description = "submodule example";
    type = with types; listOf (submodule {
      options = {
        foo = mkOption {
          type = int;
        };
        bar = mkOption {
          type = str;
        };
      };
    });
  };
}
```


**Testing**
```nix eval.nix
let
	pkgs = import <nixpkgs> {};
	res = pkgs.lib.evalModules {
		modules = [./git-repos.nix];
	};
in
res.config
```
`nix-instantiate --eval eval.nix`