Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at 22.05 164 lines 5.5 kB view raw
1{ lib 2, python3 3, pkgconfig 4, wrapGAppsHook 5, gettext 6, gtk3 7, glib 8, dbus 9, gobject-introspection 10, xmodmap 11, pygobject3 12, setuptools 13, evdev 14, pydantic 15, pydbus 16, psutil 17, fetchFromGitHub 18, buildPythonApplication 19, procps 20, gtksourceview4 21, nixosTests 22 # Change the default log level to debug for easier debugging of package issues 23, withDebugLogLevel ? false 24 # Xmodmap is an optional dependency 25 # If you use Xmodmap to set keyboard mappings (or your DE does) 26 # it is required to correctly map keys 27, withXmodmap ? true 28 # Some tests are flakey under high CPU load and could cause intermittent 29 # failures when building. Override this to true to run tests anyway 30 # See upstream issue: https://github.com/sezanzeb/input-remapper/issues/306 31, withDoCheck ? false 32 # Version and rev and hash are package arguments to allow overriding 33 # while ensuring the values in prePatch and src match 34 # https://discourse.nixos.org/t/avoid-rec-expresions-in-nixpkgs/8293/7 35 # The names are prefixed with input_remapper to avoid potential 36 # collisions with package names 37, input_remapper_version ? "1.4.2" 38, input_remapper_src_rev ? "af20f87a1298153e765b840a2164ba63b9ef937a" 39, input_remapper_src_hash ? "sha256-eG4Fx1z74Bq1HrfmzOuULQLziGdWnHLax8y2dymjWsI=" 40}: 41 42let 43 maybeXmodmap = lib.optional withXmodmap xmodmap; 44in 45buildPythonApplication { 46 pname = "input-remapper"; 47 version = input_remapper_version; 48 49 src = fetchFromGitHub { 50 rev = input_remapper_src_rev; 51 owner = "sezanzeb"; 52 repo = "input-remapper"; 53 hash = input_remapper_src_hash; 54 }; 55 56 # Fixes error 57 # Couldn’t recognize the image file format for file "*.svg" 58 # at startup, see https://github.com/NixOS/nixpkgs/issues/56943 59 strictDeps = false; 60 61 prePatch = '' 62 # set revision for --version output 63 echo "COMMIT_HASH = '${input_remapper_src_rev}'" > inputremapper/commit_hash.py 64 65 # fix FHS paths 66 substituteInPlace inputremapper/configs/data.py \ 67 --replace "/usr/share/input-remapper" "$out/usr/share/input-remapper" 68 '' + (lib.optionalString (withDebugLogLevel) '' 69 # if debugging 70 substituteInPlace inputremapper/logger.py --replace "logger.setLevel(logging.INFO)" "logger.setLevel(logging.DEBUG)" 71 ''); 72 73 doCheck = withDoCheck; 74 checkInputs = [ 75 psutil 76 ]; 77 pythonImportsCheck = [ 78 "evdev" 79 "inputremapper" 80 ]; 81 82 # Custom test script, can't use plain pytest / pytestCheckHook 83 # We only run tests in the unit folder, integration tests require UI 84 # To allow tests which access the system and session DBUS to run, we start a dbus session 85 # and bind it to both the system and session buses 86 installCheckPhase = '' 87 echo "<busconfig> 88 <type>session</type> 89 <listen>unix:tmpdir=$TMPDIR</listen> 90 <listen>unix:path=/build/system_bus_socket</listen> 91 <standard_session_servicedirs/> 92 <policy context=\"default\"> 93 <!-- Allow everything to be sent --> 94 <allow send_destination=\"*\" eavesdrop=\"true\"/> 95 <!-- Allow everything to be received --> 96 <allow eavesdrop=\"true\"/> 97 <!-- Allow anyone to own anything --> 98 <allow own=\"*\"/> 99 </policy> 100 </busconfig>" > dbus.cfg 101 PATH=${lib.makeBinPath ([ dbus procps ] ++ maybeXmodmap)}:$PATH \ 102 USER="$(id -u -n)" \ 103 DBUS_SYSTEM_BUS_ADDRESS=unix:path=/build/system_bus_socket \ 104 ${dbus}/bin/dbus-run-session --config-file dbus.cfg \ 105 python tests/test.py --start-dir unit 106 ''; 107 108 # Nixpkgs 15.9.4.3. When using wrapGAppsHook with special derivers you can end up with double wrapped binaries. 109 dontWrapGApps = true; 110 preFixup = '' 111 makeWrapperArgs+=( 112 "''${gappsWrapperArgs[@]}" 113 --prefix PATH : "${lib.makeBinPath maybeXmodmap}" 114 ) 115 ''; 116 117 nativeBuildInputs = [ 118 wrapGAppsHook 119 gettext # needed to build translations 120 gtk3 121 glib 122 gobject-introspection 123 pygobject3 124 ] ++ maybeXmodmap; 125 126 propagatedBuildInputs = [ 127 setuptools # needs pkg_resources 128 pygobject3 129 evdev 130 pkgconfig 131 pydantic 132 pydbus 133 gtksourceview4 134 ]; 135 136 postInstall = '' 137 sed -r "s#RUN\+\=\"/bin/input-remapper-control#RUN\+\=\"$out/bin/input-remapper-control#g" -i data/99-input-remapper.rules 138 sed -r "s#ExecStart\=/usr/bin/input-remapper-service#ExecStart\=$out/bin/input-remapper-service#g" -i data/input-remapper.service 139 140 chmod +x data/*.desktop 141 142 install -D -t $out/share/applications/ data/*.desktop 143 install -D -t $out/share/polkit-1/actions/ data/input-remapper.policy 144 install -D data/99-input-remapper.rules $out/etc/udev/rules.d/99-input-remapper.rules 145 install -D data/input-remapper.service $out/lib/systemd/system/input-remapper.service 146 install -D data/input-remapper.policy $out/share/polkit-1/actions/input-remapper.policy 147 install -D data/inputremapper.Control.conf $out/etc/dbus-1/system.d/inputremapper.Control.conf 148 install -D -t $out/usr/share/input-remapper/ data/* 149 150 # Only install input-remapper prefixed binaries, we don't care about deprecated key-mapper ones 151 install -m755 -D -t $out/bin/ bin/input-remapper* 152 ''; 153 154 passthru.tests = nixosTests.input-remapper; 155 156 meta = with lib; { 157 description = "An easy to use tool to change the mapping of your input device buttons"; 158 homepage = "https://github.com/sezanzeb/input-remapper"; 159 license = licenses.gpl3Plus; 160 platforms = platforms.linux; 161 maintainers = with maintainers; [ LunNova ]; 162 mainProgram = "input-remapper-gtk"; 163 }; 164}