使用callPackage时,如何使用Nix覆盖带有git / local软件包的Haskell软件包?

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (2)
  • 关注 (0)
  • 查看 (27)

基本上我正在使用这个:

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

但是,pandoc-include-code无法构建存在问题,这似乎已经在git存储库中得到修复。如何覆盖包以指向git存储库或本地目录?

我是否会按照https://nixos.org/nixos/nix-pills/nixpkgs-overriding-packages.html上的说明进行操作,或者由于使用该nixpkgs.pkgs.haskell.packages.${compiler}.callPackage功能,这会有所不同吗?

编辑: 感谢@ sara的回答我现在有:

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

因此,我认为现在确定如何覆盖该依赖关系是一个问题。

提问于
用户回答回答于

我克隆了我想覆盖的存储库pandoc-include-code/然后:

{ 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" (./.) {}

用于直接引用git存储库:

{ 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" (./.) {}
用户回答回答于

考虑使用callCabal2nix来自haskell.packages.${compiler}

它将遍历您的.cabal文件并生成一个nix表达式,用于从中派生(因此不需要gitchapter.nix),然后您可以使用overrideCabal函数in haskell.lib以与常规派生重写类似的方式覆盖它。然后,您可以从git获取更新的pandoc派生,并将其作为覆盖表达式中的buildInput添加。

扫码关注云+社区

领取腾讯云代金券

年度创作总结 领取年终奖励