【问题标题】:How do I override a Haskell package in nixpkgs via Nix?如何通过 Nix 覆盖 nixpkgs 中的 Haskell 包?
【发布时间】:2019-10-18 05:44:46
【问题描述】:

基本上我正在使用这个:

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

所以我想现在是确定如何覆盖该依赖关系的问题。

【问题讨论】:

    标签: haskell nix


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

      引用的本地路径示例:

      { 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 仓库:

          pandoc-include-code  = self.callCabal2nix "pandoc-include-code" (builtins.fetchGit {
              url = "git@github.com:owickstrom/pandoc-include-code.git";
              rev = "3afe94299b3a473fda0c62fdfd318435117751dd";
            })
            {};
      

      Hackage(通过 tar 存档)示例:

        prettyprinter = self.callCabal2nix "prettyprinter" (builtins.fetchTarball {
          url = "https://hackage.haskell.org/package/prettyprinter-1.7.0/prettyprinter-1.7.0.tar.gz";
        }) {};
      

      【讨论】:

      • 您可以使用nix直接引用存储库中的提交!这样你就不需要克隆 repo!
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-04
      • 2019-04-15
      • 2019-11-04
      • 2023-03-12
      • 2020-07-28
      • 2019-12-18
      相关资源
      最近更新 更多