haskell - 如何将 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
中......
无需进一步解释。听起来这应该很容易,但我不知道怎么做。我该怎么做?
解决方案
在shell.nix
使用shellFor
功能。它在包集中而不是haskell.lib
. 基于https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/haskell-modules/make-package-set.nix上的 shellFor 内联文档中的示例,我已重命名为all-packages.nix
添加了一个 let 绑定它在shell.nix
并添加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"
推荐阅读
- javascript - 为什么 displayName 没有得到更新?使用 onAuthChanged
- speech-to-text - 如何在没有先前语音注册的情况下使用 Microsoft 语音到文本进行说话人识别(分类)?
- javascript - 如果输入字段和文件为空,如何禁用按钮?
- javascript - 从 JSON 文件导入数据到 JS
- azure - 如何一次从多个订阅中读取数据
- npm - 如何自动更新 npm?
- python - Numpy矢量化而不是for循环
- python - Tkinter 错误。按钮的未知选项-命令。(Python 3)
- java - 如何在 RestAPI 中获取 GET 调用的响应体?
- python - 提取列中的嵌套元素并存储到新列中