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