nixos-config/docs/content/en-US/04-nixos-modules/01-profiles/index.adoc

3.0 KiB
Raw Blame History


title: Profiles --- = Profiles

In my github:{github-repo}[NixOS modules, path=./modules/nixos, rev=master], there is a subset of modules for profiles. The way we defined profiles is very similar to digga profiles.

Profiles are a convenient shorthand for the definition of options in contrast to their declaration. Theyre built into the NixOS module system for a reason: to elegantly provide a clear separation of concerns.

— digga library

Except the difference is we also included a declaration for setting those options. This enables different modules in our NixOS configurations to set those up in different points in time without getting a duplicate value error which is nice. However, enabling profiles shouldnt be taken lightly. In my project, the situations to enable profiles are limited.

Here are the module namespaces with their guidelines for setting them profiles.

  • services and programs shouldnt 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 environments (e.g., NixOS, home-manager) as an optional part of the configuration. Take note that workflows are also exported in the flake output. [1]

  • 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.

Son, just like what I keep telling you: is this solution good enough?

For the most part, yeah. But the way how Im using profiles is pretty similar to digga profiles in the same way that it is really used only once at most point.

Why dont you use digga then?

digga github:divnix/digga[was considered to be a dead project, issue=503] which is unfortunate. When I was grokking flakes, I used their example extensively and eventually understood a lot about flakes and Nix modules overall. But the project is really big and overwhelming to use it for someone who only started using flakes so I just went through the project piece by piece and only used a small subset of it. I think this comment sums up the problems of the project.

Also take note, youll see similar home-manager profile modules around in my project. Theyre pretty much the same as defined here except that theyre home-manager modules.


1. Overall, I dont think its not much of a threat to set profiles in the workflow unless users that is not me have conspicuously similar setup to mine. Its just discouraged to minimize stepping on as less as configurations as possible.