[Nix-dev] Function to look up symbols dynamically?

Bryan Ferris primummoven at gmail.com
Wed Mar 15 17:21:02 CET 2017


@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?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.science.uu.nl/pipermail/nix-dev/attachments/20170315/ed7a24d6/attachment.html>


More information about the nix-dev mailing list