push sheeet
Some checks failed
Periodic Merges (6h) / master → staging-nixos (push) Failing after 12m50s
Periodic Merges (6h) / master → staging-next (push) Failing after 12m54s
Periodic Merges (24h) / merge-base(master,staging) → haskell-updates (push) Failing after 11m54s
Periodic Merges (6h) / staging-next → staging (push) Failing after 12m13s
Periodic Merges (24h) / staging-next-25.05 → staging-25.05 (push) Failing after 13m24s
Periodic Merges (24h) / release-25.05 → staging-next-25.05 (push) Failing after 14m28s

This commit is contained in:
Dark Steveneq
2025-10-09 14:15:47 +02:00
commit 646b892680
49168 changed files with 5897842 additions and 0 deletions

View File

@@ -0,0 +1,127 @@
diff --git a/cloudinit/distros/__init__.py b/cloudinit/distros/__init__.py
index 79e26235..bdc32c52 100644
--- a/cloudinit/distros/__init__.py
+++ b/cloudinit/distros/__init__.py
@@ -91,6 +91,7 @@ OSFAMILIES = {
],
"openeuler": ["openeuler"],
"OpenCloudOS": ["OpenCloudOS", "TencentOS"],
+ "nixos": ["nixos"],
}
LOG = logging.getLogger(__name__)
diff --git a/cloudinit/distros/nixos.py b/cloudinit/distros/nixos.py
new file mode 100644
index 00000000..67c049b8
--- /dev/null
+++ b/cloudinit/distros/nixos.py
@@ -0,0 +1,109 @@
+# vi: ts=4 expandtab
+#
+# Copyright (C) 2012 Canonical Ltd.
+# Copyright (C) 2012 Hewlett-Packard Development Company, L.P.
+# Copyright (C) 2012 Yahoo! Inc.
+#
+# Author: Scott Moser <scott.moser@canonical.com>
+# Author: Juerg Haefliger <juerg.haefliger@hp.com>
+# Author: Joshua Harlow <harlowja@yahoo-inc.com>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 3, as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+import logging
+import os
+
+from cloudinit import distros
+from cloudinit import helpers
+from cloudinit import util
+from cloudinit import atomic_helper
+
+from cloudinit.distros.parsers.hostname import HostnameConf
+from cloudinit.net import dhcp
+
+LOG = logging.getLogger(__name__)
+
+class Distro(distros.Distro):
+
+ def __init__(self, name, cfg, paths):
+ distros.Distro.__init__(self, name, cfg, paths)
+ # This will be used to restrict certain
+ # calls from repeatly happening (when they
+ # should only happen say once per instance...)
+ self._runner = helpers.Runners(paths)
+ self.usr_lib_exec = os.path.join(os.path.dirname(__file__),
+ "../../../../../libexec")
+ self.osfamily = 'nixos'
+ self.dhcp_client_priority = [
+ dhcp.Udhcpc,
+ dhcp.IscDhclient,
+ dhcp.Dhcpcd,
+ ]
+
+ def _select_hostname(self, hostname, fqdn):
+ # Prefer the short hostname over the long
+ # fully qualified domain name
+ if not hostname:
+ return fqdn
+ return hostname
+
+ def _write_hostname(self, your_hostname, out_fn):
+ conf = None
+ try:
+ # Try to update the previous one
+ # so lets see if we can read it first.
+ conf = self._read_hostname_conf(out_fn)
+ except IOError:
+ pass
+ if not conf:
+ conf = HostnameConf('')
+ conf.set_hostname(your_hostname)
+ atomic_helper.write_file(out_fn, str(conf).encode("utf-8"))
+
+ def _read_system_hostname(self):
+ sys_hostname = self._read_hostname(self.hostname_conf_fn)
+ return (self.hostname_conf_fn, sys_hostname)
+
+ def _read_hostname_conf(self, filename):
+ conf = HostnameConf(util.load_text_file(filename))
+ conf.parse()
+ return conf
+
+ def _read_hostname(self, filename, default=None):
+ hostname = None
+ try:
+ conf = self._read_hostname_conf(filename)
+ hostname = conf.hostname
+ except IOError:
+ pass
+ if not hostname:
+ return default
+ return hostname
+
+ def _write_network(self, settings):
+ raise NotImplementedError()
+
+ def apply_locale(self, locale, out_fn=None):
+ raise NotImplementedError()
+
+ def install_packages(self, pkglist):
+ raise NotImplementedError()
+
+ def package_command(self, command, args=None, pkgs=None):
+ pass
+
+ def set_timezone(self, tz):
+ pass
+
+ def update_package_sources(self):
+ pass

