cleverca22
2/28/2016 - 2:35 AM

configuration.nix

{ system ? builtins.currentSystem }:

let
  loadcfg = cfgfile: { config, pkgs, ...}: {
    imports = [ <nixos/modules/virtualisation/qemu-vm.nix> cfgfile ];
    config = {
      networking.extraHosts = ''
        192.168.3.11 nixos.example.com
        192.168.3.12 nixos2.example.com
      '';
      virtualisation = {
      };
      users.extraUsers.root.password = "root";
    };
  };
  mkcfg = cfgfile:
    import <nixos/lib/eval-config.nix> {
      inherit system;
      modules = [ (loadcfg cfgfile) ];
    };
in {
  router = (mkcfg ./routercfg.nix).config.system.build.vm;
  master = (mkcfg ./configuration.nix).config.system.build.vm;
  slave = (mkcfg ./configuration2.nix).config.system.build.vm;
  tox = (mkcfg ./tox.nix).config.system.build.vm;
}
{ config, pkgs, ... }:

{
  imports = [ ./default.nix /root/nixcfg/core.nix ];
  services = {
    dhcpd = {
      enable = true;
      interfaces = [ "eth0" ];
      machines = [
        { hostName = "nix1"; ethernetAddress = "52:54:00:12:34:01"; ipAddress = "192.168.3.11"; }
        { hostName = "nix2"; ethernetAddress = "52:54:00:12:34:02"; ipAddress = "192.168.3.12"; }
      ];
      extraConfig = ''
        subnet 192.168.3.0 netmask 255.255.255.0 {
          option subnet-mask 255.255.255.0;
          option broadcast-address 192.168.3.255;
          option routers 192.168.3.1;
          option domain-name-servers 192.168.2.61;
          range 192.168.3.100 192.168.3.200;
        }
      '';
    };
    xserver = {
      enable = true;
      displayManager.slim = {
        enable = true;
        autoLogin = true;
        defaultUser = "clever";
      };
      desktopManager.xfce = {
        enable = true;
      };
    };
  };
  environment.systemPackages = with pkgs; [ chromium wget nmap ];
  networking = {
    hostName = "router";
    interfaces.eth0 = {
      ipAddress = "192.168.3.1";
      prefixLength = 24;
    };
#    nat = {
#      enable = true;
#      externalInterface = "eth0";
#      internalIPs = [ "192.168.3.0/24" ];
#      internalInterfaces = [ "eth1" ];
#    };
  };
  virtualisation = {
    memorySize = 1024;
    qemu.networkingOptions = [
      "-net nic,vlan=0,macaddr=52:54:00:12:34:00"
      "-net vde,vlan=0,sock=/run/vde.ctl"
    ];
  };
}
{ config, pkgs, ... }:

{
  imports = [ ./default.nix /root/nixcfg/core.nix ];
  services = {
    example = {
      enable = true;
    };
  };
  environment.systemPackages = with pkgs; [ wget tcpdump ltrace gdb ];
  networking.hostName = "nixos.example.com";
  networking.firewall.allowedTCPPorts = [ 80 ];
  virtualisation = {
    memorySize = 512;
    graphics = false;
    qemu.networkingOptions = [ "-net nic,macaddr=52:54:00:12:34:01" "-net vde,sock=/run/vde.ctl" ];
  };
}