Skip to content

Commit

Permalink
Support a "defaults" attribute that sets default values for all machines
Browse files Browse the repository at this point in the history
The "defaults" attribute in every network expressions is stacked on
top of every machine configuration.  Ideally the values defined in
"defaults" would have a lower priority, but I don't think it's
possible yet to set a default priority for all values in a NixOS
module.
  • Loading branch information
edolstra committed Mar 26, 2012
1 parent b39c4f8 commit 23599d0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
19 changes: 7 additions & 12 deletions examples/apache-ec2.nix
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
let

config =
{
defaults =
{ config, pkgs, ... }:
{ deployment.targetEnv = "ec2";
deployment.ec2.region = "us-east-1";
deployment.ec2.instanceType = "m1.large";
deployment.ec2.region = pkgs.lib.mkDefault "eu-west-1";
deployment.ec2.instanceType = "m1.small";
deployment.ec2.keyPair = "eelco";
deployment.ec2.securityGroups = [ "eelco-test" ];
};

in

{
proxy = config;
backend1 = config;
backend2 = config;

backend2.deployment.ec2.region = "us-west-1";
}
15 changes: 9 additions & 6 deletions nix/eval-machine-info.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,31 @@ rec {
networks = map (networkExpr: import networkExpr) networkExprs;

network = zipAttrs networks;

defaults = network.defaults or [];

nodes =
listToAttrs (map (configurationName:
listToAttrs (map (machineName:
let
modules = getAttr configurationName network;
modules = getAttr machineName network;
in
{ name = configurationName;
{ name = machineName;
value = import <nixos/lib/eval-config.nix> {
modules =
modules ++
defaults ++
[ # Provide a default hostname and deployment target equal
# to the attribute name of the machine in the model.
{ key = "set-default-hostname";
networking.hostName = mkOverride 900 configurationName;
deployment.targetHost = mkOverride 900 configurationName;
networking.hostName = mkOverride 900 machineName;
deployment.targetHost = mkOverride 900 machineName;
environment.checkConfigurationOptions = false; # should only do this in phase 1
}
];
extraArgs = { inherit nodes; };
};
}
) (attrNames (removeAttrs network [ "network" ])));
) (attrNames (removeAttrs network [ "network" "defaults" ])));

# Phase 1: evaluate only the deployment attributes.
info = {
Expand Down

0 comments on commit 23599d0

Please sign in to comment.