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

Nicolas Pierron nicolas.b.pierron at nbp.name
Wed Mar 15 23:56:49 CET 2017


Hi Bryan,

On Wed, Mar 15, 2017 at 5:21 PM, Bryan Ferris <primummoven at gmail.com> wrote:
> I believe that for complicated configurations this would lead to a tidier
> config.

I honestly don't think this would help you keep your configuration
isolated by concerns as the module system of NixOS does.

> 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.

Modules have an `imports` top-level attribute which can be used to
list other files that have to be included in the configuration.

> This seems like a reasonable approach to a
> useful tool, no?

If you really want to continue that way, I suggest you to look at the
builtin function `builtins.readDir`.
Otherwise, if what you are looking for a better way to lookup options,
maybe you should look at `nixos-option` tool, which should help you
better understand where options are defined both within NixOS, and
within your own modules:

$ nixos-option environment.systemPackages
Declared by:
  "/nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/nixos/modules/config/system-path.nix"

Defined by:
  "/nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/nixos/modules/services/x11/desktop-managers/kde4.nix"
  "/nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/nixos/modules/services/x11/desktop-managers/xterm.nix"
  "/nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/nixos/modules/virtualisation/virtualbox-guest.nix"
  "/nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/nixos/modules/virtualisation/containers.nix"
  "/nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/nixos/modules/tasks/swraid.nix"
  ...

If you are looking for reading more about it, I will recommend the 2
following chapters of the NixOS manual:
http://nixos.org/nixos/manual/index.html#sec-configuration-syntax
http://nixos.org/nixos/manual/index.html#sec-writing-modules

-- 
Nicolas Pierron
http://www.linkedin.com/in/nicolasbpierron - http://nbp.name/


More information about the nix-dev mailing list