summaryrefslogtreecommitdiff
path: root/nixos/docs/ADDING_PACKAGES.md
blob: d1b5eba1b4a7b90f02ff4a909c5bcb50cbf820d6 (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
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# Dendritic Pattern

Dendritic is the way to organize your packages in NixOS — around features. https://github.com/mightyiam/dendritic this is a good example!

# Adding Packages

This configuration is composed from `hosts/opus/default.nix` and focused modules
under `modules/features/`. There is no central package list.

## Where a package belongs

| Package type | Module |
| --- | --- |
| Terminal | `modules/features/terminals/default.nix` |
| CLI tool (incl. shell prompts like starship) | `modules/features/cli-tools/default.nix` |
| Editor or IDE | `modules/features/editors/default.nix` |
| Compiler, linter, language tool | `modules/features/dev-tools/default.nix` |
| File manager or archive tool (incl. drag & drop tools) | `modules/features/file-managers/default.nix` |
| Wayland clipboard, screenshot, or input tool | `modules/features/wayland-tools/default.nix` |
| Audio application | `modules/features/audio-tools/default.nix` |
| Media recording or streaming tool | `modules/features/media-tools/default.nix` |
| System monitor or fetch tool | `modules/features/monitoring/default.nix` |
| Font | `modules/features/fonts/default.nix` |
| GStreamer plugin | `modules/features/gst-codecs/default.nix` |
| Runtime library for external binaries | `modules/features/binary-compat/default.nix` |
| Web browser | `modules/features/browsers/default.nix` |
| Messaging or communication app | `modules/features/messaging/default.nix` |
| Office suite, note-taking app, or document viewer/editor | `modules/features/productivity/default.nix` |
| Password manager or encryption tool | `modules/features/security/default.nix` |
| Gaming app, game launcher, or gaming service (Steam, etc.) | `modules/features/gaming/default.nix` |
| P2P or torrent client | `modules/features/p2p/default.nix` |
| Language dictionary or spell-check data | `modules/features/language-tools/default.nix` |
| Desktop application (catch-all for GUI apps without a fitting category) | `modules/features/desktop-apps/default.nix` |

First use an existing category. Create a new feature module only if the package is
its own service, subsystem, or a group of related packages without a fitting category.

## Add to an existing module

Add the package to that module's `environment.systemPackages` list:

```nix
{ pkgs, ... }:

{
  environment.systemPackages = with pkgs; [
    existing-package
    ripgrep
  ];
}
```

Most modules use `with pkgs;`, so use unqualified package names. Use `pkgs.<name>`
when an explicit path is useful, such as `pkgs.vimPlugins.im-select-nvim`, or when
applying an override:

```nix
(emacs.override { withNativeCompilation = true; })
```

Keep related packages together and follow the local ordering of the file.

## Fonts are different

Fonts belong in `modules/features/fonts/default.nix` under `fonts.packages`, not
`environment.systemPackages`:

```nix
fonts.packages = with pkgs; [
  nerd-fonts.jetbrains-mono
  noto-fonts-color-emoji
];
```

## Language dictionaries are different

Spell-check dictionaries, transliteration data, and other language data belong in
`modules/features/language-tools/default.nix` under `environment.systemPackages`, not
in `fonts.packages` or a general-purpose module:

```nix
{ pkgs, ... }:

{
  environment.systemPackages = with pkgs; [
    hunspellDicts.ru_RU
  ];
}
```

## Gaming services live in the gaming module

Gaming-related services and packages — Steam configuration, game launchers, Wine-based
app runners — belong in `modules/features/gaming/default.nix`. This keeps the host file
lean and makes the gaming stack reusable across hosts:

```nix
{ pkgs, ... }:

{
  programs.steam = {
    enable = true;
    remotePlay.openFirewall = true;
  };

  environment.systemPackages = with pkgs; [
    pkgs.lutris
    pkgs.prismlauncher
  ];
}
```

## Create a new feature module

1. Create `modules/features/<category>/default.nix`:

   ```nix
   { pkgs, ... }:

   {
     environment.systemPackages = with pkgs; [
       package-name
     ];
   }
   ```

2. Add its directory to the `imports` list in `hosts/opus/default.nix`:

   ```nix
   ../../modules/features/<category>
   ```

3. Put services and program options in the same module when they belong to that
   feature, as done by `modules/features/mpd/default.nix`.

## Host-only packages

For a package that is truly specific to this desktop, add it to the small
`environment.systemPackages` list in `hosts/opus/default.nix`. If that list starts to
represent a reusable category, extract a feature module.

## Packages from flake inputs

Packages provided by a flake input use `inputs` and the host platform, following
`modules/features/browsers/default.nix`:

```nix
{ pkgs, inputs, ... }:

{
  environment.systemPackages = with pkgs; [
    inputs.helium-browser.packages.${pkgs.stdenv.hostPlatform.system}.helium
  ];
}
```

If an input provides a NixOS module, import it in the feature module, following
`modules/features/noctalia-greeter/default.nix`:

```nix
imports = [
  inputs.some-input.nixosModules.default
];
```

The input itself must first be declared in `flake.nix`.

## Build and switch

From the `nixos/` directory, first test that the configuration evaluates and builds:

```bash
doas nixos-rebuild build --flake .#opus
```

Then activate it:

```bash
doas nixos-rebuild switch --flake .#opus
```

If a terminal's font icons do not update after adding fonts, restart the terminal or
log out and back in after the switch.