Hi Bryan,
I used to wonder why this was not implemented in NixOS config itself.
The module implementation makes it possible to configure any setting
from any file.
It is even possible to declare option for unrelated option trees.
For example, nixos/modules/services/networking/dnschain.nix declares the
option tree services.dnschain.* (not services.netxorking.dnschain.*) [1].
But it also declares the options services.dnsmasq.resolveDNSChainQueries
[2] and services.pdns-recursor.resolveDNSChainQueries [3].
As for the optiosns it sets [4], they add new users, new services and
configure dns resolvers.
I think most users do take advantage of this feature to group options to
group options related to the same aspect of a system, rather than
according to the option hierarchy.
For example, I have a config file for Epson printers[5]. It would be a
real mess if all these related options were set in different files.
See
https://www.mail-archive.com/nix-dev@lists.science.uu.nl/msg32637.html
for sample modularization of NixOS configuration.
-- Layus.
[1]:
https://github.com/rnhmjoj/nixpkgs/blob/f7d49037a48846e025dd3d8f2ecb47f499431ee8/nixos/modules/services/networking/dnschain.nix#L38
[2]:
https://github.com/rnhmjoj/nixpkgs/blob/f7d49037a48846e025dd3d8f2ecb47f499431ee8/nixos/modules/services/networking/dnschain.nix#L101
[3]:
https://github.com/rnhmjoj/nixpkgs/blob/f7d49037a48846e025dd3d8f2ecb47f499431ee8/nixos/modules/services/networking/dnschain.nix#L109
[4]:
https://github.com/rnhmjoj/nixpkgs/blob/f7d49037a48846e025dd3d8f2ecb47f499431ee8/nixos/modules/services/networking/dnschain.nix#L122-L163
[5]: https://gist.github.com/layus/32208155451f4fee8146f5e3c6f2dc3b
On 15/03/17 17:21, Bryan Ferris wrote:
@Domen:
That's great, thanks!
@Kevin
Well, the reason I want it is that I'm trying to make it so that I can
load my configuration.nix from a directory tree rather than a single
file. I noticed that I was moving lengthy sections of my config (for
instance, the systemPackages variable) into separate files and
importing them. Rather than manually telling my configuration.nix
about every new file, I want to write a script so that I can specify a
target directory (say, /etc/nixos/config.d) and have the file names
imply which attribute they are setting. For instance, I could have
/etc/nixos/config.d/environment.nix with the following contents:
{ config, pkgs, ... }:
{
systemPackages = with pkgs; [
autoconf
gcc
gdb
...
];
}
or I could have /etc/nixos/config.d/environment/systemPackages.nix
with the following contents:
{ config, pkgs, .. }:
with pkgs; [
autoconf
gcc
gdb
...
]
and in either case the script will determine what key to set based on
the relative path and filename. In this example, I see how I can use
hasAttr/getAttr to get systemPackages, but not how I could get
environment to begin with.
I believe that for complicated configurations this would lead to a
tidier config. My goal is to be able to add one line to
configuration.nix which will import everything from the directory,
meaning that you can put as much or as little as you want into the
main configuration file and you can move code around easily in order
to find the system of organization that fits your specific use-case
the best. This seems like a reasonable approach to a useful tool, no?
_______________________________________________
nix-dev mailing list
nix-dev@lists.science.uu.nl
http://lists.science.uu.nl/mailman/listinfo/nix-dev
_______________________________________________
nix-dev mailing list
nix-dev@lists.science.uu.nl
http://lists.science.uu.nl/mailman/listinfo/nix-dev