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