File tree 3 files changed +57
-1
lines changed
3 files changed +57
-1
lines changed Original file line number Diff line number Diff line change
1
+ use flake
Original file line number Diff line number Diff line change @@ -191,4 +191,7 @@ jieba.cache
191
191
192
192
193
193
# vscode
194
- /.vscode
194
+ /.vscode
195
+
196
+ # direnv
197
+ /.direnv
Original file line number Diff line number Diff line change
1
+ {
2
+ description = "MaiMBot Nix Dev Env" ;
3
+
4
+ inputs = {
5
+ nixpkgs . url = "github:NixOS/nixpkgs/nixos-unstable" ;
6
+ flake-utils . url = "github:numtide/flake-utils" ;
7
+ } ;
8
+
9
+ outputs = { self , nixpkgs , flake-utils } :
10
+ flake-utils . lib . eachDefaultSystem ( system :
11
+ let
12
+ pkgs = import nixpkgs {
13
+ inherit system ;
14
+ } ;
15
+
16
+ # 读取 requirements.txt 文件
17
+ requirementsFile = builtins . readFile ./requirements.txt ;
18
+
19
+ # 解析 requirements.txt 文件,提取包名
20
+ parseRequirements = content :
21
+ let
22
+ lines = builtins . split "\n " content ;
23
+ # 过滤掉空行和注释
24
+ filteredLines = builtins . filter ( line :
25
+ line != "" && ! ( builtins . match "^ *#.*" line )
26
+ ) lines ;
27
+ # 提取包名(去掉版本号)
28
+ packageNames = builtins . map ( line :
29
+ builtins . head ( builtins . split "[=<>]" line )
30
+ ) filteredLines ;
31
+ in
32
+ packageNames ;
33
+
34
+ # 获取 requirements.txt 中的包名列表
35
+ requirements = parseRequirements requirementsFile ;
36
+
37
+ # 动态生成 Python 环境
38
+ pythonEnv = pkgs . python3 . withPackages ( ps :
39
+ builtins . map ( pkg : ps . ${ pkg } ) requirements
40
+ ) ;
41
+ in
42
+ {
43
+ devShell = pkgs . mkShell {
44
+ buildInputs = [ pythonEnv ] ;
45
+
46
+ shellHook = ''
47
+ echo "Python environment is ready!"
48
+ '' ;
49
+ } ;
50
+ }
51
+ ) ;
52
+ }
You can’t perform that action at this time.
0 commit comments