-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
166 lines (150 loc) · 4.82 KB
/
Copy pathflake.nix
File metadata and controls
166 lines (150 loc) · 4.82 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
{
description = "ptags";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-26.05";
flake-utils.url = "github:numtide/flake-utils";
# see https://pyproject-nix.github.io/
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,
pyproject-nix,
uv2nix,
pyproject-build-systems,
}:
flake-utils.lib.eachDefaultSystem (
system:
let
name = "ptags";
pkgs = import nixpkgs {
inherit system;
config.allowUnfree = true;
};
inherit (pkgs) lib;
inherit (builtins) map;
python = pkgs.python314;
uv = pkgs.writeScriptBin "uv" ''
#!${pkgs.zsh}/bin/zsh
set -eu -o pipefail
UV_PYTHON=${python}/bin/python ${pkgs.uv}/bin/uv --no-python-downloads $@
'';
# for pyproject.toml
# [tool.uv.build-backend]
# namespace = true # if you use namespace packages
# [project.scripts]
# some = "some.main:app" # for executable entry points
# [tool.hatch.build.targets.wheel]
# packages = ["src/some.py"] # if you use single files, but needs old build system below
# [build-system]
# requires = ["hatchling"]
# build-backend = "hatchling.build"
prodPkgs = # with pkgs;
[ ];
devPkgs = (
[
uv
python
]
++ (with pkgs; [
ruff
basedpyright
nil # nix language server
nixfmt-rfc-style # nixpkgs-fmt is deprecated
])
);
devLibs = with pkgs; [
stdenv.cc.cc
# zlib
# libglvnd
# xorg.libX11
# glib
# eigen
];
devLdLibs = pkgs.buildEnv {
name = "${name}-dev-ld-libs";
paths = map (lib.getOutput "lib") devLibs;
};
devEnv = pkgs.buildEnv {
name = "${name}-dev-env";
paths = devPkgs ++ devLibs ++ prodPkgs;
};
pyproject = uv2nix.lib.workspace.loadWorkspace { workspaceRoot = ./.; };
moduleOverrides =
final: prev:
# let
# # see https://github.com/TyberiusPrime/uv2nix_hammer_overrides/tree/main
# # I dont fully understand what we do here, we switch to setuptools instead of wheels?
# # for libs that need to build for nix? and we might have to add build dependencies?
# setuptools =
# prev_lib:
# prev_lib.overrideAttrs (old: {
# nativeBuildInputs =
# (old.nativeBuildInputs or [ ]) ++ (final.resolveBuildSystem { setuptools = [ ]; });
# });
# in
{
# pprofile = setuptools prev.pprofile;
};
modules =
(pkgs.callPackage pyproject-nix.build.packages {
python = python;
}).overrideScope
(
lib.composeManyExtensions [
pyproject-build-systems.overlays.default
(pyproject.mkPyprojectOverlay { sourcePreference = "wheel"; })
moduleOverrides
]
);
venv = modules.mkVirtualEnv "${name}-venv" pyproject.deps.default;
inherit (pkgs.callPackages pyproject-nix.build.util { }) mkApplication;
app = mkApplication {
venv = venv;
package = modules.ptags;
};
# TODO this could help, but Im not sure its the best way to do it
# wrappedApp = pkgs.writeScriptBin "TODO" ''
# #!${pkgs.zsh}/bin/zsh
# LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/run/opengl-driver/lib/ ${app}/bin/TODO $@
# '';
package = pkgs.buildEnv {
name = "${name}-env";
paths = [ app ] ++ prodPkgs;
postBuild = ''
# TODO for example add some $out/share/zsh/site-functions/_name for completions
'';
};
in
{
packages.default = package;
devShells.default = pkgs.mkShellNoCC {
packages = [ devEnv ];
LD_LIBRARY_PATH = "${pkgs.lib.makeLibraryPath [ devLdLibs ]}";
shellHook = ''
if [[ -v h ]]; then
export PATH=$h/bin:$PATH;
else
echo 'Project root env var h is not set.' >&2
fi
'';
};
}
);
}