Skip to content

Commit 9bf865c

Browse files
committed
feat: 增加 nix 支持
1 parent c11dd85 commit 9bf865c

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

.envrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use flake

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -191,4 +191,7 @@ jieba.cache
191191

192192

193193
# vscode
194-
/.vscode
194+
/.vscode
195+
196+
# direnv
197+
/.direnv

flake.nix

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
}

0 commit comments

Comments
 (0)