Merge pull request #157146 from illustris/cloudinit

This commit is contained in:
Sandro 2022-02-07 01:27:21 +01:00 committed by GitHub
commit 255417b8f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 53 additions and 2 deletions

View File

@ -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 {
type = types.str;
default = ''
system_info:
distro: nixos
network:
renderers: [ 'networkd' ]
users:
- root
@ -109,9 +120,12 @@ in
environment.etc."cloud/cloud.cfg".text = cfg.config;
systemd.network.enable = cfg.network.enable;
systemd.services.cloud-init-local =
{ description = "Initial cloud-init job (pre-networking)";
wantedBy = [ "multi-user.target" ];
before = ["systemd-networkd.service"];
path = path;
serviceConfig =
{ Type = "oneshot";

View File

@ -35,6 +35,24 @@ let
public-keys:
- "${snakeOilPublicKey}"
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
'';
};
@ -46,9 +64,13 @@ in makeTest {
machine = { ... }:
{
virtualisation.qemu.options = [ "-cdrom" "${metadataDrive}/metadata.iso" ];
services.cloud-init.enable = true;
services.cloud-init = {
enable = true;
network.enable = true;
};
services.openssh.enable = true;
networking.hostName = "";
networking.useDHCP = false;
};
testScript = ''
# To wait until cloud-init terminates its run
@ -80,5 +102,8 @@ in makeTest {
).strip()
== "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")
'';
}

View File

@ -1,11 +1,14 @@
{ lib
, nixosTests
, buildPythonApplication
, cloud-utils
, dmidecode
, fetchFromGitHub
, iproute2
, openssh
, python3
, shadow
, systemd
}:
python3.pkgs.buildPythonApplication rec {
@ -25,6 +28,13 @@ python3.pkgs.buildPythonApplication rec {
prePatch = ''
substituteInPlace setup.py \
--replace /lib/systemd $out/lib/systemd
substituteInPlace cloudinit/net/networkd.py \
--replace "['/usr/sbin', '/bin']" "['/usr/sbin', '/bin', '${iproute2}/bin', '${systemd}/bin']"
substituteInPlace tests/unittests/test_net_activators.py \
--replace "['/usr/sbin', '/bin']" \
"['/usr/sbin', '/bin', '${iproute2}/bin', '${systemd}/bin']"
'';
postInstall = ''
@ -108,6 +118,8 @@ python3.pkgs.buildPythonApplication rec {
"cloudinit"
];
passthru.tests.cloud-init = nixosTests.cloud-init;
meta = with lib; {
homepage = "https://cloudinit.readthedocs.org";
description = "Provides configuration and customization of cloud instance";

View File

@ -2579,7 +2579,7 @@ with pkgs;
clog-cli = callPackage ../development/tools/clog-cli { };
cloud-init = python3.pkgs.callPackage ../tools/virtualization/cloud-init { };
cloud-init = python3.pkgs.callPackage ../tools/virtualization/cloud-init { inherit systemd; };
cloudbrute = callPackage ../tools/security/cloudbrute { };