2021-02-14 02:38:20 +00:00
|
|
|
# Profiles
|
|
|
|
|
2021-03-14 07:10:51 +00:00
|
|
|
Profiles are a convenient shorthand for the [_definition_][definition] of
|
|
|
|
[options][options] in contrast to their [_declaration_][declaration]. They're
|
|
|
|
built into the NixOS module system for a reason: to elegantly provide a clear
|
|
|
|
separation of concerns.
|
2021-02-14 02:38:20 +00:00
|
|
|
|
2021-06-03 19:25:06 +00:00
|
|
|
## Creation
|
2022-11-20 22:28:23 +00:00
|
|
|
|
2021-06-03 19:25:06 +00:00
|
|
|
Profiles are created with the `rakeLeaves` function which recursively collects
|
2022-11-20 22:28:23 +00:00
|
|
|
`.nix` files from within a folder. The recursion stops at folders with a `default.nix`
|
2021-06-03 19:25:06 +00:00
|
|
|
in them. You end up with an attribute set with leaves(paths to profiles) or
|
|
|
|
nodes(attrsets leading to more nodes or leaves).
|
|
|
|
|
|
|
|
A profile is used for quick modularization of [interelated bits](./profiles.md#subprofiles).
|
2021-02-14 02:38:20 +00:00
|
|
|
|
2021-03-14 07:10:51 +00:00
|
|
|
> ##### _Notes:_
|
2022-11-20 22:28:23 +00:00
|
|
|
>
|
|
|
|
> - For _declaring_ module options, there's the [modules](../outputs/modules.md) directory.
|
|
|
|
> - This directory takes inspiration from
|
2021-03-14 07:10:51 +00:00
|
|
|
> [upstream](https://github.com/NixOS/nixpkgs/tree/master/nixos/modules/profiles)
|
|
|
|
> .
|
2021-02-14 02:38:20 +00:00
|
|
|
|
2021-06-03 19:25:06 +00:00
|
|
|
### Nested profiles
|
2022-11-20 22:28:23 +00:00
|
|
|
|
2021-06-03 19:25:06 +00:00
|
|
|
Profiles can be nested in attribute sets due to the recursive nature of `rakeLeaves`.
|
|
|
|
This can be useful to have a set of profiles created for a specific purpose. It is
|
|
|
|
sometimes useful to have a `common` profile that has high level concerns related
|
|
|
|
to all its sister profiles.
|
2021-02-14 02:38:20 +00:00
|
|
|
|
2021-02-25 21:47:19 +00:00
|
|
|
### Example
|
|
|
|
|
2021-06-03 19:25:06 +00:00
|
|
|
profiles/develop/common.nix:
|
2022-11-20 22:28:23 +00:00
|
|
|
|
2021-02-25 21:47:19 +00:00
|
|
|
```nix
|
|
|
|
{
|
|
|
|
imports = [ ./zsh ];
|
|
|
|
# some generic development concerns ...
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2021-06-03 19:25:06 +00:00
|
|
|
profiles/develop/zsh.nix:
|
2022-11-20 22:28:23 +00:00
|
|
|
|
2021-02-25 21:47:19 +00:00
|
|
|
```nix
|
|
|
|
{ ... }:
|
|
|
|
{
|
|
|
|
programs.zsh.enable = true;
|
|
|
|
# zsh specific options ...
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2021-06-03 19:25:06 +00:00
|
|
|
The examples above will end up with a profiles set like this:
|
2022-11-20 22:28:23 +00:00
|
|
|
|
2021-06-03 19:25:06 +00:00
|
|
|
```nix
|
|
|
|
{
|
|
|
|
develop = {
|
|
|
|
common = ./profiles/develop/common.nix;
|
|
|
|
zsh = ./profiles/develop/zsh.nix;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2021-02-14 02:38:20 +00:00
|
|
|
## Conclusion
|
2022-11-20 22:28:23 +00:00
|
|
|
|
2021-03-14 07:10:51 +00:00
|
|
|
Profiles are the most important concept in DevOS. They allow us to keep our
|
|
|
|
Nix expressions self contained and modular. This way we can maximize reuse
|
|
|
|
across hosts while minimizing boilerplate. Remember, anything machine
|
2021-04-19 02:26:27 +00:00
|
|
|
specific belongs in your [host](hosts.md) files instead.
|
2021-03-14 07:10:51 +00:00
|
|
|
|
|
|
|
[definition]: https://nixos.org/manual/nixos/stable/index.html#sec-option-definitions
|
|
|
|
[declaration]: https://nixos.org/manual/nixos/stable/index.html#sec-option-declarations
|
|
|
|
[options]: https://nixos.org/manual/nixos/stable/index.html#sec-writing-modules
|
2021-10-11 22:32:01 +00:00
|
|
|
[spec]: https://github.com/divnix/devos/tree/main/lib/devos/mkProfileAttrs.nix
|
2021-03-14 07:10:51 +00:00
|
|
|
[config]: https://nixos.wiki/wiki/Module#structure
|