[Nix-dev] Best Practices on Modularizing Configuration.nix?

Tomasz Czyż tomasz.czyz at gmail.com
Mon Feb 27 15:28:15 CET 2017


Hey Mark,

I use almost the same setup and for 1.5y works very well.

I have "modules" and "hosts" directories. Each "host" contains
configuration about hardware/disk setup and includes set of modules from
"modules". On each host there is a symlink to correct
"hosts/<hostname>.nix" file.

I found this setup pretty robust on dev machines.
On servers I use nixops which pushes configuration so I don't manage
/etc/nixos there.

Tom

2017-02-27 14:15 GMT+00:00 Mark Gardner <mkg at vt.edu>:

> Now that I am putting NixOS on more and more machines, I would like to
> modularize and share parts of the config to maximize reuse and ensure
> uniformity. My approach is to consider the sub-config files as traits or
> roles and combine them together to create configuration.nix for a specific
> machine, like this:
>
> - cfg/common.nix  # common config
> - cfg/desktop.nix  # xorg and related
> - cfg/laptop.nix  # related to all laptops
> - cfg/work.nix  # work location related
> ...
> - cfg/mylaptop.nix  # specific laptop related
>
> I import from these to make up configuration.nix. For example, on my
> laptop, configuration.nix contains:
>
> ---
> { config, pkgs, ... }:
>
> {
>   imports =
>     [
>       ./hardware-configuration.nix
>       ./cfg/mylaptop.nix
>       ./cfg/common.nix
>       ./cfg/desktop.nix
>       ./cfg/laptop.nix
>       ./cfg/work.nix
>     ];
> }
> ---
>
> So far, this seems like a good approach. Except that each machine has its
> own configuration.nix that I would like to keep in the git repository too
> but of course I can't have different top level files with the same name. To
> solve this, I could moved the current configuration.nix inside of cfg (as
> cfg/mylaptop.cfg.nix perhaps) or merge with the existing cfg/mylaptop.nix
> then making configuration.nix a symlink to it. That way the only thing to
> do by hand is create the symlink to select a particular configuration. Is
> this reasonable? Is there a better way to do it?
>
> How do you modularize your configuration and put it into a repo such that
> you can easily create a configuration for a new machine (and put it in the
> repo too) without a lot of hand work?
>
> Mark
> --
> Mark Gardner
> --
>
> _______________________________________________
> nix-dev mailing list
> nix-dev at lists.science.uu.nl
> http://lists.science.uu.nl/mailman/listinfo/nix-dev
>
>


-- 
Tomasz Czyż
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.science.uu.nl/pipermail/nix-dev/attachments/20170227/7a2205c1/attachment.html>


More information about the nix-dev mailing list