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

Badi' Abdul-Wahid abdulwahidc at gmail.com
Wed Mar 1 14:29:54 CET 2017


My approach mirrors Jookia's as well. I put all my configuration files into
a single repository and make /etc/nixos/configuration.nix look something
like:

{ imports = [ /home/badi/nixos/fangorn.nix ]; }

I found symlinking configuration.nix to the appropriate entrypoint
problematic when moving between machines (in addition to being on github,
the repo is also synced directly between each node using syncthing. Dropbox
or some other shared filesystem could work as well).

Associated configuration sets are in separate files such as users.nix,
monitoring.nix, syncthing.nix, basicsystem.nix, laptop.nix, etc, while
machine specific options are defined in <hostname>.nix (eg fangorn.nix in
above), which then imports the various options as needed.

This works fairly well as I routinely move between several machines that I
want to keep as identical as possible.

On Mon, Feb 27, 2017 at 9:08 PM, Profpatsch <mail at profpatsch.de> wrote:

> On 17-02-27 09:15am, Mark Gardner wrote:
> > 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.
>
> As far as the non-dev-ops-y parts go
> (that is: the nix expression parts),
> there’s basically two ways to structure modules:
>
> 1. Using `import`
> 2. Using `imports` from the module system
> 3. Using option definitions
>
> All have their place, I personally use the first
> two for more ephemeral settings and the latter if
> I want to share something for use by others.
>
> Example from my current machine config in our vuizvui repo:
>
> I have a folder for my personal machines, with a lib.nix
> and pkgs.nix; these are included as attrsets with `import`
> https://github.com/openlab-aux/vuizvui/blob/ac8da8796649e463
> b7d31dad6bfc95f01008c787/machines/profpatsch/katara.nix#L4
>
> My config for workstation/server/base is split into various
> module files, which get included with `imports`.
> https://github.com/openlab-aux/vuizvui/blob/ac8da8796649e463
> b7d31dad6bfc95f01008c787/machines/profpatsch/katara.nix#L9
> https://github.com/openlab-aux/vuizvui/blob/ac8da8796649e463
> b7d31dad6bfc95f01008c787/machines/profpatsch/base-workstation.nix#L11
>
> Then finally there’s the Thinkpad-specific setup,
> which I have put into a module with an enable option
> for others to use.
> https://github.com/openlab-aux/vuizvui/blob/ac8da8796649e463
> b7d31dad6bfc95f01008c787/machines/profpatsch/katara.nix#L45
> https://github.com/openlab-aux/vuizvui/blob/ac8da8796649e463
> b7d31dad6bfc95f01008c787/modules/hardware/thinkpad.nix
> and it’s actually used by our hackerspace’s Thinkpad, too:
> https://github.com/openlab-aux/vuizvui/blob/cd4bc6fde00e3da0
> 382a3eb151dbbd0087449377/machines/labnet/labtops.nix#L9
>
> I hope that helps.
>
>
> --
> Proudly written in Mutt with Vim on NixOS.
> Q: Why is this email longer than five sentences?
> A: Sometimes you have to be more verbose. :)
> May take up to five days to read your message. If it’s urgent, call me.
> _______________________________________________
> nix-dev mailing list
> nix-dev at lists.science.uu.nl
> http://lists.science.uu.nl/mailman/listinfo/nix-dev
>



-- 

Badi' Abdul-Wahid
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.science.uu.nl/pipermail/nix-dev/attachments/20170301/0ca65472/attachment.html>


More information about the nix-dev mailing list