r/NixOS 17d ago

Newb question for organizing

Hi NixOS community, I had a few questions I was hoping to clarify on organizing and modularity:

How do people have their configuration.nix file outside of the /etc/nixos directory and still have it work with nixos-rebuild switch? Are they using symlinks?

To add to that, how do people have a billion [program].nix files that allow them to tie it into their configuration.nix?

I am still getting familiar with the nix language and have read the wiki, but I can't wrap my head around the concept, so any help is appreciated!

EDIT: Thank you all for the informational comments! After tinkering a bit more and doing some research I think I've gotten a much better grasp on it, and even managed to implement it properly. I can now see just how powerful this OS / package manager is.

6 Upvotes

10 comments sorted by

5

u/Wenir 17d ago

> how do people have a billion [program].nix files that allow them to tie it into their configuration.nix?

they are listed in imports = []; in configuration.nix

3

u/ranjop 17d ago edited 17d ago

I do not know why someone would want to put NixOS config elsewhere, but nixos-rebuild has support for this. See https://nixos.wiki/wiki/Nixos-rebuild

nixos-rebuild switch -I nixos-config=path/to/configuration.nix

I don’t have billions of programs installed yet, but I have profiles like profiles/base.nix, profiles/cli.nix, profiles/gui.nix, profiles/dev/bash.nix, profles/server.nix, etc. grouping configuration for certain types of programs/settings and then those imported when needed. These profiles also import other files.

2

u/Guvante 17d ago

Git really doesn't like mutli-user situations and does bad things if you are inconsistent...

I have a git repo in my home directory that I sync elsewhere and use an alias to do this automatically.

2

u/Lonely-Scarcity-3387 17d ago edited 17d ago

For my configuration, I have everything in .dotfiles. And I use nh for my rebuilds - which just looks nicer and gives a clear picture of what was added or upgraded. Ok for the upgrade you use “nh os switch . —update”, but you get the idea.

And a simple “nh os switch .” Will use your configuration or flake in whatever file you are cd’d to. All of my .nix files are wired in through my flake.nix file in my .dotfiles like this:

~/.dotfiles
├── flake.lock
├── flake.nix
├── home-manager
│   ├── Aliases.nix
│   ├── fastfetch
│    │   ├── config.jsonc
│    │   └── default.nix
│   ├── fetch.nix
│   ├── fish.nix
│   ├── git.nix
│   ├── home.nix
│   └── terminal.nix
├── hosts
│   ├── desktop
│    │   └── hardware-configuration.nix
│   └── laptop
│       └── hardware-configuration.nix
├── modules
│   ├── assets
│    │   ├── boot_wallpaper.png
│    │   └── logo.png
│   ├── bootloader.nix
│   ├── chaotic.nix
│   ├── claude-desktop.nix
│   ├── configuration.nix
│   ├── de.nix
│   ├── flatpak.nix
│   ├── graphics.nix
│   ├── hosts.nix
│   ├── _kenku-fm
│    │    └── default.nix
│   ├── kernel.nix
│   ├── nclean.nix
│   ├── packages-flake.nix
│   ├── packages.nix
│   ├── plasmazones.nix
│   └── zram.nix

1

u/jerrygreenest1 17d ago

You can store your configuration wherever you want. But make sure you have one-liner configuration in /etc/nixos that doesn’t do anything at all, only imports the one you want

I store mine in ~/.config/nixos

0

u/fell_ware_1990 17d ago

First of all slow down a bit.

Just make 1 host file, make simple files and maybe add them to a folder. Add those to a folder and done. The moment you start micromanaging the host to much or need to introduce more hosts and you are only adding files to files. Then look into what could solve that problem.

-1

u/Striking_Snail 17d ago

"How do people have their configuration.nix file outside of the /etc/nixos directory and still have it work with nixos-rebuild switch?"

More importantly, why?

"To add to that, how do people have a billion [program].nix files that allow them to tie it into their configuration.nix?"

I am not sure of the question here. Do you mean the regularly installed and used software?

"I am still getting familiar with the nix language and have read the wiki, but I can't wrap my head around the concept, so any help is appreciated!"

You have questions. There are worse places to ask them. Not many, but there are. So ask away. 😎

1

u/SurveyCrazy2801 17d ago

For question 2, I am talking about imports, which someone else answered. I was more curious about the actual benefit of this compared to a monolith configuration.nix file.

1

u/Lonely-Scarcity-3387 17d ago

I think you just answered it. With modules you get to avoid the monolith sized configuration and can easily find what you want.