1{ lib
2, stdenv
3, fetchFromGitLab
4, fetchpatch
5, pkg-config
6, rsync
7, libxslt
8, meson
9, ninja
10, python3
11, dbus
12, umockdev
13, libeatmydata
14, gtk-doc
15, docbook-xsl-nons
16, udev
17, libgudev
18, libusb1
19, glib
20, gobject-introspection
21, gettext
22, systemd
23, useIMobileDevice ? true
24, libimobiledevice
25, withDocs ? (stdenv.buildPlatform == stdenv.hostPlatform)
26}:
27
28stdenv.mkDerivation rec {
29 pname = "upower";
30 version = "1.90.0";
31
32 outputs = [ "out" "dev" ]
33 ++ lib.optionals withDocs [ "devdoc" ];
34
35 src = fetchFromGitLab {
36 domain = "gitlab.freedesktop.org";
37 owner = "upower";
38 repo = "upower";
39 rev = "v${version}";
40 hash = "sha256-+C/4dDg6WTLpBgkpNyxjthSdqYdaTLC8vG6jG1LNJ7w=";
41 };
42
43 # Remove when this is fixed upstream:
44 # https://gitlab.freedesktop.org/upower/upower/-/issues/214
45 patches = lib.optional (stdenv.hostPlatform.system == "i686-linux")
46 ./i686-test-remove-battery-check.patch;
47
48 strictDeps = true;
49
50 depsBuildBuild = [
51 pkg-config
52 ];
53
54 nativeBuildInputs = [
55 meson
56 ninja
57 python3
58 gtk-doc
59 docbook-xsl-nons
60 gettext
61 gobject-introspection
62 libxslt
63 pkg-config
64 rsync
65 ];
66
67 buildInputs = [
68 libgudev
69 libusb1
70 udev
71 systemd
72 # Duplicate from checkInputs until https://github.com/NixOS/nixpkgs/issues/161570 is solved
73 umockdev
74 ] ++ lib.optionals useIMobileDevice [
75 libimobiledevice
76 ];
77
78 checkInputs = [
79 python3.pkgs.dbus-python
80 python3.pkgs.python-dbusmock
81 python3.pkgs.pygobject3
82 dbus
83 umockdev
84 libeatmydata
85 python3.pkgs.packaging
86 ];
87
88 propagatedBuildInputs = [
89 glib
90 ];
91
92 mesonFlags = [
93 "--localstatedir=/var"
94 "--sysconfdir=/etc"
95 "-Dos_backend=linux"
96 "-Dsystemdsystemunitdir=${placeholder "out"}/etc/systemd/system"
97 "-Dudevrulesdir=${placeholder "out"}/lib/udev/rules.d"
98 "-Dudevhwdbdir=${placeholder "out"}/lib/udev/hwdb.d"
99 "-Dintrospection=${if (stdenv.buildPlatform == stdenv.hostPlatform) then "auto" else "disabled"}"
100 "-Dgtk-doc=${lib.boolToString withDocs}"
101 ];
102
103 doCheck = true;
104
105 postPatch = ''
106 patchShebangs src/linux/integration-test.py
107 patchShebangs src/linux/unittest_inspector.py
108 '';
109
110 preCheck = ''
111 # Our gobject-introspection patches make the shared library paths absolute
112 # in the GIR files. When running tests, the library is not yet installed,
113 # though, so we need to replace the absolute path with a local one during build.
114 # We are using a symlink that will be overwitten during installation.
115 mkdir -p "$out/lib"
116 ln -s "$PWD/libupower-glib/libupower-glib.so" "$out/lib/libupower-glib.so.3"
117 '';
118
119 checkPhase = ''
120 runHook preCheck
121
122 # Slow fsync calls can make self-test fail:
123 # https://gitlab.freedesktop.org/upower/upower/-/issues/195
124 eatmydata meson test --print-errorlogs
125
126 runHook postCheck
127 '';
128
129 postInstall = ''
130 # Move stuff from DESTDIR to proper location.
131 # We use rsync to merge the directories.
132 for dir in etc var; do
133 rsync --archive "${DESTDIR}/$dir" "$out"
134 rm --recursive "${DESTDIR}/$dir"
135 done
136 for o in out dev; do
137 rsync --archive "${DESTDIR}/''${!o}" "$(dirname "''${!o}")"
138 rm --recursive "${DESTDIR}/''${!o}"
139 done
140 # Ensure the DESTDIR is removed.
141 rmdir "${DESTDIR}/nix/store" "${DESTDIR}/nix" "${DESTDIR}"
142 '';
143
144 # HACK: We want to install configuration files to $out/etc
145 # but upower should read them from /etc on a NixOS system.
146 # With autotools, it was possible to override Make variables
147 # at install time but Meson does not support this
148 # so we need to convince it to install all files to a temporary
149 # location using DESTDIR and then move it to proper one in postInstall.
150 DESTDIR = "${placeholder "out"}/dest";
151
152 meta = with lib; {
153 homepage = "https://upower.freedesktop.org/";
154 changelog = "https://gitlab.freedesktop.org/upower/upower/-/blob/v${version}/NEWS";
155 description = "A D-Bus service for power management";
156 maintainers = teams.freedesktop.members;
157 platforms = platforms.linux;
158 license = licenses.gpl2Plus;
159 };
160}