2021-12-11 05:37:27 +00:00
= Modules
:toc:
2021-12-19 09:37:47 +00:00
These are various modules ranging from link:https://nixos.org/manual/nixos/stable/index.html#sec-writing-modules[NixOS modules] and link:https://github.com/nix-community/home-manager[home-manager] modules.
2021-12-11 05:37:27 +00:00
2021-12-19 09:37:47 +00:00
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.)
2021-12-11 05:37:27 +00:00
2021-12-21 06:29:27 +00:00
For example, take the following module folder structure of the link:./nixos/[custom NixOS modules]...
2021-12-11 05:37:27 +00:00
2021-12-19 09:37:47 +00:00
[source, tree]
----
2021-12-21 06:29:27 +00:00
nixos/
2021-12-19 09:37:47 +00:00
├── 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
----
2021-12-11 05:37:27 +00:00
2021-12-21 06:29:27 +00:00
...where it should have the equivalent attribute set.
2021-12-11 05:37:27 +00:00
2021-12-19 09:37:47 +00:00
[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;
}
----
2021-12-11 05:37:27 +00:00
2021-12-19 09:37:47 +00:00
The resulting attribute set can be easily be used for importing.
Here's an example of a NixOS system created with the modules which can used for shared configuration between hosts.
2021-12-11 05:37:27 +00:00
[source, nix]
----
2021-12-19 09:37:47 +00:00
lib.nixosSystem {
system = "x86_64-linux";
modules = lib.mapAttrsToList (name: path: import path) (lib.filesToAttr ./modules);
}
2021-12-11 05:37:27 +00:00
----
2021-12-19 09:37:47 +00:00
== Flake outputs
Various modules are then exported to the project flake as the following output:
* `nixosModules` exports modules from link:./nixos/[`./nixos/`].
* `homeManagerModules` exports modules from link:./home-manager/[`./home-manager/`].