Class: VagrantPlugins::Nixos::Cap::ConfigureNetworks

Inherits:
Object
  • Object
show all
Includes:
Vagrant::Util
Defined in:
lib/vagrant-nixos/cap/configure_networks.rb

Class Method Summary collapse

Class Method Details

.configure_networks(machine, networks) ⇒ Object



44
45
46
47
48
# File 'lib/vagrant-nixos/cap/configure_networks.rb', line 44

def self.configure_networks(machine, networks)
	if Nixos.write_config(machine, "vagrant-interfaces.nix", nix_module(networks))
		Nixos.rebuild(machine)
	end
end

.nix_interface_expr(options) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/vagrant-nixos/cap/configure_networks.rb', line 12

def self.nix_interface_expr(options)
	<<-NIX
		{ 
			name = "eth#{options[:interface]}";
			ipAddress = "#{options[:ip]}";
			subnetMask = "#{options[:netmask]}";
		}
	NIX
end

.nix_module(networks) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/vagrant-nixos/cap/configure_networks.rb', line 22

def self.nix_module(networks)
	exprs = networks.inject([]) do |exprs, network|
		# Interfaces without an ip set will fallback to
		# DHCP if useDHCP is set. So skip them.
		if network[:ip].nil? or network[:ip].empty?
			exprs
		else
			exprs << nix_interface_expr(network)
		end
	end
	<<-NIX
		{ config, pkgs, ... }:
		{
			networking.usePredictableInterfaceNames = false;
			networking.useDHCP = true;
			networking.interfaces = [
				#{exprs.join("\n")}
			];
		}
	NIX
end