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