需要将特定版本的 pandoc 构建到 poetry2nix nixos flake 中

Need to build specific version of pandoc into poetry2nix nixos flake

这可能非常简单,但是在尝试了解我需要使用哪个工具 stack/cabal 和 haskell 两个小时后,我没有设法提供所需的完整 pandoc 安装在 运行 时间通过我的 python 包裹...

我实际的薄片是

{
  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";

  outputs = inputs@{ self, nixpkgs, flake-utils, poetry }:
    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 = [
            pkgs.haskellPackages.pandoc_2_14_2
            pkgs.graphviz
            pkgs.bash
            pkgs.wget
            pkgs.findutils
          ];
        };
      }
    );
}

Return 这个错误在 nix build 的薄片。

➜ nix build
warning: Git tree '/home/reyman/Projets/notebook-wiki' is dirty
error: builder for '/nix/store/v4kl1d521p30d29zp7c55mcpiwqpzgkf-pandoc-2.14.2.drv' failed with exit code 1;
       last 10 log lines:
       >   confHook, called at libraries/Cabal/Cabal/Distribution/Simple/UserHooks.hs:65:5 in Cabal-3.2.1.0:Distribution.Simple.UserHooks
       >   configureAction, called at libraries/Cabal/Cabal/Distribution/Simple.hs:180:19 in Cabal-3.2.1.0:Distribution.Simple
       >   defaultMainHelper, called at libraries/Cabal/Cabal/Distribution/Simple.hs:116:27 in Cabal-3.2.1.0:Distribution.Simple
       >   defaultMain, called at Setup.hs:2:8 in main:Main
       > Setup: Encountered missing or private dependencies:
       > citeproc ==0.5.*,
       > doctemplates ==0.10.*,
       > skylighting ==0.11.*,
       > skylighting-core ==0.11.*
       >
       For full logs, run 'nix log /nix/store/v4kl1d521p30d29zp7c55mcpiwqpzgkf-pandoc-2.14.2.drv'.
error: 1 dependencies of derivation '/nix/store/vkiqdmii0cfi6vzsx0whrxmnwi20kplz-python3.9-notebook-wiki-0.0.1.drv' failed to build

我尝试添加 pkgs.haskellPackages.citeproc 但没有成功,所以这是 haskellPackages 的依赖性问题。


更新 1:

好的,我开始漫长的创作之路:


(A) 遵循的步骤:

a) 安装 haskell.nix : nix build -f https://github.com/input-output-hk/haskell.nix/archive/master.tar.gz pkgs.haskell-nix.nix-tools.ghc884 --out-link nt

b) 克隆 pandoc

c) 在同一个文件夹中创建一个 flakes flake.nix 代码底部

d) 运行 修复构建

{
  description = "PandocProject";
  inputs.haskellNix.url = "github:input-output-hk/haskell.nix";
  inputs.nixpkgs.follows = "haskellNix/nixpkgs-unstable";
  inputs.flake-utils.url = "github:numtide/flake-utils";
  outputs = { self, nixpkgs, flake-utils, haskellNix }:
    flake-utils.lib.eachSystem [ "x86_64-linux" ] (system:
    let
      overlays = [ haskellNix.overlay
        (final: prev: {
          # This overlay adds our project to pkgs
          pandocProject = final.haskell-nix.cabalProject {
              cabalProjectFreeze = null;
              cabalProject = null;
              cabalProjectLocal = null;

              compiler-nix-name = "ghc8104";
              name = "pandocProject";

              src = final.fetchFromGitHub {
                 name = "pandoc";
                 owner = "jgm";
                 repo = "pandoc";
                 rev = "d05460d00d7c9af3b4913f1760ea385a7d855d84";
                 sha256 = "1a3kwag6j13b42zhzxiwlzabsc6c9jppiwv9j8gbnf2k1yb84kdm";
              };

              pkg-def-extras = with final.haskell.lib; [];
            };
        })
      ];
      pkgs = import nixpkgs { inherit system overlays; };
      flake = pkgs.pandocProject.flake {};
    in flake // {
      # Built by `nix build .`
      defaultPackage = flake.packages."pandoc:exe:pandoc";
    });
}

现在,我正在尝试 link poetry2nix 薄片和这个 pandoc 薄片。

当你想“link”两片时,最好的方法是使用overlays。我已经修改了你的薄片并将它们发布在这个答案的下面。现在你只需要修改薄片 B,这样它就会使用薄片 A 的覆盖,但这更像是一个 haskell.nix 问题。值得注意的是“技巧”,我曾经合并两个叠加层,这样薄片 A 的 poetry2nix 叠加层将传播到薄片 B。

薄片 A:

{
  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";

  outputs = inputs@{ self, nixpkgs, flake-utils, poetry }:
    let
      overlay = final: prev: ({
        # FIXME: Change to some more verbose name
        somePythonApp = final.poetry2nix.mkPoetryApplication {
          projectDir = ./.;
          python = prev.python39;
          propagatedBuildInputs = [
            prev.haskellPackages.pandoc_2_14_2
            prev.graphviz
            prev.bash
            prev.wget
            prev.findutils
          ];
        };
      } //
      # This is kind of ugly, but required as it is not possible to return array in flake
      # It merges poetry overlay with this overlay
      (poetry.overlay final prev));
    in
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = import nixpkgs { inherit system; overlays = [ overlay ]; };
      in
      {
        defaultPackage = pkgs.somePythonApp;
      }
    ) // {
      # Provide overlay outside of flake-utils so that it will not have
      # system prefix.
      inherit overlay;
    };
}

薄片 B:

{
  description = "PandocProject";
  inputs.haskellNix.url = "github:input-output-hk/haskell.nix";
  inputs.nixpkgs.follows = "haskellNix/nixpkgs-unstable";
  inputs.flake-utils.url = "github:numtide/flake-utils";
  inputs.my-cool-python-script.url = "path:/home/mateusz/so/flakeA"; # FIXME: Change to your url
  outputs = { self, nixpkgs, flake-utils, haskellNix, my-cool-python-script }:
    flake-utils.lib.eachSystem [ "x86_64-linux" ] (system:
      let
        overlays = [
          my-cool-python-script.overlay
          haskellNix.overlay
          (final: prev: {
            # This overlay adds our project to pkgs
            pandocProject = final.haskell-nix.cabalProject {
              cabalProjectFreeze = null;
              cabalProject = null;
              cabalProjectLocal = null;

              # In the `final` attribute there is your python script !
              # Not sure how you want to use it
              # It is avaible as `final.somePythonApp` 
              
              compiler-nix-name = "ghc8104";
              name = "pandocProject";

              src = final.fetchFromGitHub {
                name = "pandoc";
                owner = "jgm";
                repo = "pandoc";
                rev = "d05460d00d7c9af3b4913f1760ea385a7d855d84";
                sha256 = "1a3kwag6j13b42zhzxiwlzabsc6c9jppiwv9j8gbnf2k1yb84kdm";
              };

              pkg-def-extras = with final.haskell.lib; [ ];
            };
          })
        ];
        pkgs = import nixpkgs { inherit system overlays; };
        flake = pkgs.pandocProject.flake { };
      in
      flake // {
        # Built by `nix build .`
        defaultPackage = flake.packages."pandoc:exe:pandoc";
      });
}