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