-
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathflake.nix
More file actions
307 lines (278 loc) · 10.4 KB
/
flake.nix
File metadata and controls
307 lines (278 loc) · 10.4 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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
pyproject-nix = {
url = "github:pyproject-nix/pyproject.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
uv2nix = {
url = "github:pyproject-nix/uv2nix";
inputs.pyproject-nix.follows = "pyproject-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
pyproject-build-systems = {
url = "github:pyproject-nix/build-system-pkgs";
inputs.pyproject-nix.follows = "pyproject-nix";
inputs.uv2nix.follows = "uv2nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{
self,
nixpkgs,
flake-utils,
uv2nix,
pyproject-nix,
pyproject-build-systems,
...
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
python = pkgs.python311;
workspace = uv2nix.lib.workspace.loadWorkspace { workspaceRoot = ./.; };
overlay = workspace.mkPyprojectOverlay {
# Prefer prebuilt binary wheels as a package source.
# Sdists are less likely to "just work" because of the metadata missing from uv.lock.
sourcePreference = "wheel";
};
pyprojectOverrides = final: prev: {
onelauncher = prev.onelauncher.overrideAttrs (previousAttrs: {
passthru = previousAttrs.passthru // {
# Add tests to Nix package
tests =
let
virtualenv = final.mkVirtualEnv "onelauncher-pytest-env" {
onelauncher = [ "test" ];
};
in
(previousAttrs.tests or { })
// {
pytest = pkgs.stdenv.mkDerivation {
name = "${final.onelauncher.name}-pytest";
inherit (final.onelauncher) src;
nativeBuildInputs = [
virtualenv
];
dontConfigure = true;
buildPhase = ''
runHook preBuild
pytest --junitxml=report.xml
runHook postBuild
'';
installPhase = ''
runHook preInstall
mv report.xml $out
runHook postInstall
'';
};
};
};
});
zeep = prev.zeep.overrideAttrs (prevAttrs: {
nativeBuildInputs = prevAttrs.nativeBuildInputs ++ [
(final.resolveBuildSystem {
setuptools = [ ];
})
];
});
asyncache = prev.asyncache.overrideAttrs (prevAttrs: {
nativeBuildInputs = prevAttrs.nativeBuildInputs ++ [
(final.resolveBuildSystem {
poetry-core = [ ];
})
];
});
sgmllib3k = prev.sgmllib3k.overrideAttrs (prevAttrs: {
nativeBuildInputs = prevAttrs.nativeBuildInputs ++ [
(final.resolveBuildSystem {
setuptools = [ ];
})
];
});
nuitka = prev.nuitka.overrideAttrs (prevAttrs: {
nativeBuildInputs = prevAttrs.nativeBuildInputs ++ [
(final.resolveBuildSystem {
setuptools = [ ];
})
];
});
# Based on https://github.com/nix-community/poetry2nix/blob/ce2369db77f45688172384bbeb962bc6c2ea6f94/overrides/default.nix#L2915
pyside6-essentials = prev.pyside6-essentials.overrideAttrs (
prevAttrs:
pkgs.lib.optionalAttrs pkgs.stdenv.isLinux {
autoPatchelfIgnoreMissingDeps = [
"libmysqlclient.so.21"
"libfbclient.so.2"
"libclntsh.so.23.1"
"libmimerapi.so"
"libQt6EglFsKmsGbmSupport.so*"
"libQt6QuickShapesDesignHelpers.so.6"
"libQt6QuickVectorImageHelpers.so.6"
"libtiff.so.5"
];
preFixup = ''
addAutoPatchelfSearchPath ${final.shiboken6}/${final.python.sitePackages}/shiboken6
'';
propagatedBuildInputs = prevAttrs.propagatedBuildInputs or [ ] ++ [
pkgs.qt6.full
pkgs.libxkbcommon
pkgs.gtk3
pkgs.speechd
pkgs.gst
pkgs.gst_all_1.gst-plugins-base
pkgs.gst_all_1.gstreamer
pkgs.postgresql.lib
pkgs.unixODBC
pkgs.pcsclite
pkgs.xorg.libxcb
pkgs.xorg.xcbutil
pkgs.xorg.xcbutilcursor
pkgs.xorg.xcbutilerrors
pkgs.xorg.xcbutilimage
pkgs.xorg.xcbutilkeysyms
pkgs.xorg.xcbutilrenderutil
pkgs.xorg.xcbutilwm
pkgs.libdrm
pkgs.pulseaudio
];
}
);
};
# Construct package set
pythonSet =
# Use base package set from pyproject.nix builders.
(pkgs.callPackage pyproject-nix.build.packages {
inherit python;
}).overrideScope
(
nixpkgs.lib.composeManyExtensions [
pyproject-build-systems.overlays.wheel
overlay
pyprojectOverrides
]
);
getExtraPkgs = pkgs: [
pkgs.innoextract
(pkgs.runCommand "onelauncher-shell-completions"
{
nativeBuildInputs = [
self.packages.${system}.onelauncher-unwrapped
pkgs.installShellFiles
];
}
''
installShellCompletion --cmd onelauncher \
--bash <(onelauncher generate-shell-completion bash) \
--fish <(onelauncher generate-shell-completion fish) \
--zsh <(onelauncher generate-shell-completion zsh)
''
)
];
in
{
packages =
let
inherit (pkgs.callPackages pyproject-nix.build.util { }) mkApplication;
in
{
onelauncher-unwrapped = mkApplication {
venv = pythonSet.mkVirtualEnv "onelauncher-env" workspace.deps.default;
package = pythonSet.onelauncher;
};
onelauncher = pkgs.steam.buildRuntimeEnv {
inherit (self.packages.${system}.onelauncher-unwrapped) pname version meta;
extraPkgs = pkgs: [ self.packages.${system}.onelauncher-unwrapped ] ++ getExtraPkgs pkgs;
runScript = pkgs.lib.getExe self.packages.${system}.onelauncher-unwrapped;
};
default = self.packages.${system}.onelauncher;
fhs-run =
(pkgs.steam.override {
extraPkgs = pkgs: [
pkgs.libz
];
privateTmp = false;
}).run-free;
};
apps = {
onelauncher = flake-utils.lib.mkApp { drv = self.packages.${system}.onelauncher; };
default = self.apps.${system}.onelauncher;
};
checks = {
inherit (pythonSet.onelauncher.passthru.tests) pytest;
};
devShells.default =
let
editableOverlay = workspace.mkEditablePyprojectOverlay {
# Use environment variable
root = "$REPO_ROOT";
# Optional: Only enable editable for these packages
# members = [ "onelauncher" ];
};
editablePythonSet = pythonSet.overrideScope (
nixpkgs.lib.composeManyExtensions [
editableOverlay
(final: prev: {
onelauncher = prev.onelauncher.overrideAttrs (old: {
# Filter the sources going into an editable build so the editable
# package doesn't have to be rebuilt on every change.
src = nixpkgs.lib.fileset.toSource {
root = old.src;
fileset = nixpkgs.lib.fileset.unions [
(old.src + "/pyproject.toml")
(old.src + "/README.md")
(old.src + "/src/onelauncher/__init__.py")
];
};
# Hatchling (our build system) has a dependency on the `editables` package when building editables.
#
# In normal Python flows this dependency is dynamically handled, and doesn't need to be explicitly declared.
# This behavior is documented in PEP-660.
#
# With Nix the dependency needs to be explicitly declared.
nativeBuildInputs =
old.nativeBuildInputs
++ final.resolveBuildSystem {
editables = [ ];
};
});
})
]
);
# Enable all optional dependencies for development.
virtualenv = editablePythonSet.mkVirtualEnv "onelauncher-dev-env" workspace.deps.all;
in
pkgs.mkShell {
packages = [
virtualenv
pkgs.uv
# Used for Nuitka compilation caching
pkgs.ccache
]
++ getExtraPkgs pkgs;
env = {
# Don't create venv using `uv`.
UV_NO_SYNC = "1";
UV_PYTHON = pythonSet.python.interpreter;
UV_PYTHON_DOWNLOADS = "never";
# Used in OneLauncher script
NIX_PYTHON_ENV = "${virtualenv}";
};
shellHook = ''
# Undo dependency propagation by nixpkgs.
unset PYTHONPATH
# Get repository root using git. This is expanded at runtime by the editable `.pth` machinery.
export REPO_ROOT=$(git rev-parse --show-toplevel)
# Help IDEs find the right Python environment
ln --force --no-target-directory --symbolic "${virtualenv}" ./.venv
ln --force --symbolic "${
pkgs.callPackage ./src/run_patch_client { }
}/bin/run_ptch_client.exe" ./src/onelauncher/external/run_ptch_client.exe
'';
};
}
);
}