1{ lib
2, nixosTests
3, buildPythonApplication
4, cloud-utils
5, dmidecode
6, fetchFromGitHub
7, iproute2
8, openssh
9, python3
10, shadow
11, systemd
12, coreutils
13, gitUpdater
14, busybox
15}:
16
17python3.pkgs.buildPythonApplication rec {
18 pname = "cloud-init";
19 version = "23.1.2";
20 namePrefix = "";
21
22 src = fetchFromGitHub {
23 owner = "canonical";
24 repo = "cloud-init";
25 rev = "refs/tags/${version}";
26 hash = "sha256-tn4flcrf04hVWhqkmK4qDenXcnV93pP+C+8J63b6FXQ=";
27 };
28
29 patches = [
30 ./0001-add-nixos-support.patch
31 # upstream: https://github.com/canonical/cloud-init/pull/2125
32 ./0002-Add-Udhcpc-support.patch
33 # upstream: https://github.com/canonical/cloud-init/pull/2151
34 ./0003-vultr-remove-check_route-check.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 propagatedBuildInputs = with python3.pkgs; [
60 configobj
61 jinja2
62 jsonpatch
63 jsonschema
64 netifaces
65 oauthlib
66 pyserial
67 pyyaml
68 requests
69 ];
70
71 nativeCheckInputs = with python3.pkgs; [
72 pytestCheckHook
73 httpretty
74 dmidecode
75 # needed for tests; at runtime we rather want the setuid wrapper
76 shadow
77 responses
78 pytest-mock
79 coreutils
80 ];
81
82 makeWrapperArgs = [
83 "--prefix PATH : ${lib.makeBinPath [ dmidecode cloud-utils.guest busybox ]}/bin"
84 ];
85
86 disabledTests = [
87 # tries to create /var
88 "test_dhclient_run_with_tmpdir"
89 # clears path and fails because mkdir is not found
90 "test_path_env_gets_set_from_main"
91 # tries to read from /etc/ca-certificates.conf while inside the sandbox
92 "test_handler_ca_certs"
93 "TestRemoveDefaultCaCerts"
94 # Doesn't work in the sandbox
95 "TestEphemeralDhcpNoNetworkSetup"
96 "TestHasURLConnectivity"
97 "TestReadFileOrUrl"
98 "TestConsumeUserDataHttp"
99 # Chef Omnibus
100 "TestInstallChefOmnibus"
101 # https://github.com/canonical/cloud-init/pull/893
102 "TestGetPackageMirrorInfo"
103 # Disable failing VMware and PuppetAio tests
104 "test_get_data_iso9660_with_network_config"
105 "test_get_data_vmware_guestinfo_with_network_config"
106 "test_get_host_info"
107 "test_no_data_access_method"
108 "test_install_with_collection"
109 "test_install_with_custom_url"
110 "test_install_with_default_arguments"
111 "test_install_with_no_cleanup"
112 "test_install_with_version"
113 ];
114
115 preCheck = ''
116 # TestTempUtils.test_mkdtemp_default_non_root does not like TMPDIR=/build
117 export TMPDIR=/tmp
118 '';
119
120 pythonImportsCheck = [
121 "cloudinit"
122 ];
123
124 passthru = {
125 tests = { inherit (nixosTests) cloud-init cloud-init-hostname; };
126 updateScript = gitUpdater { ignoredVersions = ".ubuntu.*"; };
127 };
128
129 meta = with lib; {
130 homepage = "https://github.com/canonical/cloud-init";
131 description = "Provides configuration and customization of cloud instance";
132 license = with licenses; [ asl20 gpl3Plus ];
133 maintainers = with maintainers; [ illustris jfroche ];
134 platforms = platforms.all;
135 };
136}