[Nix-dev] Resolution context of `require' paths

Eelco Dolstra e.dolstra at tudelft.nl
Tue Jun 30 11:28:48 CEST 2009


Hi,

Nicolas Pierron wrote:

> On Tue, Jun 30, 2009 at 09:50, Ludovic Courtès<ludo at gnu.org> wrote:
>> Hello,
>>
>> The `modular-nixos' branch introduces `require' statements, which now
>> take a path, e.g.,
>>
>>  require = [ ./nixos/hardware/network/intel-4965agn.nix ];
>>
>> The problem is that the resolution context of this relative path is
>> often problematic.
> 
> I don't consider this being a problem.

I do consider this a problem:

- You can't easily use a different NixOS tree by setting $NIXOS, since those
hardcoded paths ignore it.

- Because $NIXOS is ignored, nixos-install currently fails if you use these
paths.  This is because during the installation nix-env is run in a chroot,
where the NixOS sources are under /mnt/etc/nixos/nixos rather than
/etc/nixos/nixos.  Sure, this could be fixed by copying the sources to the
target filesystem first, but it's not nice.

- It makes the filenames part of the "interface" of NixOS, so we can never
change them.

Possible solutions:

- Go back to using options to enable modules, just as we do for most other kinds
of modules (e.g. hardware.enableIntel4965 = true).

- Pass the full set of modules to configuration.nix (and other modules of
course) where they can be selected *by attribute name* rather than filename:

  {config, pkgs, modules, ...}:

  {
     require = [modules.intel4965agn];
  }

  where "modules" is defined somewhere in the NixOS tree:

  modules =
    { intel4965agn = ./hardware/network/intel-4965agn.nix;
      sshd = ./services/networking/sshd.nix;
      ...
    };

  This allows a bit more abstraction than hardcoded filenames, because you can
now refactor the module structure.  For instance, if you ever combine all those
Intel modules into one:

  modules =
    { intel4965agn = ./hardware/network/intel.nix;
      intel3965abg = ./hardware/network/intel.nix;
      ...
    };

- Or at the very least pass the root of the NixOS tree to configuration.nix:

  {config, pkgs, nixos, ...}:

  {
    require = [ ${nixos}/hardware/network/intel-4965agn.nix ];
  }

  But this still suffers from hardcoding filenames.

-- 
Eelco Dolstra | http://www.st.ewi.tudelft.nl/~dolstra/



More information about the nix-dev mailing list