-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
226 lines (189 loc) · 7.05 KB
/
Copy pathflake.nix
File metadata and controls
226 lines (189 loc) · 7.05 KB
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
{
description = "User space driver for Huion Keydial Mini bluetooth device";
inputs.nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.1"; # unstable Nixpkgs
outputs =
{ self, ... }@inputs:
let
inherit (inputs.nixpkgs) lib;
supportedSystems = [
"x86_64-linux"
"aarch64-linux"
"aarch64-darwin"
];
forEachSupportedSystem =
f:
lib.genAttrs supportedSystems (
system:
f {
inherit system;
pkgs = import inputs.nixpkgs { inherit system; };
}
);
/*
Change this value ({major}.{min}) to
update the Python virtual-environment
version. When you do this, make sure
to delete the `.venv` directory to
have the hook rebuild it for the new
version, since it won't overwrite an
existing one. After this, reload the
development shell to rebuild it.
You'll see a warning asking you to
do this when version mismatches are
present. For safety, removal should
be a manual step, even if trivial.
*/
version = "3.13";
in
{
packages = forEachSupportedSystem (
{ pkgs, system }:
{
default = self.packages.${system}.huion-keydial-mini-driver;
huion-keydial-mini-driver = pkgs.python3Packages.buildPythonApplication {
pname = "huion-keydial-mini-driver";
version = "1.2.1";
src = ./.;
pyproject = true;
build-system = with pkgs.python3Packages; [
setuptools
wheel
];
dependencies = with pkgs.python3Packages; [
bleak
evdev
click
pyyaml
dbus-next
];
nativeCheckInputs = with pkgs.python3Packages; [
pytest
pytest-asyncio
pytest-cov
pytest-mock
];
doCheck = false; # Disable tests for now, can enable if needed
postInstall = ''
# Patch and install udev helper script with correct bash path
mkdir -p $out/bin
${pkgs.gnused}/bin/sed \
"s|#!/bin/bash|#!${pkgs.bash}/bin/bash|g" \
${./packaging/udev/unbind-huion.sh} \
> $out/bin/unbind-huion.sh
chmod 755 $out/bin/unbind-huion.sh
# Patch and install systemd user service with correct binary path
mkdir -p $out/lib/systemd/user
${pkgs.gnused}/bin/sed \
"s|/usr/bin/huion-keydial-mini|$out/bin/huion-keydial-mini|g" \
${./packaging/systemd/huion-keydial-mini-user.service} \
> $out/lib/systemd/user/huion-keydial-mini-user.service
# Patch and install udev rules with correct script path
mkdir -p $out/lib/udev/rules.d
${pkgs.gnused}/bin/sed \
"s|/usr/local/bin/unbind-huion.sh|$out/bin/unbind-huion.sh|g" \
${./packaging/udev/99-huion-keydial-mini.rules} \
> $out/lib/udev/rules.d/99-huion-keydial-mini.rules
# Install default config
install -Dm644 ${./packaging/config.yaml.default} \
$out/etc/huion-keydial-mini/config.yaml
# Install documentation
install -Dm644 ${./README.md} \
$out/share/doc/huion-keydial-mini-driver/README.md
# Install license
install -Dm644 ${./LICENSE} \
$out/share/licenses/huion-keydial-mini-driver/LICENSE
# Install systemd user preset
install -Dm644 ${
pkgs.writeText "99-huion-keydial-mini.preset" ''
# Enable huion-keydial-mini-user service
enable huion-keydial-mini-user.service
''
} $out/lib/systemd/user-preset/99-huion-keydial-mini.preset
'';
meta = with lib; {
description = "User space driver for Huion Keydial Mini bluetooth device";
homepage = "https://github.com/the3dcoder/KeydialCommander";
license = licenses.mit;
maintainers = [ ];
platforms = platforms.linux;
};
};
}
);
# NixOS module for easy system integration
nixosModules.default =
{
config,
lib,
pkgs,
...
}:
let
cfg = config.services.huion-keydial-mini;
in
{
options.services.huion-keydial-mini = {
enable = lib.mkEnableOption "Huion Keydial Mini driver";
package = lib.mkOption {
type = lib.types.package;
default = self.packages.${pkgs.system}.huion-keydial-mini-driver;
description = "The huion-keydial-mini-driver package to use";
};
};
config = lib.mkIf cfg.enable {
environment.systemPackages = [ cfg.package ];
# Install udev rules (already patched in postInstall)
services.udev.packages = [ cfg.package ];
# Install systemd user service (already patched in postInstall)
systemd.packages = [ cfg.package ];
# Ensure bluez is enabled
hardware.bluetooth.enable = true;
# Add users to input group (users need to be specified in their own config)
users.groups.input = { };
};
};
devShells = forEachSupportedSystem (
{ pkgs, system }:
let
concatMajorMinor =
v:
lib.pipe v [
lib.versions.splitVersion
(lib.sublist 0 2)
lib.concatStrings
];
python = pkgs."python${concatMajorMinor version}";
in
{
default = pkgs.mkShellNoCC {
venvDir = ".venv";
postShellHook = ''
export CPATH="${pkgs.linuxHeaders}/include:$CPATH"
export C_INCLUDE_PATH="${pkgs.linuxHeaders}/include:$C_INCLUDE_PATH"
export CPLUS_INCLUDE_PATH="${pkgs.linuxHeaders}/include:$CPLUS_INCLUDE_PATH"
venvVersionWarn() {
local venvVersion
venvVersion="$("$venvDir/bin/python" -c 'import platform; print(platform.python_version())')"
[[ "$venvVersion" == "${python.version}" ]] && return
cat <<EOF
Warning: Python version mismatch: [$venvVersion (venv)] != [${python.version}]
Delete '$venvDir' and reload to rebuild for version ${python.version}
EOF
}
venvVersionWarn
'';
packages =
(with python.pkgs; [
venvShellHook
pip
])
++ (with pkgs; [
linuxHeaders
])
++ [ self.formatter.${system} ];
};
}
);
formatter = forEachSupportedSystem ({ pkgs, ... }: pkgs.nixfmt);
};
}