如何将ghcide添加到shell.nix

问题描述

我有一个Haskell Cabal项目。我一直在使用 cabal2nix 构建它。因此,我有3个nix文件:

  • project.nix- cabal2nix 生成的.nix文件。
  • default.nix-仅haskell.callPackage ./project.nix {}
  • shell.nix-仅返回默认的环境(import ./default.nix {}).env

最近,我决定使用ghcide设置vscode开发环境。在说明中说

在项目pkgs.haskellPackages.ghcide中包含shell.nix ...

无需进一步说明。听起来应该很容易,但是我不知道怎么做。我该怎么办?

解决方法

您可以将ghcide软件包添加到buildTools配置下;

{mkDerivation,stdenv,base,aeson,scotty,wai-extra,text,ghcide}:
mkDerivation {
  pname = "come";
  version = "0.1.0.0";
  src = ./.;
  isLibrary = false;
  isExecutable = true;
  executableHaskellDepends = [
    base aeson scotty wai-extra text
  ];
  buildTools = [ghcide];
  homepage = "http://emre.xyz/come";
  description = "demo project";
  license = with stdenv.lib.licenses; [gpl3Plus];
}
,

shell.nix中使用shellFor函数。它在软件包集中,而不是haskell.lib中。根据{{​​3}}上shellFor内联文档的示例,我已重命名all-packages.nix,并在shell.nix中为其添加了一个let绑定,并添加了ghcide

    # Returns a derivation whose environment contains a GHC with only
    # the dependencies of packages listed in `packages`,not the
    # packages themselves. Using nix-shell on this derivation will
    # give you an environment suitable for developing the listed
    # packages with an incremental tool like cabal-install.
    # In addition to the "packages" arg and "withHoogle" arg,anything that
    # can be passed into stdenv.mkDerivation can be included in the input attrset
    #
    #     # all-packages.nix
    #     with import <nixpkgs> {};
    #     haskellPackages.extend (haskell.lib.packageSourceOverrides {
    #       frontend = ./frontend;
    #       backend = ./backend;
    #       common = ./common;
    #     })
    #
    #     # shell.nix
    #     let pkgs = import <nixpkgs> {};
    #         allPackages = import ./all-packages.nix;
    #     in
    #     allPackages.shellFor {
    #       packages = p: [p.frontend p.backend p.common];
    #       withHoogle = true;
    #       buildInputs = [ allPackages.ghcide ];
    #     }
    #
    #     -- cabal.project
    #     packages:
    #       frontend/
    #       backend/
    #       common/
    #
    #     bash$ nix-shell --run "cabal new-build all"
    #     bash$ nix-shell --run "python"

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...