this post was submitted on 24 Jul 2024
15 points (100.0% liked)

Nix / NixOS

1776 readers
1 users here now

Main links

Videos

founded 1 year ago
MODERATORS
 

I am just setting up my NixOS config for the first time, and I know that it will be fairly complex. I know it will only be possible and scalable if I have sane conventions.

I have read a number of example configs, but there does not seem to be consistent conventions between them of where to store custom option declarations, how to handle enabling/disabling modules, etc. They all work, but they do it in different ways.

Are there any official or unofficial conventions/style guides to NixOS config structure, and where can I find them?

For example, should I make a lib directory where I put modules that are easily portable and reusable in other people's configs? When should I break modules up into smaller ones? Etc. These are things that I hope to be addressed.

top 3 comments
sorted by: hot top controversial new old
[–] [email protected] 5 points 4 months ago

Unfortunately, nothing is standard. So I would say, across all the configs you looked at, which had a file and module structure that you understood? I'd follow that then.

My config has a users and hosts dir, to distinguish home manager and nixos configs. Inside each is the list of users and hosts configuration files. In addition, there is a modules folder that holds modules that are common among different users/hosts.

[–] [email protected] 2 points 4 months ago

There are no established conventions yet, you can do as you please. There are some frameworks trying to create structures, but they are in no way mandatory or even agreed upon.

[–] DrGamerPhD 1 points 3 months ago* (last edited 3 months ago)

i took the structure from vimjoyer's video on this. i think it's a great starting point, after which you can start experimenting with moving stuff around and borrowing from other configs as you learn how things work

how you separate modules is really up to you; i wouldn't overthink it too much. in my config, my modules are split into home-manager modules and system modules, like this:

  • dotfiles/modules/home-manager
  • dotfiles/modules/nixos

then in those, i separate based either on subject (like shell stuff, music software, games) or if the config for one program is getting really big (like my alacritty or firefox configs). my layout evolved over a few months, so don't feel as though you need to get it spot-on from the start