nixos-config/modules/README.adoc

63 lines
2.0 KiB
Plaintext
Raw Normal View History

= Modules
:toc:
These are the modules to be used for the system configuration.
Multiple types of modules can be found here but the usual types of modules you'll be paying attention is the modules for link:https://nixos.org/manual/nixos/stable/index.html#sec-writing-modules[NixOS modules] and home-manager, both in link:./nixos/[`./nixos/`] and link:./home-manager/[`./home-manager/`], respectively.
The modules are imported usually through `lib.filesToAttr`, allowing for easier structuring without modifying the index file of each module (i.e., `default.nix`).
(See the implementation for more details.)
For example, take the following module folder structure...
[source, tree]
----
system/
├── themes/
│   ├── a-happy-gnome/
│   │   ├── default.nix
│   │   └── README.adoc
│   ├── a-sad-gnome/
│   │   ├── default.nix
│   │   └── README.adoc
│   └── default.nix
├── specific/
│   ├── borg.nix
│   └── prometheus.nix
├── agenix.nix
├── archiving.nix
├── desktop.nix
├── dev.nix
├── editors.nix
└── users.nix
----
...should have the following attribute set when run with `lib.filesToAttr ./nixos`.
[source, nix]
----
{
agenix = path/to/agenix.nix;
archiving = path/to/archiving.nix;
desktop = path/to/desktop.nix;
dev = path/to/dev.nix;
editors = path/to/editors.nix;
specific = {
borg = path/to/specific/borg.nix;
prometheus = path/to/specific/prometheus.nix;
};
themes = path/to/themes; # Since it has a 'default.nix' detected, we're using it instead.
users = path/to/users.nix;
}
----
The resulting attribute set can be easily be used for importing.
Here's an example of a NixOS system created with the NixOS modules which can used for shared configuration between hosts.
[source, nix]
----
lib.nixosSystem {
system = "x86_64-linux";
modules = lib.mapAttrsToList (name: path: import path) (lib.filesToAttr ./modules/nixos);
}
----