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