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