nixos/cloud-init: add support for network configuration
This commit is contained in:
parent
d0c12f5b3f
commit
43cfb7204b
|
@ -52,11 +52,22 @@ in
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
network.enable = mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
default = false;
|
||||||
|
description = ''
|
||||||
|
Allow the cloud-init service to configure network interfaces
|
||||||
|
through systemd-networkd.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
config = mkOption {
|
config = mkOption {
|
||||||
type = types.str;
|
type = types.str;
|
||||||
default = ''
|
default = ''
|
||||||
system_info:
|
system_info:
|
||||||
distro: nixos
|
distro: nixos
|
||||||
|
network:
|
||||||
|
renderers: [ 'networkd' ]
|
||||||
users:
|
users:
|
||||||
- root
|
- root
|
||||||
|
|
||||||
|
@ -109,9 +120,12 @@ in
|
||||||
|
|
||||||
environment.etc."cloud/cloud.cfg".text = cfg.config;
|
environment.etc."cloud/cloud.cfg".text = cfg.config;
|
||||||
|
|
||||||
|
systemd.network.enable = cfg.network.enable;
|
||||||
|
|
||||||
systemd.services.cloud-init-local =
|
systemd.services.cloud-init-local =
|
||||||
{ description = "Initial cloud-init job (pre-networking)";
|
{ description = "Initial cloud-init job (pre-networking)";
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
|
before = ["systemd-networkd.service"];
|
||||||
path = path;
|
path = path;
|
||||||
serviceConfig =
|
serviceConfig =
|
||||||
{ Type = "oneshot";
|
{ Type = "oneshot";
|
||||||
|
|
|
@ -35,6 +35,24 @@ let
|
||||||
public-keys:
|
public-keys:
|
||||||
- "${snakeOilPublicKey}"
|
- "${snakeOilPublicKey}"
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
cat << EOF > $out/iso/network-config
|
||||||
|
version: 1
|
||||||
|
config:
|
||||||
|
- type: physical
|
||||||
|
name: eth0
|
||||||
|
mac_address: '52:54:00:12:34:56'
|
||||||
|
subnets:
|
||||||
|
- type: static
|
||||||
|
address: '12.34.56.78'
|
||||||
|
netmask: '255.255.255.0'
|
||||||
|
gateway: '12.34.56.9'
|
||||||
|
- type: nameserver
|
||||||
|
address:
|
||||||
|
- '8.8.8.8'
|
||||||
|
search:
|
||||||
|
- 'example.com'
|
||||||
|
EOF
|
||||||
${pkgs.cdrkit}/bin/genisoimage -volid cidata -joliet -rock -o $out/metadata.iso $out/iso
|
${pkgs.cdrkit}/bin/genisoimage -volid cidata -joliet -rock -o $out/metadata.iso $out/iso
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
@ -46,9 +64,13 @@ in makeTest {
|
||||||
machine = { ... }:
|
machine = { ... }:
|
||||||
{
|
{
|
||||||
virtualisation.qemu.options = [ "-cdrom" "${metadataDrive}/metadata.iso" ];
|
virtualisation.qemu.options = [ "-cdrom" "${metadataDrive}/metadata.iso" ];
|
||||||
services.cloud-init.enable = true;
|
services.cloud-init = {
|
||||||
|
enable = true;
|
||||||
|
network.enable = true;
|
||||||
|
};
|
||||||
services.openssh.enable = true;
|
services.openssh.enable = true;
|
||||||
networking.hostName = "";
|
networking.hostName = "";
|
||||||
|
networking.useDHCP = false;
|
||||||
};
|
};
|
||||||
testScript = ''
|
testScript = ''
|
||||||
# To wait until cloud-init terminates its run
|
# To wait until cloud-init terminates its run
|
||||||
|
@ -80,5 +102,8 @@ in makeTest {
|
||||||
).strip()
|
).strip()
|
||||||
== "test"
|
== "test"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
assert "default via 12.34.56.9 dev eth0 proto static" in unnamed.succeed("ip route")
|
||||||
|
assert "12.34.56.0/24 dev eth0 proto kernel scope link src 12.34.56.78" in unnamed.succeed("ip route")
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue