at 24.05-pre 214 lines 5.7 kB view raw
1{ lib 2, stdenv 3, fetchFromGitLab 4, makeWrapper 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, gettext 21, systemd 22, nixosTests 23, useIMobileDevice ? true 24, libimobiledevice 25, withDocs ? withIntrospection 26, mesonEmulatorHook 27, withIntrospection ? lib.meta.availableOn stdenv.hostPlatform gobject-introspection && stdenv.hostPlatform.emulatorAvailable buildPackages 28, buildPackages 29, gobject-introspection 30}: 31 32assert withDocs -> withIntrospection; 33 34stdenv.mkDerivation (finalAttrs: { 35 pname = "upower"; 36 version = "1.90.2"; 37 38 outputs = [ "out" "dev" "installedTests" ] 39 ++ lib.optionals withDocs [ "devdoc" ]; 40 41 src = fetchFromGitLab { 42 domain = "gitlab.freedesktop.org"; 43 owner = "upower"; 44 repo = "upower"; 45 rev = "v${finalAttrs.version}"; 46 hash = "sha256-7WzMAJuf1czU8ZalsEU/NwCXYqTGvcqEqxFt5ocgt48="; 47 }; 48 49 patches = lib.optionals (stdenv.hostPlatform.system == "i686-linux") [ 50 # Remove when this is fixed upstream: 51 # https://gitlab.freedesktop.org/upower/upower/-/issues/214 52 ./i686-test-remove-battery-check.patch 53 ] ++ [ 54 ./installed-tests-path.patch 55 ]; 56 57 strictDeps = true; 58 59 depsBuildBuild = [ 60 pkg-config 61 ]; 62 63 nativeBuildInputs = [ 64 meson 65 ninja 66 python3 67 docbook-xsl-nons 68 gettext 69 libxslt 70 makeWrapper 71 pkg-config 72 rsync 73 glib 74 ] ++ lib.optionals withIntrospection [ 75 gobject-introspection 76 ] ++ lib.optionals withDocs [ 77 gtk-doc 78 ] ++ lib.optionals (withDocs && !stdenv.buildPlatform.canExecute stdenv.hostPlatform) [ 79 mesonEmulatorHook 80 ]; 81 82 buildInputs = [ 83 libgudev 84 libusb1 85 udev 86 systemd 87 # Duplicate from nativeCheckInputs until https://github.com/NixOS/nixpkgs/issues/161570 is solved 88 umockdev 89 90 # For installed tests. 91 (python3.withPackages (pp: [ 92 pp.dbus-python 93 pp.python-dbusmock 94 pp.pygobject3 95 pp.packaging 96 ])) 97 ] ++ lib.optionals useIMobileDevice [ 98 libimobiledevice 99 ]; 100 101 nativeCheckInputs = [ 102 python3.pkgs.dbus-python 103 python3.pkgs.python-dbusmock 104 python3.pkgs.pygobject3 105 dbus 106 umockdev 107 libeatmydata 108 python3.pkgs.packaging 109 ]; 110 111 propagatedBuildInputs = [ 112 glib 113 ]; 114 115 mesonFlags = [ 116 "--localstatedir=/var" 117 "--sysconfdir=/etc" 118 "-Dos_backend=linux" 119 "-Dsystemdsystemunitdir=${placeholder "out"}/etc/systemd/system" 120 "-Dudevrulesdir=${placeholder "out"}/lib/udev/rules.d" 121 "-Dudevhwdbdir=${placeholder "out"}/lib/udev/hwdb.d" 122 (lib.mesonEnable "introspection" withIntrospection) 123 (lib.mesonBool "gtk-doc" withDocs) 124 "-Dinstalled_test_prefix=${placeholder "installedTests"}" 125 ]; 126 127 doCheck = true; 128 129 postPatch = '' 130 patchShebangs src/linux/integration-test.py 131 patchShebangs src/linux/unittest_inspector.py 132 133 substituteInPlace src/linux/integration-test.py \ 134 --replace "/usr/share/dbus-1" "$out/share/dbus-1" 135 ''; 136 137 preCheck = '' 138 # Our gobject-introspection patches make the shared library paths absolute 139 # in the GIR files. When running tests, the library is not yet installed, 140 # though, so we need to replace the absolute path with a local one during build. 141 # We are using a symlink that will be overwitten during installation. 142 mkdir -p "$out/lib" 143 ln -s "$PWD/libupower-glib/libupower-glib.so" "$out/lib/libupower-glib.so.3" 144 ''; 145 146 checkPhase = '' 147 runHook preCheck 148 149 # Slow fsync calls can make self-test fail: 150 # https://gitlab.freedesktop.org/upower/upower/-/issues/195 151 eatmydata meson test --print-errorlogs 152 153 runHook postCheck 154 ''; 155 156 postCheck = '' 157 # Undo patchShebangs from postPatch so that it can be replaced with runtime shebang 158 # unittest_inspector.py intentionally not reverted because it would trigger 159 # meson rebuild during install and it is not used at runtime anyway. 160 sed -Ei 's~#!.+/bin/python3~#!/usr/bin/python3~' \ 161 ../src/linux/integration-test.py 162 ''; 163 164 postInstall = '' 165 # Move stuff from DESTDIR to proper location. 166 # We use rsync to merge the directories. 167 for dir in etc var; do 168 rsync --archive "$DESTDIR/$dir" "$out" 169 rm --recursive "$DESTDIR/$dir" 170 done 171 for o in out dev installedTests; do 172 rsync --archive "$DESTDIR/''${!o}" "$(dirname "''${!o}")" 173 rm --recursive "$DESTDIR/''${!o}" 174 done 175 # Ensure the DESTDIR is removed. 176 rmdir "$DESTDIR/nix/store" "$DESTDIR/nix" "$DESTDIR" 177 ''; 178 179 postFixup = '' 180 wrapProgram "$installedTests/libexec/upower/integration-test.py" \ 181 --prefix GI_TYPELIB_PATH : "${lib.makeSearchPath "lib/girepository-1.0" [ 182 "$out" 183 umockdev.out 184 ]}" \ 185 --prefix PATH : "${lib.makeBinPath [ 186 umockdev 187 ]}" 188 ''; 189 190 env = { 191 # HACK: We want to install configuration files to $out/etc 192 # but upower should read them from /etc on a NixOS system. 193 # With autotools, it was possible to override Make variables 194 # at install time but Meson does not support this 195 # so we need to convince it to install all files to a temporary 196 # location using DESTDIR and then move it to proper one in postInstall. 197 DESTDIR = "${placeholder "out"}/dest"; 198 }; 199 200 passthru = { 201 tests = { 202 installedTests = nixosTests.installed-tests.upower; 203 }; 204 }; 205 206 meta = with lib; { 207 homepage = "https://upower.freedesktop.org/"; 208 changelog = "https://gitlab.freedesktop.org/upower/upower/-/blob/v${finalAttrs.version}/NEWS"; 209 description = "A D-Bus service for power management"; 210 maintainers = teams.freedesktop.members; 211 platforms = platforms.linux; 212 license = licenses.gpl2Plus; 213 }; 214})