如何在poetry2nix的NixOS flake中构建指定版本pandoc
关联pandoc flake与poetry2nix flake的实现方法
直接在原有的Python项目flake中引入你编译好的pandoc flake作为依赖即可,无需做复杂适配,修改步骤如下:
步骤1:添加pandoc输入项
在你的Python项目flake.nix的inputs块中添加pandoc的引用,如果你的pandoc flake存放在本地的./pandoc目录下,配置如下:
inputs.pandoc.url = "path:./pandoc"; # 可选:统一nixpkgs版本避免潜在冲突 inputs.pandoc.inputs.nixpkgs.follows = "nixpkgs";
如果pandoc flake已经推送到Git仓库,将url替换为对应的Git地址即可。
步骤2:在poetry构建配置中引入pandoc
修改outputs的参数接收pandoc输入,然后将pandoc添加到propagatedBuildInputs中,替换原来的pkgs.haskellPackages.pandoc_2_14_2。
完整修改后的Python项目flake.nix示例
{ description = "Application packaged using poetry2nix"; inputs.flake-utils.url = "github:numtide/flake-utils"; inputs.nixpkgs.url = "github:NixOS/nixpkgs"; inputs.poetry.url = "github:nix-community/poetry2nix"; # 新增pandoc输入 inputs.pandoc.url = "path:./pandoc"; inputs.pandoc.inputs.nixpkgs.follows = "nixpkgs"; outputs = inputs@{ self, nixpkgs, flake-utils, poetry, pandoc }: flake-utils.lib.eachDefaultSystem (system: let pkgs = import nixpkgs { inherit system; overlays = [ poetry.overlay ]; }; inherit (pkgs) poetry2nix; in { defaultPackage = poetry2nix.mkPoetryApplication { projectDir = ./.; python = pkgs.python39; propagatedBuildInputs = [ # 替换原来的haskellPackages.pandoc pandoc.defaultPackage.${system} pkgs.graphviz pkgs.bash pkgs.wget pkgs.findutils ]; }; } ); }
验证方法
执行nix build完成构建后,运行./result/bin/pandoc --version,确认版本为你需要的2.14.2即可。
额外优化建议
你不需要自行编译pandoc,nixpkgs中提供了预编译的pandoc-bin包,直接替换原来的pkgs.haskellPackages.pandoc_2_14_2为pkgs.pandoc_2_14_2-bin即可,无需处理Haskell依赖问题,构建速度更快。
内容的提问来源于stack exchange,提问作者reyman64
相关产品推荐
相关产品推荐

