nixos-config/modules/nixos/profiles/README.adoc

69 lines
3.2 KiB
Plaintext
Raw Normal View History

= Profiles
:toc:
:check_variable: _isInsideFds
2022-09-26 06:17:39 +00:00
We're defining profiles after how link:https://digga.divnix.com/concepts/profiles.html[digga library from divnix defines it].
That is...
2022-09-26 06:17:39 +00:00
[quote, digga library]
____
Profiles are a convenient shorthand for the definition of options in contrast to their declaration.
They're built into the NixOS module system for a reason: to elegantly provide a clear separation of concerns.
____
In other words, these are simple configuration that are typically composed of setting common NixOS options such as enabling NixOS services or installing system packages.
== What are profiles, really?
2022-09-26 06:17:39 +00:00
However, unlike digga profiles, we do implement an interface (or a declaration) on top of the definition of options.
Each profile should have an interface to be enabled first (e.g., `options.profiles.${profile}`) since it will be included as part of the included modules for our NixOS configurations.
2022-09-28 11:11:12 +00:00
This basically makes it easier to create a centralized and one consistent version of a part of a configuration which we can just enable it anywhere multiple times.
This also prevents potential problems that comes with importing a (digga) profile multiple times such as unintended merged values (i.e., duplicated items in a list).
2022-09-26 06:17:39 +00:00
Furthermore, they are not going to be exported to the flakes since they are quite specific and practically, no one is going to use them with each user having different requirements even with a cluster of systems.
Thus, you should be mindful to use profiles whenever you write or update NixOS modules.
As future reference, here's an exhaustive list of namespaces you should avoid using them as much as possible:
* `services` and `programs` shouldn't use any profiles at all since they are small in scope that they are more likely to be combined with other modules.
* Any modules under `workflows` are not exactly prohibited to use profiles since they are all-encompassing modules that creates a desktop that may be composed of multiple modules.
However, it is heavily discouraged.
If used, be sure to put it under a check with `{check_variable}` which is an extra argument passed to various profiles (e.g., NixOS, home-manager) as an optional part of the configuration.
2022-09-28 11:11:12 +00:00
Take note that workflows are also exported in the flake output.
footnote:[Overall, I don't think it's not much of a threat to set profiles in the workflow unless users that is not me have conspicuously similar setup to mine. It's just discouraged to minimize stepping on as less as configurations as possible.]
2022-09-26 06:17:39 +00:00
2022-09-28 11:11:12 +00:00
* Really, anything that is being exported in the flake outputs (i.e., look for the attributes in `nix flake show`) unless explicitly stated like the case for `workflows`.
2022-09-26 06:17:39 +00:00
== Setting profiles conditionally
The following snippet of a NixOS module with an optional part check with the simple boolean variable.
[subs=attributes, source, nix]
----
{ config, options, pkgs, lib, ... }@attrs:
{
# ...
config = lib.mkIf cfg.enable (lib.mkMerge [
{
# Some required parts here.
}
(lib.mkIf (attrs ? {check_variable} && attrs.{check_variable}) {
# Set profiles here.
})
];
}
----
So yeah... have at it.
This is useful for setting profiles inside of modules that are otherwise not possible to easily export for others' use (e.g., `workflows`).