Home > Mobile >  Need to build specific version of pandoc into poetry2nix nixos flake
Need to build specific version of pandoc into poetry2nix nixos flake

Time:11-17

This is probably very simple, but after two hours to try to understand which tool i need to use stack/cabal with haskell, i didn't manage how to provide a full pandoc installation needed by my python package at runtime ...

My actual flakes is

{
  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 this error at nix build of the flake.

➜ 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

I try to add pkgs.haskellPackages.citeproc without success, so this is a problem of dependencies with haskellPackages.


Update 1 :

Ok, i start the long road to create :

  • One flake (A) that compile pandoc.
  • one flake (B) with my python script that use (A)

The steps followed for (A) :

a) install 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) clone pandoc

c) create a flakes flake.nix with code bottom into this same folder

d) run nix build

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

Now, i'm trying to link poetry2nix flakes and this pandoc flakes.

CodePudding user response:

When you want to "link" two flakes, the best way to do it is to use overlays. I have modified your flakes and posted them below in this answer. Now you only need to modify flake B, so that it would use overlay from flake A, but this is more of a haskell.nix issue. It is worth to notice the "trick", that I have used to merge two overlays so that poetry2nix overlay from flake A will be propagated to flake B.

Flake 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;
    };
}

Flake 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";
      });
}
  • Related