1{
2 lib,
3 fetchFromGitHub,
4 buildPythonPackage,
5 bash,
6 bashInteractive,
7 util-linux,
8 setuptools,
9 distro,
10 udevCheckHook,
11}:
12
13buildPythonPackage rec {
14 pname = "google-compute-engine";
15 version = "20190124";
16 format = "setuptools";
17
18 src = fetchFromGitHub {
19 owner = "GoogleCloudPlatform";
20 repo = "compute-image-packages";
21 rev = version;
22 sha256 = "08cy0jd463kng6hwbd3nfldsp4dpd2lknlvdm88cq795wy0kh4wp";
23 };
24
25 buildInputs = [ bash ];
26 propagatedBuildInputs = [
27 setuptools
28 distro
29 ];
30
31 nativeBuildInputs = [
32 udevCheckHook
33 ];
34
35 postPatch = ''
36 for file in $(find google_compute_engine -type f); do
37 substituteInPlace "$file" \
38 --replace /bin/systemctl "/run/current-system/systemd/bin/systemctl" \
39 --replace /bin/bash "${bashInteractive}/bin/bash" \
40 --replace /sbin/hwclock "${util-linux}/bin/hwclock"
41 # SELinux tool ??? /sbin/restorecon
42 done
43
44 substituteInPlace google_config/udev/64-gce-disk-removal.rules \
45 --replace /bin/sh "${bash}/bin/sh" \
46 --replace /bin/umount "${util-linux}/bin/umount" \
47 --replace /usr/bin/logger "${util-linux}/bin/logger"
48 '';
49
50 postInstall = ''
51 # allows to install the package in `services.udev.packages` in NixOS
52 mkdir -p $out/lib/udev/rules.d
53 cp -r google_config/udev/*.rules $out/lib/udev/rules.d
54
55 # sysctl snippets will be used by google-compute-config.nix
56 mkdir -p $out/sysctl.d
57 cp google_config/sysctl/*.conf $out/sysctl.d
58
59 patchShebangs $out/bin/*
60 '';
61
62 pythonImportsCheck = [ "google_compute_engine" ];
63
64 meta = with lib; {
65 description = "Google Compute Engine tools and services";
66 homepage = "https://github.com/GoogleCloudPlatform/compute-image-packages";
67 license = licenses.asl20;
68 maintainers = with maintainers; [ zimbatm ];
69 platforms = platforms.linux;
70 };
71}