# How do you structure your NixOS configs?

**URL:** https://discourse.nixos.org/t/how-do-you-structure-your-nixos-configs/65851
**Category:** Uncategorized
**Created:** [June 20, 2025, 1:51pm UTC](https://discourse.nixos.org/t/how-do-you-structure-your-nixos-configs/65851 "2025-06-20T13:51:26Z")
**Posts on this page:** 1
**Showing post:** 15

<div class="post-metadata">

### Author: ![vic](https://discourse.nixos.org/user_avatar/discourse.nixos.org/vic/32/35386_2.png) [@vic](https://discourse.nixos.org/u/vic)
#### Post date: [June 22, 2025, 9:04pm UTC](https://discourse.nixos.org/t/how-do-you-structure-your-nixos-configs/65851/15 "2025-06-22T21:04:55Z")

</div>

> [@fzakaria](#):
>
> I haven’t tried it yet but it does seem like you have to then toggle it on for each individual host rather than relying on common imports to just work it all out ?

I’m seeing that is a common misconception. I’ll try to clarify how it all depends on you designing your modules to compose effectively for you.

Imagine I have many hosts (I do have a home-lab of 11 hosts). If I want a common feature (say my ssh-keys setup) across all of them, then I’d create a generic `ssh` feature - on nixos it would add openssh, and some firewall rules. on darwin it would enable macos ssh server. on homeManager it would setup .ssh/config or keys -.

This ssh feature is just an example of something I’d like to be present across all my home-lab hosts.

Then I would add another more global feature: `home-lab`

```nix
{inputs, ...}:
{
  # this base module will be included in each host of mine, having a single point
  # where to include common configs across all my 11 hosts.
  flake.modules.nixos.home-lab.imports = with inputs.self.modules.nixos [
     ssh # our example feature
     # ... other modules that will always be part of any host
     home-lab-fw # firewall rules to participate on home-lab network
     vic-user # include my user on all of them
     etc-etc
  ];
}

```

And you are right that this single `nixos.home-lab` module should be included in all hosts. How you do that, is not mandated by the pattern, I do it by having a [single abstraction](https://github.com/vic/vix/blob/2ef479630d450738f1edf4c52dcfe9a9a9e1fdf7/modules/flake/osConfigurations.nix#L33) that instantiates my nixos hosts.

```nix
  mkNixos =
    system: cls: name:
    inputs.nixpkgs.lib.nixosSystem {
      inherit system;
      modules = [
        inputs.self.modules.nixos.${cls}
        inputs.self.modules.nixos.${name}
        inputs.self.modules.nixos.${system}
        {
          networking.hostName = lib.mkDefault name;
          nixpkgs.hostPlatform = lib.mkDefault system;
          system.stateVersion = "25.05";
        }
      ];
    };

```

The important bit there is `cls`, for me that is the _top-level_ aspect (or feature) that I want included on all hosts of that class, in our example this could be `home-lab` since `home-lab` already includes all other modules. Notice my mkNixos function just includes three modules `modules.nixos.${cls}` (eg, our `home-lab` example), `modules.nixos.${hostname}` so that we also have a module that contributes specific features for that host, and `modules.nixos.${system}` currently empty but could be common configs per arch.

At the end of the day, you DO have common imports you pass into `nixpkgs.lib.nixosSystem.modules`, and that’s all.

The dendritic pattern does not mandate anything about _how_ you instantiate your hosts or which modules you include or how many files you touch if adding a global feature. We (people already using the Dendritic pattern) are still exploring and finding out better ways to do things. I’m quite happy with my `mkNixos` function and has served well for me.

I’m currently trying to move [common shareable features](https://github.com/mightyiam/dendritic/discussions/8) like my [mkNixos](https://github.com/vic/vix/blob/a6930c1d8ed2451e8430697492bef436daaf6d00/modules/community/lib/mk-os.nix) function (and [many other reusable modules](https://github.com/vic/vix/blob/a6930c1d8ed2451e8430697492bef436daaf6d00/modules/community)) for [other people to reuse on their dendritic setups](https://github.com/vic/dennix).

Hope this has helped clarify the issue about having common imports. Having common imports is actually the point of using such dendritic setups. 🙂

> [@fzakaria](#):
>
> I also concur. You should upstream this into the dendritic repo explanation

Will do 🙂 Maybe we should follows these Dendritic specific questions on [another thread](https://discourse.nixos.org/t/pattern-every-file-is-a-flake-parts-module/61271/11) to avoid hijacking this thread.

---

_[View the full topic](https://discourse.nixos.org/t/how-do-you-structure-your-nixos-configs/65851)._
