How do I override a Haskell package with a git / local package with Nix?

依然范特西╮ 提交于 2020-03-14 05:19:08

问题


Essentially I'm using this:

default.nix

{ nixpkgs ? import <nixpkgs> {}, compiler ? "ghc864" }:
nixpkgs.pkgs.haskell.packages.${compiler}.callPackage ./gitchapter.nix { }

gitchapter.nix

{ mkDerivation, base, directory, extra, filepath, foldl, hpack
, HUnit, mtl, optparse-applicative, pandoc-include-code, parsec
, pretty-simple, process, QuickCheck, rainbow, regex-pcre
, regex-posix, safe, stdenv, string-conversions, system-filepath
, template-haskell, text, transformers, turtle, unix
, unordered-containers
}:
mkDerivation {
  pname = "gitchapter";
  version = "0.1.0.0";
  src = ./.;
  isLibrary = false;
  isExecutable = true;
  libraryToolDepends = [ hpack ];
  executableHaskellDepends = [
    base directory extra filepath foldl HUnit mtl optparse-applicative
    pandoc-include-code parsec pretty-simple process QuickCheck rainbow
    regex-pcre regex-posix safe string-conversions system-filepath
    template-haskell text transformers turtle unix unordered-containers
  ];
  preConfigure = "hpack";
  license = stdenv.lib.licenses.bsd3;
}

However there is an issue with the pandoc-include-code failing to build, which seems to have since been fixed in the git repository. How can I override the package either to point to git repository or a local directory?

Would I follow the instructions at https://nixos.org/nixos/nix-pills/nixpkgs-overriding-packages.html or would this work differently due to using the nixpkgs.pkgs.haskell.packages.${compiler}.callPackage function?


Edit: Thanks to @sara's answer I now have:

{ nixpkgs ? import <nixpkgs> {}, compiler ? "ghc864" } :
let
  gitchapter = nixpkgs.pkgs.haskell.packages.${compiler}.callCabal2nix "gitchaper" (./.) {};
  zzzzz = nixpkgs.pkgs.haskell.lib.overrideCabal gitchapter;
in
  nixpkgs.pkgs.haskell.packages.${compiler}.callPackage (zzzzz) { }

So it I suppose now it's a matter of determining how to override that dependency now.


回答1:


Consider using callCabal2nix from haskell.packages.${compiler}!

It will go through your .cabal file and generate a nix expression for a derivation from that (thus making gitchapter.nix unnecessary), which you then can override using the overrideCabal function in haskell.lib in a similar fashion to normal derivation overriding. You can then fetch the updated pandoc derivation from git, and add it as a buildInput in your override expression.




回答2:


I cloned the repository I wanted to override into pandoc-include-code/ and then:

{ nixpkgs ? import <nixpkgs> {}, compiler ? "ghc864" } :
let
  myHaskellPackages = nixpkgs.pkgs.haskell.packages.${compiler}.override {
    overrides = self: super: rec {
    pandoc-include-code  = self.callCabal2nix "pandoc-include-code" (./pandoc-include-code) {};
    };
  };
in
  myHaskellPackages.callCabal2nix "gitchaper" (./.) {}

For referencing the git repository directly:

{ nixpkgs ? import <nixpkgs> {}, compiler ? "ghc864" } :
let
  myHaskellPackages = nixpkgs.pkgs.haskell.packages.${compiler}.override {
    overrides = self: super: rec {
    pandoc-include-code  = self.callCabal2nix "pandoc-include-code" (builtins.fetchGit {
        url = "git@github.com:owickstrom/pandoc-include-code.git";
        rev = "3afe94299b3a473fda0c62fdfd318435117751dd";
      })
      {};
    };
  };
in
  myHaskellPackages.callCabal2nix "gitchaper" (./.) {}


来源:https://stackoverflow.com/questions/56414329/how-do-i-override-a-haskell-package-with-a-git-local-package-with-nix

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!