Class: VagrantPlugins::Nixos::Cap::ConfigureNetworks
- Inherits:
-
Object
- Object
- VagrantPlugins::Nixos::Cap::ConfigureNetworks
- Includes:
- Vagrant::Util
- Defined in:
- lib/vagrant-nixos/cap/configure_networks.rb
Class Method Summary collapse
- .configure_networks(machine, networks) ⇒ Object
- .nix_interface_expr(options) ⇒ Object
- .nix_module(networks) ⇒ Object
Class Method Details
.configure_networks(machine, networks) ⇒ Object
47 48 49 50 51 |
# File 'lib/vagrant-nixos/cap/configure_networks.rb', line 47 def self.configure_networks(machine, networks) if Nixos.write_config(machine, "vagrant-interfaces.nix", nix_module(networks)) machine.env.ui.info "Setting up network interfaces #{networks}" end end |
.nix_interface_expr(options) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/vagrant-nixos/cap/configure_networks.rb', line 13 def self.nix_interface_expr() addr = NetAddr::CIDR.create("#{[:ip]} #{[:netmask]}") prefix_length = addr.netmask[1, addr.netmask.size] <<-NIX { name = "eth#{[:interface]}"; ipAddress = "#{[:ip]}"; prefixLength = #{prefix_length}; } NIX end |
.nix_module(networks) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/vagrant-nixos/cap/configure_networks.rb', line 25 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 |