1{
2 lib,
3 nixosTests,
4 cloud-utils,
5 dmidecode,
6 fetchFromGitHub,
7 iproute2,
8 openssh,
9 python3,
10 shadow,
11 systemd,
12 coreutils,
13 gitUpdater,
14 busybox,
15 procps,
16}:
17
18python3.pkgs.buildPythonApplication rec {
19 pname = "cloud-init";
20 version = "25.2";
21 pyproject = true;
22
23 namePrefix = "";
24
25 src = fetchFromGitHub {
26 owner = "canonical";
27 repo = "cloud-init";
28 tag = version;
29 hash = "sha256-Ww76dhfoGrIbxPiXHxDjpgPsinmfrs42NnGmzhBeGC0=";
30 };
31
32 patches = [
33 ./0001-add-nixos-support.patch
34 ./0002-fix-test-logs-on-nixos.patch
35 ];
36
37 prePatch = ''
38 substituteInPlace setup.py \
39 --replace /lib/systemd $out/lib/systemd
40
41 substituteInPlace cloudinit/net/networkd.py \
42 --replace '["/usr/sbin", "/bin"]' '["/usr/sbin", "/bin", "${iproute2}/bin", "${systemd}/bin"]'
43
44 substituteInPlace tests/unittests/test_net_activators.py \
45 --replace '["/usr/sbin", "/bin"]' \
46 '["/usr/sbin", "/bin", "${iproute2}/bin", "${systemd}/bin"]'
47
48 substituteInPlace tests/unittests/cmd/test_clean.py \
49 --replace "/bin/bash" "/bin/sh"
50 '';
51
52 postInstall = ''
53 install -D -m755 ./tools/write-ssh-key-fingerprints $out/libexec/write-ssh-key-fingerprints
54 for i in $out/libexec/*; do
55 wrapProgram $i --prefix PATH : "${lib.makeBinPath [ openssh ]}"
56 done
57 '';
58
59 build-system = with python3.pkgs; [
60 setuptools
61 ];
62
63 propagatedBuildInputs = with python3.pkgs; [
64 configobj
65 jinja2
66 jsonpatch
67 jsonschema
68 netifaces
69 oauthlib
70 pyserial
71 pyyaml
72 requests
73 ];
74
75 nativeCheckInputs = with python3.pkgs; [
76 pytest7CheckHook
77 httpretty
78 dmidecode
79 # needed for tests; at runtime we rather want the setuid wrapper
80 passlib
81 shadow
82 responses
83 pytest-mock
84 coreutils
85 procps
86 ];
87
88 makeWrapperArgs = [
89 "--prefix PATH : ${
90 lib.makeBinPath [
91 dmidecode
92 cloud-utils.guest
93 busybox
94 ]
95 }/bin"
96 ];
97
98 disabledTests = [
99 # tries to create /var
100 "test_dhclient_run_with_tmpdir"
101 "test_dhcp_client_failover"
102 # clears path and fails because mkdir is not found
103 "test_path_env_gets_set_from_main"
104 # tries to read from /etc/ca-certificates.conf while inside the sandbox
105 "test_handler_ca_certs"
106 "TestRemoveDefaultCaCerts"
107 # Doesn't work in the sandbox
108 "TestEphemeralDhcpNoNetworkSetup"
109 "TestHasURLConnectivity"
110 "TestReadFileOrUrl"
111 "TestConsumeUserDataHttp"
112 # Chef Omnibus
113 "TestInstallChefOmnibus"
114 # Disable failing VMware and PuppetAio tests
115 "test_get_data_iso9660_with_network_config"
116 "test_get_data_vmware_guestinfo_with_network_config"
117 "test_get_host_info"
118 "test_no_data_access_method"
119 "test_install_with_collection"
120 "test_install_with_custom_url"
121 "test_install_with_default_arguments"
122 "test_install_with_no_cleanup"
123 "test_install_with_version"
124 # https://github.com/canonical/cloud-init/issues/5002
125 "test_found_via_userdata"
126 ];
127
128 preCheck = ''
129 # TestTempUtils.test_mkdtemp_default_non_root does not like TMPDIR=/build
130 export TMPDIR=/tmp
131 '';
132
133 pythonImportsCheck = [
134 "cloudinit"
135 ];
136
137 passthru = {
138 tests = { inherit (nixosTests) cloud-init cloud-init-hostname; };
139 updateScript = gitUpdater { ignoredVersions = ".ubuntu.*"; };
140 };
141
142 meta = with lib; {
143 homepage = "https://github.com/canonical/cloud-init";
144 description = "Provides configuration and customization of cloud instance";
145 changelog = "https://github.com/canonical/cloud-init/raw/${version}/ChangeLog";
146 license = with licenses; [
147 asl20
148 gpl3Plus
149 ];
150 maintainers = with maintainers; [
151 illustris
152 jfroche
153 ];
154 platforms = platforms.all;
155 };
156}