View File

@@ -0,0 +1,22 @@
diff --git a/tests/unittests/cmd/devel/test_logs.py b/tests/unittests/cmd/devel/test_logs.py
index 78466e8d0..cc2b7246d 100644
--- a/tests/unittests/cmd/devel/test_logs.py
+++ b/tests/unittests/cmd/devel/test_logs.py
@@ -179,7 +179,7 @@ class TestCollectLogs:
for to_write in to_collect:
write_file(
- tmp_path / to_write, pathlib.Path(to_write).name, mode=0x700
+ tmp_path / to_write, pathlib.Path(to_write).name
)
collect_dir = tmp_path / "collect"
@@ -225,7 +225,7 @@ class TestCollectLogs:
for to_write in to_collect:
write_file(
- tmp_path / to_write, pathlib.Path(to_write).name, mode=0x700
+ tmp_path / to_write, pathlib.Path(to_write).name
)
collect_dir = tmp_path / "collect"

View File

@@ -0,0 +1,156 @@
{
lib,
nixosTests,
cloud-utils,
dmidecode,
fetchFromGitHub,
iproute2,
openssh,
python3,
shadow,
systemd,
coreutils,
gitUpdater,
busybox,
procps,
}:
python3.pkgs.buildPythonApplication rec {
pname = "cloud-init";
version = "25.2";
pyproject = true;
namePrefix = "";
src = fetchFromGitHub {
owner = "canonical";
repo = "cloud-init";
tag = version;
hash = "sha256-Ww76dhfoGrIbxPiXHxDjpgPsinmfrs42NnGmzhBeGC0=";
};
patches = [
./0001-add-nixos-support.patch
./0002-fix-test-logs-on-nixos.patch
];
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"]'
substituteInPlace tests/unittests/cmd/test_clean.py \
--replace "/bin/bash" "/bin/sh"
'';
postInstall = ''
install -D -m755 ./tools/write-ssh-key-fingerprints $out/libexec/write-ssh-key-fingerprints
for i in $out/libexec/*; do
wrapProgram $i --prefix PATH : "${lib.makeBinPath [ openssh ]}"
done
'';
build-system = with python3.pkgs; [
setuptools
];
propagatedBuildInputs = with python3.pkgs; [
configobj
jinja2
jsonpatch
jsonschema
netifaces
oauthlib
pyserial
pyyaml
requests
];
nativeCheckInputs = with python3.pkgs; [
pytest7CheckHook
httpretty
dmidecode
# needed for tests; at runtime we rather want the setuid wrapper
passlib
shadow
responses
pytest-mock
coreutils
procps
];
makeWrapperArgs = [
"--prefix PATH : ${
lib.makeBinPath [
dmidecode
cloud-utils.guest
busybox
]
}/bin"
];
disabledTests = [
# tries to create /var
"test_dhclient_run_with_tmpdir"
"test_dhcp_client_failover"
# clears path and fails because mkdir is not found
"test_path_env_gets_set_from_main"
# tries to read from /etc/ca-certificates.conf while inside the sandbox
"test_handler_ca_certs"
"TestRemoveDefaultCaCerts"
# Doesn't work in the sandbox
"TestEphemeralDhcpNoNetworkSetup"
"TestHasURLConnectivity"
"TestReadFileOrUrl"
"TestConsumeUserDataHttp"
# Chef Omnibus
"TestInstallChefOmnibus"
# Disable failing VMware and PuppetAio tests
"test_get_data_iso9660_with_network_config"
"test_get_data_vmware_guestinfo_with_network_config"
"test_get_host_info"
"test_no_data_access_method"
"test_install_with_collection"
"test_install_with_custom_url"
"test_install_with_default_arguments"
"test_install_with_no_cleanup"
"test_install_with_version"
# https://github.com/canonical/cloud-init/issues/5002
"test_found_via_userdata"
];
preCheck = ''
# TestTempUtils.test_mkdtemp_default_non_root does not like TMPDIR=/build
export TMPDIR=/tmp
'';
pythonImportsCheck = [
"cloudinit"
];
passthru = {
tests = { inherit (nixosTests) cloud-init cloud-init-hostname; };
updateScript = gitUpdater { ignoredVersions = ".ubuntu.*"; };
};
meta = with lib; {
homepage = "https://github.com/canonical/cloud-init";
description = "Provides configuration and customization of cloud instance";
changelog = "https://github.com/canonical/cloud-init/raw/${version}/ChangeLog";
license = with licenses; [
asl20
gpl3Plus
];
maintainers = with maintainers; [
illustris
jfroche
];
platforms = platforms.all;
};
}