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

benley at gmail.com benley at gmail.com
Mon Feb 27 22:29:33 CET 2017


My approach is quite similar to Jookia's.  I also point nixpkgs at a
remote tarball from a github branch that I control, which takes the
place of using nix-channel, and set nixos-config relative to
config.networking.hostName.  With this setup, I don't need any
symlinks, nor custom imports in ~/.nixpkgs/config.nix because it has
the same view of nixpkgs as the rest of the system.

In nix.nix[1], imported from configuration.nix[2]:

    nix.nixPath = [
      "nixpkgs=https://github.com/benley/archive/nixos-benley.tar.gz"
      "nixos-config=/home/benley/p/dotfiles/machines/${config.networking.hostName}/configuration.nix"
      "dotfiles=/home/benley/p/dotfiles"
    ];

In ~/.nix-defexpr/nixpkgs.nix:

    import <nixpkgs> { }

Having <dotfiles> be an element of NIX_PATH has also been useful in
various places, such as in ~/default.nix, which is used by
nix-home[3].

In ~/default.nix:

    (import <dotfiles> { }).homedir

And finally I have a directory full of dotfiles that get overlaid into
my homedir, for various things that don't really belong in the
system-wide config[4].  This works equally well with non-nixos
systems, as long as they have nix installed.

In theory I could point nixos-config at a github URL too, but I like
the convenience of being able to directly edit it in my homedir as
needed.

[1]: https://github.com/benley/dotfiles/blob/master/machines/imports/nix.nix
[2]: https://github.com/benley/dotfiles/blob/master/machines/samus/configuration.nix
[3]: https://github.com/sheenobu/nix-home
[4]: https://github.com/benley/dotfiles/tree/master/cfg (also see
homedir.nix in this repo)

On Mon, Feb 27, 2017 at 3:40 PM, Jookia <166291 at gmail.com> wrote:
>
> On Mon, Feb 27, 2017 at 09:15:27AM -0500, Mark Gardner wrote:
> > 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
> > --
>
> I have a configuration for each host, but then I set my nix path like so:
>
> NIX_PATH=nixpkgs=/home/jookia.data/nixos/nixpkgs.git:nixos-config=/home/jookia.data/nixos/configuration.git/novena.nix
>
> nixos-config points to my host-specific configuration. Then in that host
> configuration I set the path something like this:
>
> nix.nixPath = [
>   "nixos-config=/home/jookia.data/nixos/configuration.git/novena.nix"
> ];
> _______________________________________________
> nix-dev mailing list
> nix-dev at lists.science.uu.nl
> http://lists.science.uu.nl/mailman/listinfo/nix-dev


More information about the nix-dev mailing list