diff options
author | aszlig <aszlig@redmoonstudios.org> | 2016-05-03 02:28:23 +0200 |
---|---|---|
committer | aszlig <aszlig@redmoonstudios.org> | 2016-05-03 02:49:49 +0200 |
commit | 58b0058419e9caebfdb9628b8ac89413c22b6973 (patch) | |
tree | 77fc1212d6355071dcbdf474d72a248a01879df7 | |
parent | dccee5cecb6bd7b7e369cab99eb78006879c41e9 (diff) |
lib/call-network: Pass nodes attribute to modules
On NixOps as well as for NixOS test networks, there is a nodes attribute which allows to reference configuration definitions from other modules. Currently this isn't used at all but might come in handy if we want to cross-reference machine configurations (for example referencing IP addresses in a static network configuration). Signed-off-by: aszlig <aszlig@redmoonstudios.org>
-rw-r--r-- | lib/call-network.nix | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/lib/call-network.nix b/lib/call-network.nix index dac125e7..d9e073f1 100644 --- a/lib/call-network.nix +++ b/lib/call-network.nix @@ -1,15 +1,21 @@ path: args: -with builtins; +with import "${import ../nixpkgs-path.nix}/lib"; let - machines = import path; -in listToAttrs (map (name: { - inherit name; - value = import ./call-machine.nix machines.${name} ({ - extraConfig = { lib, ... }: { - imports = lib.singleton (args.extraConfig or {}); - networking.hostName = lib.mkOverride 900 name; - }; - } // removeAttrs args [ "extraConfig" ]); -}) (attrNames machines)) + machineAttrs = import path; + + mkMachine = name: { + inherit name; + value = import ./call-machine.nix machineAttrs.${name} ({ + extraConfig = { lib, ... }: { + imports = lib.singleton (args.extraConfig or {}); + networking.hostName = lib.mkOverride 900 name; + _module.args.nodes = mapAttrs (const (m: m ? eval)) machines; + }; + } // removeAttrs args [ "extraConfig" ]); + }; + + machines = listToAttrs (map mkMachine (attrNames machineAttrs)); + +in machines |