Fix network config for recent NixOS releases

The old config style doesn't build anymore on the current
release NixOS 20.09. It stopped working some releases ago.
This commit is contained in:
Tobias dpausp 2021-01-24 23:59:00 +00:00
parent 365dc3bed2
commit 2d1a82bcf0
2 changed files with 32 additions and 6 deletions

View File

@ -1,16 +1,15 @@
{ config, pkgs, ... }: { config, pkgs, ... }:
{ {
networking.interfaces = [ networking.interfaces = {
<% networks.select {|n| n[:device]}.each do |network| %> <% networks.select {|n| n[:device]}.each do |network| %>
{ <%= network[:device] %>.ipv4.addresses = [{
name = "<%= network[:device] %>";
<% if network[:type] == :static %> <% if network[:type] == :static %>
ipAddress = "<%= network[:ip] %>"; address = "<%= network[:ip] %>";
<% end %> <% end %>
<% if network[:prefix_length] %> <% if network[:prefix_length] %>
prefixLength = <%= network[:prefix_length] %>; prefixLength = <%= network[:prefix_length] %>;
<% end %> <% end %>
} }];
<% end %> <% end %>
]; };
} }

View File

@ -0,0 +1,27 @@
require_relative "../../../base"
require "vagrant/util/template_renderer"
describe "templates/guests/nixos/network" do
let(:template) { "guests/nixos/network" }
it "renders the template" do
result = Vagrant::Util::TemplateRenderer.render(template, networks: [{
device: "en0",
ip: "1.1.1.1",
prefix_length: "24",
type: :static,
}])
expect(result).to eq <<-EOH.gsub(/^ {6}/, "")
{ config, pkgs, ... }:
{
networking.interfaces = {
en0.ipv4.addresses = [{
address = "1.1.1.1";
prefixLength = 24;
}];
};
}
EOH
end
end