nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at python-updates 247 lines 6.3 kB view raw
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.91.0"; 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-naKklfBtwBorfSLPLc/XYC4M22G6X5So4Q3SXZtT4pI="; 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 68 strictDeps = true; 69 70 depsBuildBuild = [ 71 pkg-config 72 ]; 73 74 nativeBuildInputs = [ 75 meson 76 ninja 77 python3 78 docbook-xsl-nons 79 gettext 80 libxslt 81 makeWrapper 82 pkg-config 83 glib 84 ] 85 ++ lib.optionals withIntrospection [ 86 gobject-introspection 87 ] 88 ++ lib.optionals withDocs [ 89 gtk-doc 90 ] 91 ++ lib.optionals (withDocs && !stdenv.buildPlatform.canExecute stdenv.hostPlatform) [ 92 mesonEmulatorHook 93 ]; 94 95 buildInputs = [ 96 libgudev 97 libusb1 98 udev 99 ] 100 ++ lib.optionals withIntrospection [ 101 # Duplicate from nativeCheckInputs until https://github.com/NixOS/nixpkgs/issues/161570 is solved 102 umockdev 103 104 # For installed tests. 105 (python3.withPackages (pp: [ 106 pp.dbus-python 107 pp.python-dbusmock 108 pp.pygobject3 109 pp.packaging 110 ])) 111 ] 112 ++ lib.optionals withSystemd [ 113 systemd 114 ] 115 ++ lib.optionals useIMobileDevice [ 116 libimobiledevice 117 ]; 118 119 nativeCheckInputs = [ 120 libeatmydata 121 ] 122 ++ lib.optionals withIntrospection [ 123 python3.pkgs.dbus-python 124 python3.pkgs.python-dbusmock 125 python3.pkgs.pygobject3 126 dbus 127 umockdev 128 python3.pkgs.packaging 129 ]; 130 131 propagatedBuildInputs = [ 132 glib 133 polkit 134 ]; 135 136 mesonFlags = [ 137 "--localstatedir=/var" 138 "--sysconfdir=/etc" 139 "-Dos_backend=linux" 140 "-Dsystemdsystemunitdir=${placeholder "out"}/etc/systemd/system" 141 "-Dudevrulesdir=${placeholder "out"}/lib/udev/rules.d" 142 "-Dudevhwdbdir=${placeholder "out"}/lib/udev/hwdb.d" 143 (lib.mesonEnable "introspection" withIntrospection) 144 (lib.mesonBool "gtk-doc" withDocs) 145 "-Dinstalled_test_prefix=${placeholder "installedTests"}" 146 ]; 147 148 doCheck = true; 149 doInstallCheck = true; 150 151 postPatch = '' 152 patchShebangs src/linux/integration-test.py 153 patchShebangs src/linux/unittest_inspector.py 154 155 substituteInPlace src/linux/integration-test.py \ 156 --replace-fail "/usr/share/dbus-1" "$out/share/dbus-1" 157 ''; 158 159 preCheck = '' 160 # Our gobject-introspection patches make the shared library paths absolute 161 # in the GIR files. When running tests, the library is not yet installed, 162 # though, so we need to replace the absolute path with a local one during build. 163 mkdir -p "$out/lib" 164 ln -s "$PWD/libupower-glib/libupower-glib.so" "$out/lib/libupower-glib.so.3" 165 ''; 166 167 checkPhase = '' 168 runHook preCheck 169 170 # Slow fsync calls can make self-test fail: 171 # https://gitlab.freedesktop.org/upower/upower/-/issues/195 172 eatmydata meson test --print-errorlogs 173 174 runHook postCheck 175 ''; 176 177 postCheck = '' 178 # Undo patchShebangs from postPatch so that it can be replaced with runtime shebang 179 # unittest_inspector.py intentionally not reverted because it would trigger 180 # meson rebuild during install and it is not used at runtime anyway. 181 sed -Ei 's~#!.+/bin/python3~#!/usr/bin/python3~' \ 182 ../src/linux/integration-test.py 183 184 # Undo preCheck installation since DESTDIR hack expects outputs to not exist. 185 rm "$out/lib/libupower-glib.so.3" 186 rmdir "$out/lib" "$out" 187 ''; 188 189 postInstall = '' 190 # Move stuff from DESTDIR to proper location. 191 for o in $(getAllOutputNames); do 192 # devdoc is created later by _multioutDocs hook. 193 if [[ "$o" = "devdoc" ]]; then continue; fi 194 mv "$DESTDIR''${!o}" "$(dirname "''${!o}")" 195 done 196 197 mv "$DESTDIR/var" "$out" 198 # The /etc already exist so we need to merge it. 199 cp --recursive "$DESTDIR/etc" "$out" 200 rm --recursive "$DESTDIR/etc" 201 202 # Ensure we did not forget to install anything. 203 rmdir --parents --ignore-fail-on-non-empty "$DESTDIR${builtins.storeDir}" 204 ! test -e "$DESTDIR" 205 ''; 206 207 postFixup = lib.optionalString withIntrospection '' 208 wrapProgram "$installedTests/libexec/upower/integration-test.py" \ 209 --prefix GI_TYPELIB_PATH : "${ 210 lib.makeSearchPath "lib/girepository-1.0" [ 211 "$out" 212 umockdev.out 213 ] 214 }" \ 215 --prefix PATH : "${ 216 lib.makeBinPath [ 217 umockdev 218 ] 219 }" 220 ''; 221 222 env = { 223 # HACK: We want to install configuration files to $out/etc 224 # but upower should read them from /etc on a NixOS system. 225 # With autotools, it was possible to override Make variables 226 # at install time but Meson does not support this 227 # so we need to convince it to install all files to a temporary 228 # location using DESTDIR and then move it to proper one in postInstall. 229 DESTDIR = "dest"; 230 }; 231 232 passthru = { 233 tests = { 234 installedTests = nixosTests.installed-tests.upower; 235 }; 236 }; 237 238 meta = { 239 homepage = "https://upower.freedesktop.org/"; 240 changelog = "https://gitlab.freedesktop.org/upower/upower/-/blob/v${finalAttrs.version}/NEWS"; 241 description = "D-Bus service for power management"; 242 mainProgram = "upower"; 243 teams = [ lib.teams.freedesktop ]; 244 platforms = lib.platforms.linux; 245 license = lib.licenses.gpl2Plus; 246 }; 247})