update: 更新开发必要的包,但是因为 nb-cli 上游打包中并未包含 nonebot2,因此目前本配置并不能用于运行和调试

This commit is contained in:
Rikki
2025-03-07 18:01:32 +08:00
parent 9bf865cfd8
commit cfcdcc653e
2 changed files with 100 additions and 30 deletions

61
flake.lock generated Normal file
View File

@@ -0,0 +1,61 @@
{
"nodes": {
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1731533236,
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1741196730,
"narHash": "sha256-0Sj6ZKjCpQMfWnN0NURqRCQn2ob7YtXTAOTwCuz7fkA=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "48913d8f9127ea6530a2a2f1bd4daa1b8685d8a3",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-24.11",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

View File

@@ -1,50 +1,59 @@
{ {
description = "MaiMBot Nix Dev Env"; description = "MaiMBot Nix Dev Env";
# 本配置仅方便用于开发,但是因为 nb-cli 上游打包中并未包含 nonebot2因此目前本配置并不能用于运行和调试
inputs = { inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";
flake-utils.url = "github:numtide/flake-utils"; flake-utils.url = "github:numtide/flake-utils";
}; };
outputs = { self, nixpkgs, flake-utils }: outputs =
flake-utils.lib.eachDefaultSystem (system: {
self,
nixpkgs,
flake-utils,
}:
flake-utils.lib.eachDefaultSystem (
system:
let let
pkgs = import nixpkgs { pkgs = import nixpkgs {
inherit system; inherit system;
}; };
# 读取 requirements.txt 文件 pythonEnv = pkgs.python3.withPackages (
requirementsFile = builtins.readFile ./requirements.txt; ps: with ps; [
pymongo
# 解析 requirements.txt 文件,提取包名 python-dotenv
parseRequirements = content: pydantic
let jieba
lines = builtins.split "\n" content; openai
# 过滤掉空行和注释 aiohttp
filteredLines = builtins.filter (line: requests
line != "" && !(builtins.match "^ *#.*" line) urllib3
) lines; numpy
# 提取包名(去掉版本号) pandas
packageNames = builtins.map (line: matplotlib
builtins.head (builtins.split "[=<>]" line) networkx
) filteredLines; python-dateutil
in APScheduler
packageNames; loguru
tomli
# 获取 requirements.txt 中的包名列表 customtkinter
requirements = parseRequirements requirementsFile; colorama
pypinyin
# 动态生成 Python 环境 pillow
pythonEnv = pkgs.python3.withPackages (ps: setuptools
builtins.map (pkg: ps.${pkg}) requirements ]
); );
in in
{ {
devShell = pkgs.mkShell { devShell = pkgs.mkShell {
buildInputs = [ pythonEnv ]; buildInputs = [
pythonEnv
pkgs.nb-cli
];
shellHook = '' shellHook = ''
echo "Python environment is ready!"
''; '';
}; };
} }