fork
Configure Feed
Select the types of activity you want to include in your feed.
lol
fork
Configure Feed
Select the types of activity you want to include in your feed.
1{
2 lib,
3 stdenv,
4 fetchFromGitLab,
5 fetchpatch,
6 makeWrapper,
7 pkg-config,
8 libxslt,
9 meson,
10 ninja,
11 python3,
12 dbus,
13 umockdev,
14 libeatmydata,
15 gtk-doc,
16 docbook-xsl-nons,
17 udev,
18 libgudev,
19 libusb1,
20 glib,
21 gettext,
22 polkit,
23 nixosTests,
24 useIMobileDevice ? true,
25 libimobiledevice,
26 withDocs ? withIntrospection,
27 mesonEmulatorHook,
28 withIntrospection ?
29 lib.meta.availableOn stdenv.hostPlatform gobject-introspection
30 && stdenv.hostPlatform.emulatorAvailable buildPackages,
31 buildPackages,
32 gobject-introspection,
33 withSystemd ? lib.meta.availableOn stdenv.hostPlatform systemd,
34 systemd,
35}:
36
37assert withDocs -> withIntrospection;
38
39stdenv.mkDerivation (finalAttrs: {
40 pname = "upower";
41 version = "1.90.6";
42
43 outputs = [
44 "out"
45 "dev"
46 ]
47 ++ lib.optionals withDocs [ "devdoc" ]
48 ++ lib.optionals withIntrospection [ "installedTests" ];
49
50 src = fetchFromGitLab {
51 domain = "gitlab.freedesktop.org";
52 owner = "upower";
53 repo = "upower";
54 rev = "v${finalAttrs.version}";
55 hash = "sha256-Y3MIB6a11P00B/6E3UyoyjLLP8TIT3vM2FDO7zlBz/w=";
56 };
57
58 patches =
59 lib.optionals (stdenv.hostPlatform.system == "i686-linux") [
60 # Remove when this is fixed upstream:
61 # https://gitlab.freedesktop.org/upower/upower/-/issues/214
62 ./i686-test-remove-battery-check.patch
63 ]
64 ++ [
65 ./installed-tests-path.patch
66
67 # Fix a race condition in test_sibling_priority_no_overwrite
68 # Remove when updating to > 1.90.6
69 (fetchpatch {
70 url = "https://gitlab.freedesktop.org/upower/upower/-/commit/9ee76826bd41a5d3a377dfd6f5835f42ec50be9a.patch";
71 hash = "sha256-E56iz/iHn+VM7Opo0a13A5nhnB9nf6C7Y1kyWzk4ZnU=";
72 })
73 # Fix style issues in the udev rules file
74 (fetchpatch {
75 url = "https://gitlab.freedesktop.org/upower/upower/-/commit/6f9d84694da56b317989b8c34250b60d833a4b29.patch";
76 hash = "sha256-xBUbf4qz9Llmw7CuKKMp/uPk7JqwjB4+p7z9kMOVRuE=";
77 })
78 ];
79
80 strictDeps = true;
81
82 depsBuildBuild = [
83 pkg-config
84 ];
85
86 nativeBuildInputs = [
87 meson
88 ninja
89 python3
90 docbook-xsl-nons
91 gettext
92 libxslt
93 makeWrapper
94 pkg-config
95 glib
96 ]
97 ++ lib.optionals withIntrospection [
98 gobject-introspection
99 ]
100 ++ lib.optionals withDocs [
101 gtk-doc
102 ]
103 ++ lib.optionals (withDocs && !stdenv.buildPlatform.canExecute stdenv.hostPlatform) [
104 mesonEmulatorHook
105 ];
106
107 buildInputs = [
108 libgudev
109 libusb1
110 udev
111 ]
112 ++ lib.optionals withIntrospection [
113 # Duplicate from nativeCheckInputs until https://github.com/NixOS/nixpkgs/issues/161570 is solved
114 umockdev
115
116 # For installed tests.
117 (python3.withPackages (pp: [
118 pp.dbus-python
119 pp.python-dbusmock
120 pp.pygobject3
121 pp.packaging
122 ]))
123 ]
124 ++ lib.optionals withSystemd [
125 systemd
126 ]
127 ++ lib.optionals useIMobileDevice [
128 libimobiledevice
129 ];
130
131 nativeCheckInputs = [
132 libeatmydata
133 ]
134 ++ lib.optionals withIntrospection [
135 python3.pkgs.dbus-python
136 python3.pkgs.python-dbusmock
137 python3.pkgs.pygobject3
138 dbus
139 umockdev
140 python3.pkgs.packaging
141 ];
142
143 propagatedBuildInputs = [
144 glib
145 polkit
146 ];
147
148 mesonFlags = [
149 "--localstatedir=/var"
150 "--sysconfdir=/etc"
151 "-Dos_backend=linux"
152 "-Dsystemdsystemunitdir=${placeholder "out"}/etc/systemd/system"
153 "-Dudevrulesdir=${placeholder "out"}/lib/udev/rules.d"
154 "-Dudevhwdbdir=${placeholder "out"}/lib/udev/hwdb.d"
155 (lib.mesonEnable "introspection" withIntrospection)
156 (lib.mesonBool "gtk-doc" withDocs)
157 "-Dinstalled_test_prefix=${placeholder "installedTests"}"
158 ];
159
160 doCheck = true;
161 doInstallCheck = true;
162
163 postPatch = ''
164 patchShebangs src/linux/integration-test.py
165 patchShebangs src/linux/unittest_inspector.py
166
167 substituteInPlace src/linux/integration-test.py \
168 --replace-fail "/usr/share/dbus-1" "$out/share/dbus-1"
169 '';
170
171 preCheck = ''
172 # Our gobject-introspection patches make the shared library paths absolute
173 # in the GIR files. When running tests, the library is not yet installed,
174 # though, so we need to replace the absolute path with a local one during build.
175 mkdir -p "$out/lib"
176 ln -s "$PWD/libupower-glib/libupower-glib.so" "$out/lib/libupower-glib.so.3"
177 '';
178
179 checkPhase = ''
180 runHook preCheck
181
182 # Slow fsync calls can make self-test fail:
183 # https://gitlab.freedesktop.org/upower/upower/-/issues/195
184 eatmydata meson test --print-errorlogs
185
186 runHook postCheck
187 '';
188
189 postCheck = ''
190 # Undo patchShebangs from postPatch so that it can be replaced with runtime shebang
191 # unittest_inspector.py intentionally not reverted because it would trigger
192 # meson rebuild during install and it is not used at runtime anyway.
193 sed -Ei 's~#!.+/bin/python3~#!/usr/bin/python3~' \
194 ../src/linux/integration-test.py
195
196 # Undo preCheck installation since DESTDIR hack expects outputs to not exist.
197 rm "$out/lib/libupower-glib.so.3"
198 rmdir "$out/lib" "$out"
199 '';
200
201 postInstall = ''
202 # Move stuff from DESTDIR to proper location.
203 for o in $(getAllOutputNames); do
204 # devdoc is created later by _multioutDocs hook.
205 if [[ "$o" = "devdoc" ]]; then continue; fi
206 mv "$DESTDIR''${!o}" "$(dirname "''${!o}")"
207 done
208
209 mv "$DESTDIR/var" "$out"
210 # The /etc already exist so we need to merge it.
211 cp --recursive "$DESTDIR/etc" "$out"
212 rm --recursive "$DESTDIR/etc"
213
214 # Ensure we did not forget to install anything.
215 rmdir --parents --ignore-fail-on-non-empty "$DESTDIR${builtins.storeDir}"
216 ! test -e "$DESTDIR"
217 '';
218
219 postFixup = lib.optionalString withIntrospection ''
220 wrapProgram "$installedTests/libexec/upower/integration-test.py" \
221 --prefix GI_TYPELIB_PATH : "${
222 lib.makeSearchPath "lib/girepository-1.0" [
223 "$out"
224 umockdev.out
225 ]
226 }" \
227 --prefix PATH : "${
228 lib.makeBinPath [
229 umockdev
230 ]
231 }"
232 '';
233
234 env = {
235 # HACK: We want to install configuration files to $out/etc
236 # but upower should read them from /etc on a NixOS system.
237 # With autotools, it was possible to override Make variables
238 # at install time but Meson does not support this
239 # so we need to convince it to install all files to a temporary
240 # location using DESTDIR and then move it to proper one in postInstall.
241 DESTDIR = "dest";
242 };
243
244 passthru = {
245 tests = {
246 installedTests = nixosTests.installed-tests.upower;
247 };
248 };
249
250 meta = with lib; {
251 homepage = "https://upower.freedesktop.org/";
252 changelog = "https://gitlab.freedesktop.org/upower/upower/-/blob/v${finalAttrs.version}/NEWS";
253 description = "D-Bus service for power management";
254 mainProgram = "upower";
255 teams = [ teams.freedesktop ];
256 platforms = platforms.linux;
257 license = licenses.gpl2Plus;
258 };
259})