首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何通过Nix覆盖nixpkgs中的Haskell包?

如何通过Nix覆盖nixpkgs中的Haskell包?
EN

Stack Overflow用户
提问于 2019-06-02 18:49:28
回答 2查看 1.5K关注 0票数 4

本质上,我使用的是:

default.nix

代码语言:javascript
复制
{ nixpkgs ? import <nixpkgs> {}, compiler ? "ghc864" }:
nixpkgs.pkgs.haskell.packages.${compiler}.callPackage ./gitchapter.nix { }

gitchapter.nix

代码语言:javascript
复制
{ 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的回答,我现在有了:

代码语言:javascript
复制
{ 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) { }

所以,我想现在是决定如何覆盖依赖的问题了。

EN

回答 2

Stack Overflow用户

发布于 2019-06-02 19:33:20

考虑使用haskell.packages.${compiler}中的callCabal2nix

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

票数 5
EN

Stack Overflow用户

发布于 2019-06-03 00:04:55

引用的本地路径示例:

代码语言:javascript
复制
{ 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存储库:

代码语言:javascript
复制
    pandoc-include-code  = self.callCabal2nix "pandoc-include-code" (builtins.fetchGit {
        url = "git@github.com:owickstrom/pandoc-include-code.git";
        rev = "3afe94299b3a473fda0c62fdfd318435117751dd";
      })
      {};

Hackage (通过tar归档)示例:

代码语言:javascript
复制
  prettyprinter = self.callCabal2nix "prettyprinter" (builtins.fetchTarball {
    url = "https://hackage.haskell.org/package/prettyprinter-1.7.0/prettyprinter-1.7.0.tar.gz";
  }) {};
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56414329

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档